Exemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param Stream     $stream
  * @param Token|null $expected
  */
 public function __construct(Stream $stream, Token $expected = null)
 {
     $this->actual = $stream->current();
     $this->expected = $expected;
     $this->tokenLine = $this->actual->getLine();
     $message = sprintf('Unexpected token %s at line %d ("%s").', (string) $this->actual, $this->tokenLine, $stream->humanize());
     if ($this->expected !== null) {
         $message = sprintf('%s Expects token %s.', $message, (string) $this->expected);
     }
     parent::__construct($message);
 }
Exemplo n.º 2
0
 /**
  * @param Stream $stream
  *
  * @return NodeInterface
  */
 private function parseExport(Stream $stream)
 {
     $stream->expects(Token::TYPE_KEYWORD, 'export');
     if ($stream->current()->equals(Token::TYPE_KEYWORD, 'type')) {
         $stream->expects(Token::TYPE_KEYWORD, 'type');
         $typeName = $this->parseIdentifier($stream);
         $alias = null;
         if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
             $stream->expects(Token::TYPE_KEYWORD, 'as');
             $alias = $this->parseIdentifier($stream);
         }
         $stream->expects(Token::TYPE_SYMBOL, ';');
         return new MapperExportNode($typeName, $alias);
     }
     if ($stream->current()->equals(Token::TYPE_KEYWORD, 'function')) {
         $stream->expects(Token::TYPE_KEYWORD, 'function');
         $functionName = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
         $alias = null;
         if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
             $stream->expects(Token::TYPE_KEYWORD, 'as');
             $alias = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
         }
         $stream->expects(Token::TYPE_SYMBOL, ';');
         return new BlueprintExportNode($functionName, $alias);
     }
     if ($stream->current()->equals(Token::TYPE_KEYWORD, 'template')) {
         $stream->expects(Token::TYPE_KEYWORD, 'template');
         $templateName = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
         $alias = null;
         if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
             $stream->expects(Token::TYPE_KEYWORD, 'as');
             $alias = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
         }
         $stream->expects(Token::TYPE_SYMBOL, ';');
         return new BlueprintExportNode($templateName, $alias);
     }
     throw new ParserException(sprintf('Can\'t parse the stream "%s". Expects the keyword "type", "function" or "template".', $stream->humanize()));
 }