pub struct Parser { /* private fields */ }Expand description
A recursive-descent parser of SELECT statements.
Reads filtered tokens (no whitespace or comments, ending with
TokenType::Eof, as Tokenizer::filter returns them) and builds a
Select that a Walker can rewrite and a
Serializer write back. Not to be confused with the
classifier, which only reads a statement’s leading
keyword.
PHP: Utopia\Query\AST\Parser.
use utopia_query::ast::{Expression, Parser};
use utopia_query::tokenizer::Tokenizer;
let tokens = Tokenizer::filter(Tokenizer::new().tokenize("SELECT name FROM users WHERE age > 18")?);
let select = Parser::new().parse(&tokens)?;
assert!(matches!(select.where_clause, Some(Expression::Binary(ref b)) if b.operator == ">"));use Utopia\Query\AST\Parser;
use Utopia\Query\Tokenizer\Tokenizer;
$tokens = Tokenizer::filter((new Tokenizer())->tokenize('SELECT name FROM users WHERE age > 18'));
$select = (new Parser())->parse($tokens);
echo $select->where->operator, "\n"; // >Implementations§
Source§impl Parser
impl Parser
Sourcepub const fn with_literal(self, literal: StringLiteral) -> Self
pub const fn with_literal(self, literal: StringLiteral) -> Self
The parser reading string literals by literal’s rules.
PHP: new Parser($literal).
Sourcepub const fn widened(self) -> Self
pub const fn widened(self) -> Self
The parser for tokens whose text holds a character for each byte, as the PHP extension passes a string that is not UTF-8. What a literal’s escapes spell is then written the same way.
Sourcepub fn parse(&self, tokens: &[Token<'_>]) -> Result<Select>
pub fn parse(&self, tokens: &[Token<'_>]) -> Result<Select>
The statement tokens spell: filtered tokens ending with
TokenType::Eof. Fails with Error::Query on a syntax error
(naming the token and its position) and Error::Validation when
expressions nest more than 256 deep.
PHP: Parser::parse().