Example #1
0
 public function parse(Apishka_Templater_Token $token)
 {
     if (!$this->parser->isMainScope()) {
         throw new Apishka_Templater_Error_Syntax('Cannot extend from a block.', $token->getLine(), $this->parser->getFilename());
     }
     if (null !== $this->parser->getParent()) {
         throw new Apishka_Templater_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $this->parser->getFilename());
     }
     $parent = $this->parser->getExpressionParser()->parseExpression();
     $stream = $this->parser->getStream();
     $options = array();
     while (!$stream->test(Apishka_Templater_Token::BLOCK_END_TYPE)) {
         $token = $stream->expect(Apishka_Templater_Token::NAME_TYPE);
         $name = $token->getValue();
         $stream->expect(Apishka_Templater_Token::OPERATOR_TYPE, '=');
         $options[$name] = $this->parser->getExpressionParser()->parseExpression();
     }
     $parent->setAttribute('parent_options', $options);
     $this->parser->setParent($parent);
     $stream->expect(Apishka_Templater_Token::BLOCK_END_TYPE);
 }
Example #2
0
 public function decideBlockEnd(Apishka_Templater_Token $token)
 {
     return $token->test('endblock');
 }
Example #3
0
 public function parseHashExpression()
 {
     $stream = $this->parser->getStream();
     $stream->expect(Apishka_Templater_Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
     $node = Apishka_Templater_Node_Expression_Array::apishka(array(), $stream->getCurrent()->getLine());
     $first = true;
     while (!$stream->test(Apishka_Templater_Token::PUNCTUATION_TYPE, '}')) {
         if (!$first) {
             $stream->expect(Apishka_Templater_Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma');
             // trailing ,?
             if ($stream->test(Apishka_Templater_Token::PUNCTUATION_TYPE, '}')) {
                 break;
             }
         }
         $first = false;
         // a hash key can be:
         //
         //  * a number -- 12
         //  * a string -- 'a'
         //  * a name, which is equivalent to a string -- a
         //  * an expression, which must be enclosed in parentheses -- (1 + 2)
         if (($token = $stream->nextIf(Apishka_Templater_Token::STRING_TYPE)) || ($token = $stream->nextIf(Apishka_Templater_Token::NAME_TYPE)) || ($token = $stream->nextIf(Apishka_Templater_Token::NUMBER_TYPE))) {
             $key = Apishka_Templater_Node_Expression_Constant::apishka($token->getValue(), $token->getLine());
         } elseif ($stream->test(Apishka_Templater_Token::PUNCTUATION_TYPE, '(')) {
             $key = $this->parseExpression();
         } else {
             $current = $stream->getCurrent();
             throw new Apishka_Templater_Error_Syntax(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Apishka_Templater_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $this->parser->getFilename());
         }
         $stream->expect(Apishka_Templater_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
         $value = $this->parseExpression();
         $node->addElement($value, $key);
     }
     $stream->expect(Apishka_Templater_Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
     return $node;
 }
Example #4
0
 public function decideIfEnd(Apishka_Templater_Token $token)
 {
     return $token->test(array('endif'));
 }
Example #5
0
 public function parse(Apishka_Templater_Token $token)
 {
     $expr = $this->parser->getExpressionParser()->parseExpression();
     $this->parser->getStream()->expect(Apishka_Templater_Token::BLOCK_END_TYPE);
     return Apishka_Templater_Node_Do::apishka($expr, $token->getLine(), $this->getTag());
 }
Example #6
0
 public function decideForEnd(Apishka_Templater_Token $token)
 {
     return $token->test('endfor');
 }