Пример #1
0
 /**
  * Parse unary operator (- ,not)
  * 
  * @return AbstractExpression
  */
 private function _parseUnary()
 {
     $this->_recurseEnter();
     if ($this->_getCurrentToken()->Id == ExpressionTokenId::MINUS || $this->_getCurrentToken()->identifierIs(ODataConstants::KEYWORD_NOT)) {
         $op = clone $this->_getCurrentToken();
         $this->_lexer->nextToken();
         if ($op->Id == ExpressionTokenId::MINUS && ExpressionLexer::isNumeric($this->_getCurrentToken()->Id)) {
             $numberLiteral = $this->_getCurrentToken();
             $numberLiteral->Text = '-' . $numberLiteral->Text;
             $numberLiteral->Position = $op->Position;
             $v = $this->_getCurrentToken();
             $this->_setCurrentToken($numberLiteral);
             $this->_recurseLeave();
             return $this->_parsePrimary();
         }
         $expr = $this->_parsePrimary();
         FunctionDescription::validateUnaryOpArguments($op, $expr);
         if ($op->Id == ExpressionTokenId::MINUS) {
             $expr = new UnaryExpression($expr, ExpressionType::NEGATE, $expr->getType());
         } else {
             $expr = new UnaryExpression($expr, ExpressionType::NOT_LOGICAL, new Boolean());
         }
         $this->_recurseLeave();
         return $expr;
     }
     $this->_recurseLeave();
     return $this->_parsePrimary();
 }
Пример #2
0
 /**
  * Process an unary expression node for nullability 
  * 
  * @param UnaryExpression    $expression       The unary expression node
  *                                             to process.
  * @param AbstractExpression $parentExpression The parent expression of 
  *                                             expression node to process.
  * 
  * @return LogicalExpression|null
  */
 private function _processUnaryNode(UnaryExpression $expression, $parentExpression)
 {
     if ($expression->getNodeType() == ExpressionType::NEGATE) {
         return $this->_processNodeForNullability($expression->getChild(), $expression);
     }
     if ($expression->getNodeType() == ExpressionType::NOT_LOGICAL) {
         $resultExpression = $this->_processNodeForNullability($expression->getChild(), $expression);
         if ($resultExpression == null) {
             return null;
         }
         if ($parentExpression == null) {
             return new LogicalExpression($resultExpression, $expression, ExpressionType::AND_LOGICAL);
         }
         return $resultExpression;
     }
     throw ODataException::createSyntaxError(Messages::expressionParser2UnexpectedExpression(get_class($expression)));
 }