aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/Twig/Extensions/Grammar
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 /inc/3rdparty/Twig/Extensions/Grammar
parent2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff)
downloadwallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz
wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst
wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip
twig implementation
Diffstat (limited to 'inc/3rdparty/Twig/Extensions/Grammar')
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Arguments.php22
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Array.php22
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Body.php39
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Boolean.php24
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Constant.php37
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Expression.php22
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Hash.php22
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Number.php24
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Optional.php69
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Switch.php24
-rw-r--r--inc/3rdparty/Twig/Extensions/Grammar/Tag.php56
11 files changed, 0 insertions, 361 deletions
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php b/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php
deleted file mode 100644
index 158c05ac..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Arguments.php
+++ /dev/null
@@ -1,22 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Arguments extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:arguments>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 return $this->parser->getExpressionParser()->parseArguments();
21 }
22}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Array.php b/inc/3rdparty/Twig/Extensions/Grammar/Array.php
deleted file mode 100644
index 34aece0f..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Array.php
+++ /dev/null
@@ -1,22 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Array extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:array>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 return $this->parser->getExpressionParser()->parseArrayExpression();
21 }
22}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Body.php b/inc/3rdparty/Twig/Extensions/Grammar/Body.php
deleted file mode 100644
index 540cfc75..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Body.php
+++ /dev/null
@@ -1,39 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Body extends Twig_Extensions_Grammar
12{
13 protected $end;
14
15 public function __construct($name, $end = null)
16 {
17 parent::__construct($name);
18
19 $this->end = null === $end ? 'end'.$name : $end;
20 }
21
22 public function __toString()
23 {
24 return sprintf('<%s:body>', $this->name);
25 }
26
27 public function parse(Twig_Token $token)
28 {
29 $stream = $this->parser->getStream();
30 $stream->expect(Twig_Token::BLOCK_END_TYPE);
31
32 return $this->parser->subparse(array($this, 'decideBlockEnd'), true);
33 }
34
35 public function decideBlockEnd(Twig_Token $token)
36 {
37 return $token->test($this->end);
38 }
39}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php b/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php
deleted file mode 100644
index c0048090..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Boolean.php
+++ /dev/null
@@ -1,24 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Boolean extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:boolean>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, array('true', 'false'));
21
22 return new Twig_Node_Expression_Constant('true' === $token->getValue() ? true : false, $token->getLine());
23 }
24}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Constant.php b/inc/3rdparty/Twig/Extensions/Grammar/Constant.php
deleted file mode 100644
index 9df60458..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Constant.php
+++ /dev/null
@@ -1,37 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Constant extends Twig_Extensions_Grammar
12{
13 protected $type;
14
15 public function __construct($name, $type = null)
16 {
17 $this->name = $name;
18 $this->type = null === $type ? Twig_Token::NAME_TYPE : $type;
19 }
20
21 public function __toString()
22 {
23 return $this->name;
24 }
25
26 public function parse(Twig_Token $token)
27 {
28 $this->parser->getStream()->expect($this->type, $this->name);
29
30 return $this->name;
31 }
32
33 public function getType()
34 {
35 return $this->type;
36 }
37}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Expression.php b/inc/3rdparty/Twig/Extensions/Grammar/Expression.php
deleted file mode 100644
index 4c33df0e..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Expression.php
+++ /dev/null
@@ -1,22 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Expression extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 return $this->parser->getExpressionParser()->parseExpression();
21 }
22}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Hash.php b/inc/3rdparty/Twig/Extensions/Grammar/Hash.php
deleted file mode 100644
index 98b07d20..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Hash.php
+++ /dev/null
@@ -1,22 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Hash extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:hash>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 return $this->parser->getExpressionParser()->parseHashExpression();
21 }
22}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Number.php b/inc/3rdparty/Twig/Extensions/Grammar/Number.php
deleted file mode 100644
index f0857d20..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Number.php
+++ /dev/null
@@ -1,24 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Number extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:number>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 $this->parser->getStream()->expect(Twig_Token::NUMBER_TYPE);
21
22 return new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
23 }
24}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Optional.php b/inc/3rdparty/Twig/Extensions/Grammar/Optional.php
deleted file mode 100644
index da427485..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Optional.php
+++ /dev/null
@@ -1,69 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Optional extends Twig_Extensions_Grammar
12{
13 protected $grammar;
14
15 public function __construct()
16 {
17 $this->grammar = array();
18 foreach (func_get_args() as $grammar) {
19 $this->addGrammar($grammar);
20 }
21 }
22
23 public function __toString()
24 {
25 $repr = array();
26 foreach ($this->grammar as $grammar) {
27 $repr[] = (string) $grammar;
28 }
29
30 return sprintf('[%s]', implode(' ', $repr));
31 }
32
33 public function addGrammar(Twig_Extensions_GrammarInterface $grammar)
34 {
35 $this->grammar[] = $grammar;
36 }
37
38 public function parse(Twig_Token $token)
39 {
40 // test if we have the optional element before consuming it
41 if ($this->grammar[0] instanceof Twig_Extensions_Grammar_Constant) {
42 if (!$this->parser->getStream()->test($this->grammar[0]->getType(), $this->grammar[0]->getName())) {
43 return array();
44 }
45 } elseif ($this->grammar[0] instanceof Twig_Extensions_Grammar_Name) {
46 if (!$this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
47 return array();
48 }
49 } elseif ($this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) {
50 // if this is not a Constant or a Name, it must be the last element of the tag
51
52 return array();
53 }
54
55 $elements = array();
56 foreach ($this->grammar as $grammar) {
57 $grammar->setParser($this->parser);
58
59 $element = $grammar->parse($token);
60 if (is_array($element)) {
61 $elements = array_merge($elements, $element);
62 } else {
63 $elements[$grammar->getName()] = $element;
64 }
65 }
66
67 return $elements;
68 }
69}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Switch.php b/inc/3rdparty/Twig/Extensions/Grammar/Switch.php
deleted file mode 100644
index 4245f2c8..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Switch.php
+++ /dev/null
@@ -1,24 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Switch extends Twig_Extensions_Grammar
12{
13 public function __toString()
14 {
15 return sprintf('<%s:switch>', $this->name);
16 }
17
18 public function parse(Twig_Token $token)
19 {
20 $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, $this->name);
21
22 return new Twig_Node_Expression_Constant(true, $token->getLine());
23 }
24}
diff --git a/inc/3rdparty/Twig/Extensions/Grammar/Tag.php b/inc/3rdparty/Twig/Extensions/Grammar/Tag.php
deleted file mode 100644
index 727f2610..00000000
--- a/inc/3rdparty/Twig/Extensions/Grammar/Tag.php
+++ /dev/null
@@ -1,56 +0,0 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Extensions_Grammar_Tag extends Twig_Extensions_Grammar
12{
13 protected $grammar;
14
15 public function __construct()
16 {
17 $this->grammar = array();
18 foreach (func_get_args() as $grammar) {
19 $this->addGrammar($grammar);
20 }
21 }
22
23 public function __toString()
24 {
25 $repr = array();
26 foreach ($this->grammar as $grammar) {
27 $repr[] = (string) $grammar;
28 }
29
30 return implode(' ', $repr);
31 }
32
33 public function addGrammar(Twig_Extensions_GrammarInterface $grammar)
34 {
35 $this->grammar[] = $grammar;
36 }
37
38 public function parse(Twig_Token $token)
39 {
40 $elements = array();
41 foreach ($this->grammar as $grammar) {
42 $grammar->setParser($this->parser);
43
44 $element = $grammar->parse($token);
45 if (is_array($element)) {
46 $elements = array_merge($elements, $element);
47 } else {
48 $elements[$grammar->getName()] = $element;
49 }
50 }
51
52 $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
53
54 return $elements;
55 }
56}