예제 #1
0
 /**
  * Throw a syntax error
  *
  * @param string $expected
  * @throws ParserException
  */
 private function syntaxError($expected)
 {
     $token = $this->lexer->lookahead;
     $tokenPosition = isset($token['position']) ? $token['position'] : '-1';
     $message = sprintf('line 0, col %s: Error: Expected %s, got ', $tokenPosition, $expected);
     if ($this->lexer->lookahead === null) {
         $message .= 'end of string';
     } else {
         $message .= $this->lexer->getLiteral($token['type']);
     }
     throw new ParserException($message);
 }
예제 #2
0
 /**
  * Assert an expected token
  *
  * @param mixed $expected
  * @param mixed $actual
  */
 private function assertToken($expected, $actual)
 {
     $this->assertEquals($expected, $actual, sprintf('Expected %s, got %s', $this->lexer->getLiteral($expected), $this->lexer->getLiteral($actual)));
 }