Beispiel #1
0
 protected function _unexpectedToken(TokenInterface $actual, $expected)
 {
     /*{{{*/
     $msg = null;
     if ($this->debug) {
         $source = $this->lexer->getSource();
         $file = $source instanceof Source\File ? $source->getUrl() : 'internal_string';
         $name = $this->lexer->getTokenName($actual->type);
         $name .= ' (' . print_r($actual->value, true) . ')';
         if (is_array($expected)) {
             $types = array();
             foreach ($expected as $type) {
                 $types[] = $this->lexer->getTokenName($type);
             }
             $expected = implode(', ', $types);
         } else {
             $expected = $this->lexer->getTokenName($expected);
         }
         $msg = sprintf("Unexpected token %s, expected %s", $name, $expected);
         if ($actual instanceof LineToken) {
             $msg = sprintf("%s in %s on line %s, column %s", $msg, $file, $actual->line, $actual->column);
         } else {
             $msg = sprintf("%s in %s at position %s", $msg, $file, $actual->position);
         }
     }
     throw new UnexpectedTokenException($msg);
 }
Beispiel #2
0
 protected function _unexpectedToken(Token $actual, $expected)
 {
     $source = $this->lexer->getSource();
     $file = $source instanceof Source\File ? $source->getUrl() : 'internal_string';
     //$position = $actual->getPosition();
     //$line = $source->getLine($position);
     //$column = $source->getColumn($position, $line);
     $name = $this->lexer->getTokenName($actual->type);
     $name .= ' (' . print_r($actual->value, true) . ')';
     if (is_array($expected)) {
         $types = array();
         foreach ($expected as $type) {
             $types[] = $this->lexer->getTokenName($type);
         }
         $expected = implode(', ', $types);
     } else {
         $expected = $this->lexer->getTokenName($expected);
     }
     throw new UnexpectedTokenException($name, $expected, $file, $actual->line, $actual->column);
 }