/** * Tries to match the following tokens to an <assertion>. * * @throws Exception\UQLSyntaxError * @return bool|ASTAssertion */ public function matchAssertion() { $identifier = $this->nextToken(); if ($identifier['token'] != 'T_IDENTIFIER') { // If a stream doesn't start with an identifier, it's not an <assertion>. $this->rewindToken(); return false; } $operator = $this->matchOperator(); if ($operator === false) { $this->nextToken(); // MatchOperator rewinds $this->throwUnexpectedTokenSyntaxError(['OPERATOR'], 'Comparison operator expected after identifier'); } $array = $this->matchArray(); if ($array) { if ($operator['token'] !== 'T_OP_IN') { throw new UQLSyntaxError("Arrays are only valid after operator IN"); } return new ASTAssertion($identifier['match'], $operator['token'], $array); } $literal = $this->nextToken(); if ($literal['token'] == 'T_FUNCTION_CALL') { return new ASTAssertion($identifier['match'], $operator['token'], ASTFunctionCall::createFromExpression($literal['match'])); } if (strpos($literal['token'], 'T_LITERAL') !== 0) { $this->throwUnexpectedTokenSyntaxError(['ARRAY_START', 'LITERAL'], 'Array, value or function call expected after comparison operator'); } $literal = $this->transformLiteral($literal); return new ASTAssertion($identifier['match'], $operator['token'], $literal['match']); }