Example #1
0
 /**
  * @param Lexer $lexer
  * @param char $char
  */
 public function input(Lexer $lexer, $char)
 {
     //Valid inputs in this state are:
     // - Slash (/) means that we are talking about the Path Element: Dot,
     // - any digit, means that we are talking about a Decimal,
     // - dot, means that we are talking about the Path Element: Parent.
     // - comma, means that the current argument of a function is the Current path.
     //TODO: and also closing parenthesis, closing square bracket, blank.
     if ($char == '/') {
         $lexer->pushPath(new PathElementCurrent());
     } else {
         if (self::isDigit($char)) {
             $lexer->setStateDecimal('0.' . $char);
         } else {
             if ($char == '.') {
                 $lexer->setStateDotdot();
             } else {
                 if ($char == ',') {
                     $lexer->pushOperand(new TokenPath(new PathElementCurrent()));
                     $lexer->incrementLastFunctionArity();
                 } else {
                     if ($char == ')') {
                         $lexer->pushOperand(new TokenPath(new PathElementCurrent()));
                         $lexer->closeParenthesis();
                     } else {
                         if (self::isBlank($char)) {
                             $lexer->pushPath(new PathElementCurrent());
                             $lexer->setStateClosedExpression();
                         } else {
                             $this->throwError($lexer, $char);
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @param Lexer $lexer
  */
 private function pushKeyword($lexer)
 {
     switch ($this->buffer) {
         case 'or':
             $lexer->pushOperator(new TokenOr());
             break;
         case 'and':
             $lexer->pushOperator(new TokenAnd());
             break;
         case 'div':
             $lexer->pushOperator(new TokenDiv());
             break;
         case 'mod':
             $lexer->pushOperator(new TokenMod());
             break;
         case 'true':
             $lexer->pushOperand(new TokenLiteral(true));
             $lexer->setStateClosedExpression();
             break;
         case 'false':
             $lexer->pushOperand(new TokenLiteral(false));
             $lexer->setStateClosedExpression();
             break;
         case 'gt':
         case 'gte':
         case 'lt':
         case 'lte':
             $lexer->pushOperator(new TokenComparisonBinop($this->buffer));
             break;
         case 'not':
             $lexer->pushOperator(new TokenNot());
             break;
     }
 }