From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- inc/3rdparty/Twig/TokenParser/AutoEscape.php | 89 ------------------ inc/3rdparty/Twig/TokenParser/Block.php | 83 ---------------- inc/3rdparty/Twig/TokenParser/Do.php | 42 --------- inc/3rdparty/Twig/TokenParser/Embed.php | 66 ------------- inc/3rdparty/Twig/TokenParser/Extends.php | 52 ---------- inc/3rdparty/Twig/TokenParser/Filter.php | 61 ------------ inc/3rdparty/Twig/TokenParser/Flush.php | 42 --------- inc/3rdparty/Twig/TokenParser/For.php | 136 --------------------------- inc/3rdparty/Twig/TokenParser/From.php | 74 --------------- inc/3rdparty/Twig/TokenParser/If.php | 94 ------------------ inc/3rdparty/Twig/TokenParser/Import.php | 49 ---------- inc/3rdparty/Twig/TokenParser/Include.php | 80 ---------------- inc/3rdparty/Twig/TokenParser/Macro.php | 68 -------------- inc/3rdparty/Twig/TokenParser/Sandbox.php | 68 -------------- inc/3rdparty/Twig/TokenParser/Set.php | 84 ----------------- inc/3rdparty/Twig/TokenParser/Spaceless.php | 59 ------------ inc/3rdparty/Twig/TokenParser/Use.php | 82 ---------------- 17 files changed, 1229 deletions(-) delete mode 100644 inc/3rdparty/Twig/TokenParser/AutoEscape.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Block.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Do.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Embed.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Extends.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Filter.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Flush.php delete mode 100644 inc/3rdparty/Twig/TokenParser/For.php delete mode 100644 inc/3rdparty/Twig/TokenParser/From.php delete mode 100644 inc/3rdparty/Twig/TokenParser/If.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Import.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Include.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Macro.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Sandbox.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Set.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Spaceless.php delete mode 100644 inc/3rdparty/Twig/TokenParser/Use.php (limited to 'inc/3rdparty/Twig/TokenParser') diff --git a/inc/3rdparty/Twig/TokenParser/AutoEscape.php b/inc/3rdparty/Twig/TokenParser/AutoEscape.php deleted file mode 100644 index 27560288..00000000 --- a/inc/3rdparty/Twig/TokenParser/AutoEscape.php +++ /dev/null @@ -1,89 +0,0 @@ - - * {% autoescape true %} - * Everything will be automatically escaped in this block - * {% endautoescape %} - * - * {% autoescape false %} - * Everything will be outputed as is in this block - * {% endautoescape %} - * - * {% autoescape true js %} - * Everything will be automatically escaped in this block - * using the js escaping strategy - * {% endautoescape %} - * - */ -class Twig_TokenParser_AutoEscape extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - - if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { - $value = 'html'; - } else { - $expr = $this->parser->getExpressionParser()->parseExpression(); - if (!$expr instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename()); - } - $value = $expr->getAttribute('value'); - - $compat = true === $value || false === $value; - - if (true === $value) { - $value = 'html'; - } - - if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { - if (false === $value) { - throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); - } - - $value = $stream->next()->getValue(); - } - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endautoescape'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'autoescape'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Block.php b/inc/3rdparty/Twig/TokenParser/Block.php deleted file mode 100644 index a2e017f3..00000000 --- a/inc/3rdparty/Twig/TokenParser/Block.php +++ /dev/null @@ -1,83 +0,0 @@ - - * {% block head %} - * - * {% block title %}{% endblock %} - My Webpage - * {% endblock %} - * - */ -class Twig_TokenParser_Block extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - if ($this->parser->hasBlock($name)) { - throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename()); - } - $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno)); - $this->parser->pushLocalScope(); - $this->parser->pushBlockStack($name); - - if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { - $stream->next(); - - $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - if ($stream->test(Twig_Token::NAME_TYPE)) { - $value = $stream->next()->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename()); - } - } - } else { - $body = new Twig_Node(array( - new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), - )); - } - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $block->setNode('body', $body); - $this->parser->popBlockStack(); - $this->parser->popLocalScope(); - - return new Twig_Node_BlockReference($name, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endblock'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'block'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Do.php b/inc/3rdparty/Twig/TokenParser/Do.php deleted file mode 100644 index f50939dd..00000000 --- a/inc/3rdparty/Twig/TokenParser/Do.php +++ /dev/null @@ -1,42 +0,0 @@ -parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Do($expr, $token->getLine(), $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'do'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Embed.php b/inc/3rdparty/Twig/TokenParser/Embed.php deleted file mode 100644 index 69cb5f35..00000000 --- a/inc/3rdparty/Twig/TokenParser/Embed.php +++ /dev/null @@ -1,66 +0,0 @@ -parser->getStream(); - - $parent = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - // inject a fake parent to make the parent() function work - $stream->injectTokens(array( - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()), - new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()), - new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine()), - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()), - )); - - $module = $this->parser->parse($stream, array($this, 'decideBlockEnd'), true); - - // override the parent with the correct one - $module->setNode('parent', $parent); - - $this->parser->embedTemplate($module); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Embed($module->getAttribute('filename'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endembed'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'embed'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Extends.php b/inc/3rdparty/Twig/TokenParser/Extends.php deleted file mode 100644 index f5ecee21..00000000 --- a/inc/3rdparty/Twig/TokenParser/Extends.php +++ /dev/null @@ -1,52 +0,0 @@ - - * {% extends "base.html" %} - * - */ -class Twig_TokenParser_Extends extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - if (!$this->parser->isMainScope()) { - throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine(), $this->parser->getFilename()); - } - - if (null !== $this->parser->getParent()) { - throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine(), $this->parser->getFilename()); - } - $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'extends'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Filter.php b/inc/3rdparty/Twig/TokenParser/Filter.php deleted file mode 100644 index 2b97475a..00000000 --- a/inc/3rdparty/Twig/TokenParser/Filter.php +++ /dev/null @@ -1,61 +0,0 @@ - - * {% filter upper %} - * This text becomes uppercase - * {% endfilter %} - * - */ -class Twig_TokenParser_Filter extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $name = $this->parser->getVarName(); - $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $token->getLine(), $this->getTag()); - - $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $block = new Twig_Node_Block($name, $body, $token->getLine()); - $this->parser->setBlock($name, $block); - - return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endfilter'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'filter'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Flush.php b/inc/3rdparty/Twig/TokenParser/Flush.php deleted file mode 100644 index 4e15e785..00000000 --- a/inc/3rdparty/Twig/TokenParser/Flush.php +++ /dev/null @@ -1,42 +0,0 @@ -parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Flush($token->getLine(), $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'flush'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/For.php b/inc/3rdparty/Twig/TokenParser/For.php deleted file mode 100644 index 98a6d079..00000000 --- a/inc/3rdparty/Twig/TokenParser/For.php +++ /dev/null @@ -1,136 +0,0 @@ - - * - * - */ -class Twig_TokenParser_For extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); - $stream->expect(Twig_Token::OPERATOR_TYPE, 'in'); - $seq = $this->parser->getExpressionParser()->parseExpression(); - - $ifexpr = null; - if ($stream->test(Twig_Token::NAME_TYPE, 'if')) { - $stream->next(); - $ifexpr = $this->parser->getExpressionParser()->parseExpression(); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideForFork')); - if ($stream->next()->getValue() == 'else') { - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $else = $this->parser->subparse(array($this, 'decideForEnd'), true); - } else { - $else = null; - } - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - if (count($targets) > 1) { - $keyTarget = $targets->getNode(0); - $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine()); - $valueTarget = $targets->getNode(1); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); - } else { - $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); - $valueTarget = $targets->getNode(0); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); - } - - if ($ifexpr) { - $this->checkLoopUsageCondition($stream, $ifexpr); - $this->checkLoopUsageBody($stream, $body); - } - - return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); - } - - public function decideForFork(Twig_Token $token) - { - return $token->test(array('else', 'endfor')); - } - - public function decideForEnd(Twig_Token $token) - { - return $token->test('endfor'); - } - - // the loop variable cannot be used in the condition - protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition', $node->getLine(), $stream->getFilename()); - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageCondition($stream, $n); - } - } - - // check usage of non-defined loop-items - // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - $attribute = $node->getNode('attribute'); - if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) { - throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename()); - } - } - - // should check for parent.loop.XXX usage - if ($node instanceof Twig_Node_For) { - return; - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageBody($stream, $n); - } - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'for'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/From.php b/inc/3rdparty/Twig/TokenParser/From.php deleted file mode 100644 index a54054db..00000000 --- a/inc/3rdparty/Twig/TokenParser/From.php +++ /dev/null @@ -1,74 +0,0 @@ - - * {% from 'forms.html' import forms %} - * - */ -class Twig_TokenParser_From extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect('import'); - - $targets = array(); - do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $alias = $name; - if ($stream->test('as')) { - $stream->next(); - - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - } - - $targets[$name] = $alias; - - if (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - - $stream->next(); - } while (true); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); - - foreach ($targets as $name => $alias) { - $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); - } - - return $node; - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'from'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/If.php b/inc/3rdparty/Twig/TokenParser/If.php deleted file mode 100644 index 3d7d1f51..00000000 --- a/inc/3rdparty/Twig/TokenParser/If.php +++ /dev/null @@ -1,94 +0,0 @@ - - * {% if users %} - * - * {% endif %} - * - */ -class Twig_TokenParser_If extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideIfFork')); - $tests = array($expr, $body); - $else = null; - - $end = false; - while (!$end) { - switch ($stream->next()->getValue()) { - case 'else': - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $else = $this->parser->subparse(array($this, 'decideIfEnd')); - break; - - case 'elseif': - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideIfFork')); - $tests[] = $expr; - $tests[] = $body; - break; - - case 'endif': - $end = true; - break; - - default: - throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename()); - } - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); - } - - public function decideIfFork(Twig_Token $token) - { - return $token->test(array('elseif', 'else', 'endif')); - } - - public function decideIfEnd(Twig_Token $token) - { - return $token->test(array('endif')); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'if'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Import.php b/inc/3rdparty/Twig/TokenParser/Import.php deleted file mode 100644 index e7050c70..00000000 --- a/inc/3rdparty/Twig/TokenParser/Import.php +++ /dev/null @@ -1,49 +0,0 @@ - - * {% import 'forms.html' as forms %} - * - */ -class Twig_TokenParser_Import extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect('as'); - $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->addImportedSymbol('template', $var->getAttribute('name')); - - return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag()); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'import'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Include.php b/inc/3rdparty/Twig/TokenParser/Include.php deleted file mode 100644 index 4a317868..00000000 --- a/inc/3rdparty/Twig/TokenParser/Include.php +++ /dev/null @@ -1,80 +0,0 @@ - - * {% include 'header.html' %} - * Body - * {% include 'footer.html' %} - * - */ -class Twig_TokenParser_Include extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - protected function parseArguments() - { - $stream = $this->parser->getStream(); - - $ignoreMissing = false; - if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) { - $stream->next(); - $stream->expect(Twig_Token::NAME_TYPE, 'missing'); - - $ignoreMissing = true; - } - - $variables = null; - if ($stream->test(Twig_Token::NAME_TYPE, 'with')) { - $stream->next(); - - $variables = $this->parser->getExpressionParser()->parseExpression(); - } - - $only = false; - if ($stream->test(Twig_Token::NAME_TYPE, 'only')) { - $stream->next(); - - $only = true; - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return array($variables, $only, $ignoreMissing); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'include'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Macro.php b/inc/3rdparty/Twig/TokenParser/Macro.php deleted file mode 100644 index 82b4fa6d..00000000 --- a/inc/3rdparty/Twig/TokenParser/Macro.php +++ /dev/null @@ -1,68 +0,0 @@ - - * {% macro input(name, value, type, size) %} - * - * {% endmacro %} - * - */ -class Twig_TokenParser_Macro extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $this->parser->pushLocalScope(); - $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - if ($stream->test(Twig_Token::NAME_TYPE)) { - $value = $stream->next()->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename()); - } - } - $this->parser->popLocalScope(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag())); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endmacro'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'macro'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Sandbox.php b/inc/3rdparty/Twig/TokenParser/Sandbox.php deleted file mode 100644 index 9457325a..00000000 --- a/inc/3rdparty/Twig/TokenParser/Sandbox.php +++ /dev/null @@ -1,68 +0,0 @@ - - * {% sandbox %} - * {% include 'user.html' %} - * {% endsandbox %} - * - * - * @see http://www.twig-project.org/doc/api.html#sandbox-extension for details - */ -class Twig_TokenParser_Sandbox extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - // in a sandbox tag, only include tags are allowed - if (!$body instanceof Twig_Node_Include) { - foreach ($body as $node) { - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { - continue; - } - - if (!$node instanceof Twig_Node_Include) { - throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section', $node->getLine(), $this->parser->getFilename()); - } - } - } - - return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endsandbox'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'sandbox'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Set.php b/inc/3rdparty/Twig/TokenParser/Set.php deleted file mode 100644 index 70e0b41b..00000000 --- a/inc/3rdparty/Twig/TokenParser/Set.php +++ /dev/null @@ -1,84 +0,0 @@ - - * {% set foo = 'foo' %} - * - * {% set foo = [1, 2] %} - * - * {% set foo = {'foo': 'bar'} %} - * - * {% set foo = 'foo' ~ 'bar' %} - * - * {% set foo, bar = 'foo', 'bar' %} - * - * {% set foo %}Some content{% endset %} - * - */ -class Twig_TokenParser_Set extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); - - $capture = false; - if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) { - $stream->next(); - $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - if (count($names) !== count($values)) { - throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignments.", $stream->getCurrent()->getLine(), $stream->getFilename()); - } - } else { - $capture = true; - - if (count($names) > 1) { - throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $stream->getCurrent()->getLine(), $stream->getFilename()); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $values = $this->parser->subparse(array($this, 'decideBlockEnd'), true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - } - - return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endset'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'set'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Spaceless.php b/inc/3rdparty/Twig/TokenParser/Spaceless.php deleted file mode 100644 index 1e3fa8f3..00000000 --- a/inc/3rdparty/Twig/TokenParser/Spaceless.php +++ /dev/null @@ -1,59 +0,0 @@ - - * {% spaceless %} - *
- * foo - *
- * {% endspaceless %} - * - * {# output will be
foo
#} - * - */ -class Twig_TokenParser_Spaceless extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideSpacelessEnd'), true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Spaceless($body, $lineno, $this->getTag()); - } - - public function decideSpacelessEnd(Twig_Token $token) - { - return $token->test('endspaceless'); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'spaceless'; - } -} diff --git a/inc/3rdparty/Twig/TokenParser/Use.php b/inc/3rdparty/Twig/TokenParser/Use.php deleted file mode 100644 index bc0e09ef..00000000 --- a/inc/3rdparty/Twig/TokenParser/Use.php +++ /dev/null @@ -1,82 +0,0 @@ - - * {% extends "base.html" %} - * - * {% use "blocks.html" %} - * - * {% block title %}{% endblock %} - * {% block content %}{% endblock %} - * - * - * @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details. - */ -class Twig_TokenParser_Use extends Twig_TokenParser -{ - /** - * Parses a token and returns a node. - * - * @param Twig_Token $token A Twig_Token instance - * - * @return Twig_NodeInterface A Twig_NodeInterface instance - */ - public function parse(Twig_Token $token) - { - $template = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - - if (!$template instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getFilename()); - } - - $targets = array(); - if ($stream->test('with')) { - $stream->next(); - - do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $alias = $name; - if ($stream->test('as')) { - $stream->next(); - - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - } - - $targets[$name] = new Twig_Node_Expression_Constant($alias, -1); - - if (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - - $stream->next(); - } while (true); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets)))); - } - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag() - { - return 'use'; - } -} -- cgit v1.2.3