/**
  * 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();
     $vars = new \Twig_Node_Expression_Array(array(), $lineno);
     $body = null;
     $count = $this->parser->getExpressionParser()->parseExpression();
     $domain = new \Twig_Node_Expression_Constant('messages', $lineno);
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test('for')) {
         // {% transchoice count for "message" %}
         // {% transchoice count for message %}
         $stream->next();
         $body = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('with')) {
         // {% transchoice count with vars %}
         $stream->next();
         $vars = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('from')) {
         // {% transchoice count from "messages" %}
         $stream->next();
         $domain = $this->parser->getExpressionParser()->parseExpression();
     }
     if (null === $body) {
         // {% transchoice count %}message{% endtranschoice %}
         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
         $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
     }
     if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
         throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1);
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new TransNode($body, $domain, $count, $vars, $lineno, $this->getTag());
 }
Example #2
0
 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $arguments = array();
     // name - the new variable with the results
     $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '=');
     // contenttype, or simple expression to content.
     $contenttype = $this->parser->getExpressionParser()->parseExpression();
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'where')) {
         $this->parser->getStream()->next();
         $where = $this->parser->getExpressionParser()->parseHashExpression();
         $arguments = $this->convertToViewArguments($where);
     }
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'limit')) {
         $this->parser->getStream()->next();
         $limit = $this->parser->getExpressionParser()->parsePrimaryExpression()->getAttribute('value');
         $arguments['limit'] = $limit;
     }
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'order') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'orderby')) {
         $this->parser->getStream()->next();
         $order = $this->parser->getExpressionParser()->parsePrimaryExpression()->getAttribute('value');
         $arguments['order'] = $order;
     }
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'paging') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'allowpaging')) {
         $this->parser->getStream()->next();
         $arguments['paging'] = true;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Bolt_Setcontent_Node($name, $contenttype, $arguments, $lineno, $this->getTag());
 }
Example #3
0
 /**
  * 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();
     $stream = $this->parser->getStream();
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new \phpbb\template\twig\node\includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
 }
Example #4
0
 /**
  * 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();
     $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, 'in');
     $seq = $this->parser->getExpressionParser()->parseExpression();
     $withLoop = true;
     if ($this->parser->getStream()->test('without')) {
         $this->parser->getStream()->next();
         $this->parser->getStream()->expect('loop');
         $withLoop = false;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideForFork'));
     if ($this->parser->getStream()->next()->getValue() == 'else') {
         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
         $else = $this->parser->subparse(array($this, 'decideForEnd'), true);
     } else {
         $else = null;
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     if (count($targets) > 1) {
         $keyTarget = $targets->getNode(0);
         $valueTarget = $targets->getNode(1);
     } else {
         $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
         $valueTarget = $targets->getNode(0);
     }
     return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $withLoop, $lineno, $this->getTag());
 }
 /**
  * Parses {% requireEdition %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return RequireEdition_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $editionName = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new RequireEdition_Node(array('editionName' => $editionName), array(), $lineno, $this->getTag());
 }
 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $variable = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $stream->expect(\Twig_Token::NAME_TYPE, 'from');
     $collectionType = $this->parser->getExpressionParser()->parseAssignmentExpression();
     $collectionFilters = null;
     if ($stream->test(\Twig_Token::PUNCTUATION_TYPE, '|')) {
         $collectionFilters = $this->parser->getExpressionParser()->parsePostfixExpression($collectionType);
     }
     $parameters = null;
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $parameters = $this->parser->getExpressionParser()->parseExpression();
     }
     $ifExpression = null;
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'if')) {
         $ifExpression = $this->parser->getExpressionParser()->parseExpression();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse([$this, 'decideGimmeListFork']);
     if ($stream->next()->getValue() == 'else') {
         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
         $else = $this->parser->subparse([$this, 'decideGimmeListEnd'], true);
     } else {
         $else = null;
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new GimmeListNode($variable, $collectionType, $collectionFilters, $parameters, $ifExpression, $else, $body, $lineno, $this->getTag());
 }
 /**
  * Parses {% redirect %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return Redirect_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $path = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Redirect_Node(array('path' => $path), array(), $lineno, $this->getTag());
 }
 /**
  * {@inheritDoc}
  */
 public function parse(\Twig_Token $token)
 {
     $stream = $this->parser->getStream();
     $expressionParser = $this->parser->getExpressionParser();
     if ($stream->test(\Twig_Token::NAME_TYPE)) {
         $currentToken = $stream->getCurrent();
         $currentValue = $currentToken->getValue();
         $currentLine = $currentToken->getLine();
         // Creates expression: placeholder_name|default('placeholder_name')
         // To parse either variable value or name
         $name = new \Twig_Node_Expression_Filter_Default(new \Twig_Node_Expression_Name($currentValue, $currentLine), new \Twig_Node_Expression_Constant('default', $currentLine), new \Twig_Node(array(new \Twig_Node_Expression_Constant($currentValue, $currentLine)), array(), $currentLine), $currentLine);
         $stream->next();
     } else {
         $name = $expressionParser->parseExpression();
     }
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $variables = $expressionParser->parseExpression();
     } else {
         $variables = new \Twig_Node_Expression_Constant(array(), $token->getLine());
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     // build expression to call 'placeholder' function
     $expr = new \Twig_Node_Expression_Function('placeholder', new \Twig_Node(array('name' => $name, 'variables' => $variables)), $token->getLine());
     return new \Twig_Node_Print($expr, $token->getLine(), $this->getTag());
 }
Example #9
0
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $type = $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new OutputNode($type, $lineno, $this->getTag());
 }
Example #10
0
 /**
  * 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();
     $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
 }
 /**
  * Parses {% requireLogin %} tags.
  *
  * @param \Twig_Token $token
  *
  * @return RequireLogin_Node
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $header = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Header_Node(array('header' => $header), array(), $lineno, $this->getTag());
 }
Example #12
0
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     // 'svg'
     $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
     // %} (from {% stamp %})
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $aboveDumps = [];
     while (true) {
         // everything above {% stamp_dump %}
         $aboveDumps[] = $this->parser->subparse(function (\Twig_Token $token) {
             return $token->test('stamp_dump');
         });
         // allow nested {% stamp %} usage using distinct names
         $dumpName = $stream->next() && $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
         if ($dumpName == $name) {
             break;
         }
     }
     // %} (from {% stamp_dump %})
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     // everything below {% stamp_dump %}
     $belowDump = $this->parser->subparse(function (\Twig_Token $token) {
         return $token->test('endstamp');
     });
     // %} (from {% endstamp %})
     $stream->next() && $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new StampNode($name, $aboveDumps, $belowDump, $lineno, $this->getTag());
 }
Example #13
0
 /**
  * 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)
 {
     $stream = $this->parser->getStream();
     $collection = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new TwigAssets_Node_UseAsset($collection, $token->getLine(), $this->getTag());
 }
Example #14
0
 public function parse(Twig_Token $token)
 {
     $lineno = $token->getLine();
     $expr = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideIfFork'));
     $tests = array(array($expr, $body));
     $else = null;
     $end = false;
     while (!$end) {
         try {
             switch ($this->parser->getStream()->next()->getValue()) {
                 case 'else':
                     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
                     $else = $this->parser->subparse(array($this, 'decideIfEnd'));
                     break;
                 case 'elseif':
                     $expr = $this->parser->getExpressionParser()->parseExpression();
                     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
                     $body = $this->parser->subparse(array($this, 'decideIfFork'));
                     $tests[] = array($expr, $body);
                     break;
                 case 'endif':
                     $end = true;
                     break;
                 default:
                     throw new Twig_SyntaxError('', -1);
             }
         } catch (Twig_SyntaxError $e) {
             throw new Twig_SyntaxError(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), -1);
         }
     }
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_If($tests, $else, $lineno, $this->getTag());
 }
 /**
  * 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)
 {
     $parser = $this->parser;
     $stream = $parser->getStream();
     $default = null;
     $cases = array();
     $end = false;
     $name = $parser->getExpressionParser()->parseExpression();
     $stream->expect(Twig_Token::BLOCK_END_TYPE);
     $stream->expect(Twig_Token::TEXT_TYPE);
     $stream->expect(Twig_Token::BLOCK_START_TYPE);
     while (!$end) {
         $v = $stream->next();
         switch ($v->getValue()) {
             case 'default':
                 $stream->expect(Twig_Token::BLOCK_END_TYPE);
                 $default = $parser->subparse(array($this, 'decideIfEnd'));
                 break;
             case 'case':
                 $expr = $parser->getExpressionParser()->parseExpression();
                 $stream->expect(Twig_Token::BLOCK_END_TYPE);
                 $body = $parser->subparse(array($this, 'decideIfFork'));
                 $cases[] = $expr;
                 $cases[] = $body;
                 break;
             case 'endswitch':
                 $end = true;
                 break;
             default:
                 throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $lineno), -1);
         }
     }
     $stream->expect(Twig_Token::BLOCK_END_TYPE);
     return new Twig_Node_Switch($name, new Twig_Node($cases), $default, $token->getLine(), $this->getTag());
 }
 /**
  * Parses a token and returns a node.
  *
  * @param \Twig_Token $token A Twig_Token instance
  *
  * @return \Twig_Node A Twig_Node instance
  *
  * @throws \Twig_Error_Syntax
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $vars = new \Twig_Node_Expression_Array(array(), $lineno);
     $count = $this->parser->getExpressionParser()->parseExpression();
     $domain = null;
     $locale = null;
     if ($stream->test('with')) {
         // {% transchoice count with vars %}
         $stream->next();
         $vars = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('from')) {
         // {% transchoice count from "messages" %}
         $stream->next();
         $domain = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('into')) {
         // {% transchoice count into "fr" %}
         $stream->next();
         $locale = $this->parser->getExpressionParser()->parseExpression();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
     if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
         throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $body = NULL;
     $options = NULL;
     $count = NULL;
     $plural = NULL;
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test(\Twig_Token::STRING_TYPE)) {
         $body = $this->parser->getExpressionParser()->parseExpression();
     }
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test(\Twig_Token::NAME_TYPE, 'with')) {
         $stream->next();
         $options = $this->parser->getExpressionParser()->parseExpression();
     }
     if (!$body) {
         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
         $body = $this->parser->subparse(array($this, 'decideForFork'));
         if ('plural' === $stream->next()->getValue()) {
             $count = $this->parser->getExpressionParser()->parseExpression();
             $stream->expect(\Twig_Token::BLOCK_END_TYPE);
             $plural = $this->parser->subparse(array($this, 'decideForEnd'), TRUE);
         }
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $this->checkTransString($body, $lineno);
     $node = new TwigNodeTrans($body, $plural, $count, $options, $lineno, $this->getTag());
     return $node;
 }
Example #18
0
 public function parse(\Twig_Token $token)
 {
     $parser = $this->parser;
     $stream = $parser->getStream();
     $id = $parser->getExpressionParser()->parseExpression();
     $type = null;
     $optional = false;
     $options = null;
     while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
         if ($stream->test(\Twig_Token::NAME_TYPE, 'optional')) {
             $optional = true;
             $stream->next();
             continue;
         }
         if ($stream->test(\Twig_Token::NAME_TYPE, 'type')) {
             $stream->next();
             $type = $this->parser->getExpressionParser()->parseExpression();
             continue;
         }
         if ($stream->test(\Twig_Token::NAME_TYPE, 'set')) {
             $stream->next();
             $options = $this->parser->getExpressionParser()->parseExpression();
             continue;
         }
         $stream->next();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new NodeContent($this->name, $id, $type, $optional, $options, $token->getLine(), $this->getTag());
 }
 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $class = null;
     $tag = null;
     $language = null;
     $lineNumber = $token->getLine();
     $stream = $this->parser->getStream();
     $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
     $var = $stream->expect(\Twig_Token::NAME_TYPE)->getValue();
     $field = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
     if ($stream->test("tag")) {
         $stream->next();
         $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
         $tag = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test("class")) {
         $stream->next();
         $stream->expect(\Twig_Token::OPERATOR_TYPE, "=");
         $class = $this->parser->getExpressionParser()->parseExpression();
     }
     if ($stream->test('language')) {
         $stream->next();
         $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
         $language = $this->parser->getExpressionParser()->parseExpression();
     }
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
         throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "tag", "class" or "language" keyword.');
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new ContentNode($name, $var, $field, $tag, $class, $language, $lineNumber, $this->getTag());
 }
Example #20
0
 /**
  * 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)
 {
     $stream = $this->parser->getStream();
     $value = $this->parser->getExpressionParser()->parseExpression();
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new JSNode($value, $token->getLine(), $this->getTag());
 }
 /**
  * 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();
     $value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
     return new bitExpert_Silex_Twig_Translation_Node_Translate($value, $lineno, $this->getTag());
 }
Example #22
0
 /**
  * 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);
     return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
 }
 /**
  * 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->addImportedFunction($alias, $name, $node->getNode('var'));
     }
     return $node;
 }
 /**
  * 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();
     if (!$template instanceof Twig_Node_Expression_Constant) {
         throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $token->getLine());
     }
     $stream = $this->parser->getStream();
     $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))));
     return null;
 }
 /**
  * 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();
     $vars = new \Twig_Node_Expression_Array(array(), $lineno);
     $domain = null;
     $locale = null;
     if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
         if ($stream->test('with')) {
             // {% trans with vars %}
             $stream->next();
             $vars = $this->parser->getExpressionParser()->parseExpression();
         }
         if ($stream->test('from')) {
             // {% trans from "messages" %}
             $stream->next();
             $domain = $this->parser->getExpressionParser()->parseExpression();
         }
         if ($stream->test('into')) {
             // {% trans into "fr" %}
             $stream->next();
             $locale = $this->parser->getExpressionParser()->parseExpression();
         } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
             throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.');
         }
     }
     // {% trans %}message{% endtrans %}
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $body = $this->parser->subparse(array($this, 'decideTransFork'), true);
     if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
         throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text');
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new TransNode($body, $domain, null, $vars, $locale, $lineno, $this->getTag());
 }
Example #26
0
 /**
  * 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_SyntaxError("The block '{$name}' has already been defined", $lineno);
     }
     $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_SyntaxError(sprintf("Expected endblock for block '{$name}' (but %s given)", $value), $lineno);
             }
         }
     } else {
         $body = new Twig_Node(array(new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno)));
     }
     $stream->expect(Twig_Token::BLOCK_END_TYPE);
     $block = new Twig_Node_Block($name, $body, $lineno);
     $this->parser->setBlock($name, $block);
     $this->parser->popBlockStack();
     return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
 }
Example #27
0
 /**
  * {@inheritdoc}
  *
  * @param  \Twig_Token         $token
  * @return \Twig_NodeInterface
  */
 public function parse(\Twig_Token $token)
 {
     $methodName = $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE)->getValue();
     $arguments = $this->parser->getExpressionParser()->parseArguments();
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new Node(array('arguments' => $arguments), array('methodName' => $methodName), $token->getLine(), $this->getTag());
 }
Example #28
0
 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->nextIf('as')) {
             $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
         }
         $targets[$name] = $alias;
         if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
             break;
         }
     } 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) {
         if ($this->parser->isReservedMacroName($name)) {
             throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getFilename());
         }
         $this->parser->addImportedSymbol('function', $alias, 'get' . $name, $node->getNode('var'));
     }
     return $node;
 }
 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $parser = $this->parser;
     $stream = $parser->getStream();
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new TwigJsResultNode($token->getLine(), $this->getTag());
 }
Example #30
0
	public function parse(Twig_Token $token)
	{
		$lineNo = $token->getLine();
		$name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
		$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
		return new Interspire_Template_Node_Snippet($name, $lineNo);
	}