aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-03 19:26:54 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-03 19:26:54 +0200
commit4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch)
tree6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser
parent2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff)
downloadwallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz
wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst
wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip
twig implementation
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser')
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php61
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php89
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php48
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php89
4 files changed, 287 insertions, 0 deletions
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php
new file mode 100644
index 00000000..244d676e
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php
@@ -0,0 +1,61 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\TokenParser;
13
14use Symfony\Bridge\Twig\Node\FormThemeNode;
15
16/**
17 * Token Parser for the 'form_theme' tag.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21class FormThemeTokenParser extends \Twig_TokenParser
22{
23 /**
24 * Parses a token and returns a node.
25 *
26 * @param \Twig_Token $token A Twig_Token instance
27 *
28 * @return \Twig_NodeInterface A Twig_NodeInterface instance
29 */
30 public function parse(\Twig_Token $token)
31 {
32 $lineno = $token->getLine();
33 $stream = $this->parser->getStream();
34
35 $form = $this->parser->getExpressionParser()->parseExpression();
36
37 if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
38 $this->parser->getStream()->next();
39 $resources = $this->parser->getExpressionParser()->parseExpression();
40 } else {
41 $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
42 do {
43 $resources->addElement($this->parser->getExpressionParser()->parseExpression());
44 } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
45 }
46
47 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
48
49 return new FormThemeNode($form, $resources, $lineno, $this->getTag());
50 }
51
52 /**
53 * Gets the tag name associated with this token parser.
54 *
55 * @return string The tag name
56 */
57 public function getTag()
58 {
59 return 'form_theme';
60 }
61}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
new file mode 100644
index 00000000..be8ac5cf
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
@@ -0,0 +1,89 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\TokenParser;
13
14use Symfony\Bridge\Twig\Node\TransNode;
15
16/**
17 * Token Parser for the 'transchoice' tag.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21class TransChoiceTokenParser extends TransTokenParser
22{
23 /**
24 * Parses a token and returns a node.
25 *
26 * @param \Twig_Token $token A Twig_Token instance
27 *
28 * @return \Twig_NodeInterface A Twig_NodeInterface instance
29 *
30 * @throws \Twig_Error_Syntax
31 */
32 public function parse(\Twig_Token $token)
33 {
34 $lineno = $token->getLine();
35 $stream = $this->parser->getStream();
36
37 $vars = new \Twig_Node_Expression_Array(array(), $lineno);
38
39 $count = $this->parser->getExpressionParser()->parseExpression();
40
41 $domain = null;
42 $locale = null;
43
44 if ($stream->test('with')) {
45 // {% transchoice count with vars %}
46 $stream->next();
47 $vars = $this->parser->getExpressionParser()->parseExpression();
48 }
49
50 if ($stream->test('from')) {
51 // {% transchoice count from "messages" %}
52 $stream->next();
53 $domain = $this->parser->getExpressionParser()->parseExpression();
54 }
55
56 if ($stream->test('into')) {
57 // {% transchoice count into "fr" %}
58 $stream->next();
59 $locale = $this->parser->getExpressionParser()->parseExpression();
60 }
61
62 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
63
64 $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
65
66 if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67 throw new \Twig_Error_Syntax('A message must be a simple text.');
68 }
69
70 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
71
72 return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
73 }
74
75 public function decideTransChoiceFork($token)
76 {
77 return $token->test(array('endtranschoice'));
78 }
79
80 /**
81 * Gets the tag name associated with this token parser.
82 *
83 * @return string The tag name
84 */
85 public function getTag()
86 {
87 return 'transchoice';
88 }
89}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php
new file mode 100644
index 00000000..0a0ed55b
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php
@@ -0,0 +1,48 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\TokenParser;
13
14use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
15
16/**
17 * Token Parser for the 'trans_default_domain' tag.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21class TransDefaultDomainTokenParser extends \Twig_TokenParser
22{
23 /**
24 * Parses a token and returns a node.
25 *
26 * @param \Twig_Token $token A Twig_Token instance
27 *
28 * @return \Twig_NodeInterface A Twig_NodeInterface instance
29 */
30 public function parse(\Twig_Token $token)
31 {
32 $expr = $this->parser->getExpressionParser()->parseExpression();
33
34 $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
35
36 return new TransDefaultDomainNode($expr, $token->getLine(), $this->getTag());
37 }
38
39 /**
40 * Gets the tag name associated with this token parser.
41 *
42 * @return string The tag name
43 */
44 public function getTag()
45 {
46 return 'trans_default_domain';
47 }
48}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
new file mode 100644
index 00000000..a11681c2
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
@@ -0,0 +1,89 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\TokenParser;
13
14use Symfony\Bridge\Twig\Node\TransNode;
15
16/**
17 * Token Parser for the 'trans' tag.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21class TransTokenParser extends \Twig_TokenParser
22{
23 /**
24 * Parses a token and returns a node.
25 *
26 * @param \Twig_Token $token A Twig_Token instance
27 *
28 * @return \Twig_NodeInterface A Twig_NodeInterface instance
29 *
30 * @throws \Twig_Error_Syntax
31 */
32 public function parse(\Twig_Token $token)
33 {
34 $lineno = $token->getLine();
35 $stream = $this->parser->getStream();
36
37 $vars = new \Twig_Node_Expression_Array(array(), $lineno);
38 $domain = null;
39 $locale = null;
40 if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
41 if ($stream->test('with')) {
42 // {% trans with vars %}
43 $stream->next();
44 $vars = $this->parser->getExpressionParser()->parseExpression();
45 }
46
47 if ($stream->test('from')) {
48 // {% trans from "messages" %}
49 $stream->next();
50 $domain = $this->parser->getExpressionParser()->parseExpression();
51 }
52
53 if ($stream->test('into')) {
54 // {% trans into "fr" %}
55 $stream->next();
56 $locale = $this->parser->getExpressionParser()->parseExpression();
57 } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
58 throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.');
59 }
60 }
61
62 // {% trans %}message{% endtrans %}
63 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
64 $body = $this->parser->subparse(array($this, 'decideTransFork'), true);
65
66 if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67 throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text');
68 }
69
70 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
71
72 return new TransNode($body, $domain, null, $vars, $locale, $lineno, $this->getTag());
73 }
74
75 public function decideTransFork($token)
76 {
77 return $token->test(array('endtrans'));
78 }
79
80 /**
81 * Gets the tag name associated with this token parser.
82 *
83 * @return string The tag name
84 */
85 public function getTag()
86 {
87 return 'trans';
88 }
89}