/** * @param Lexer $lexer * @param char $char */ public function input(Lexer $lexer, $char) { if ($this->escaping) { $this->buffer .= $char; $this->escaping = false; } else { if ($char == "'") { $lexer->pushOperand(new TokenLiteral($this->buffer)); $this->closed = true; } else { if ($char == '\\') { $this->escaping = true; } else { if ($this->closed) { if ($char == ',') { $lexer->incrementLastFunctionArity(); $lexer->setStateEmpty(); } else { if ($char == ')') { $lexer->closeParenthesis(); } else { if (self::isBlank($char)) { } else { if ($char == '+' || $char == '-') { $lexer->pushOperator(new TokenPlusMinus($char)); } else { if ($char == '=' || $char == '!') { $lexer->setStateComparison($char); } else { if ($char == '*') { $lexer->pushOperator(new TokenMul()); } else { if ($char == ']') { $lexer->closeSquareBracket(); } else { $this->throwError($lexer, $char); } } } } } } } } else { $this->buffer .= $char; } } } } }
/** * @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); } } } } } } }
/** * @param Lexer $lexer */ protected function pushRParen(Lexer $lexer) { $lexer->pushOperand(new TokenLiteral($this->buffer)); $lexer->closeParenthesis(); }
/** * @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; } }