Example #1
0
 /**
  * Parse primary expression.
  *
  * @return Node The primary node.
  * @throws SyntaxErrorException if no operand or unary operator can be found.
  */
 private function parsePrimary()
 {
     /* @var Token $token */
     $token = $this->stream->current();
     if ($token && $this->operatorTable->isUnary($token)) {
         $this->stream->next();
         $operator = $this->operatorTable->getUnaryOperator($token);
         $operatorNode = $operator->getNode();
         $node = $operatorNode($this->parseExpression($operator->getPrecedence()));
     } else {
         if ($token) {
             $node = $this->parseOperand();
             $this->stream->next();
         } else {
             throw new SyntaxErrorException('Operand or unary operator expected; but end of stream reached');
         }
     }
     return $node;
 }
Example #2
0
 /**
  * Test if the `getUnaryOperator` method throws an exception if the requested operator doesn't exists.
  *
  * @expectedException \com\mohiva\pyramid\exceptions\UnsupportedOperatorException
  */
 public function testGetUnaryOperatorThrowsException()
 {
     $token = new Token(1, '+', 1);
     $table = new OperatorTable();
     $table->getUnaryOperator($token);
 }