示例#1
0
 /**
  * Determine if $node is in fact a unary operator.
  *
  * If $node can be a unary operator (i.e. is a '+' or '-' node),
  * **and** this is the first node we parse or the previous node
  * was a SubExpressionNode, i.e. an opening parenthesis, or the
  * previous node was already a unary minus, this means that the
  * current node is in fact a unary '+' or '-' and we return true,
  * otherwise we return false.
  *
  * @param Node $node Current node
  * @param Node|null $lastNode Previous node handled by the Parser
  * @retval boolean
  */
 protected function isUnary($node, $lastNode)
 {
     if (!$node->canBeUnary()) {
         return false;
     }
     // Unary if it is the first token
     if ($this->operatorStack->isEmpty() && $this->operandStack->isEmpty()) {
         return true;
     }
     // or if the previous token was '('
     if ($lastNode instanceof SubExpressionNode) {
         return true;
     }
     // or last node was already a unary minus
     if ($lastNode instanceof ExpressionNode && $lastNode->getOperator() == '~') {
         return true;
     }
     return false;
 }