Struct models_parser::parser::Parser [−][src]
pub struct Parser<'a> { /* fields omitted */ }
Implementations
Parse a SQL statement and produce an Abstract Syntax Tree (AST)
Parse a single top-level statement (such as SELECT, INSERT, CREATE, etc.), stopping before the statement separator, if any.
Parse a new expression
Parse tokens until the precedence changes
Parse an expression prefix
Parse CURRENT ROW
or { <positive number> | UNBOUNDED } { PRECEDING | FOLLOWING }
Parse a SQL CAST function e.g. CAST(expr AS FLOAT)
Parse a SQL TRY_CAST function e.g. TRY_CAST(expr AS FLOAT)
Parse a SQL EXISTS expression e.g. WHERE EXISTS(SELECT ...)
.
TRIM (WHERE ‘text’ FROM ‘text’)
TRIM (‘text’)
Parse a SQL LISTAGG expression, e.g. LISTAGG(...) WITHIN GROUP (ORDER BY ...)
.
Parse an INTERVAL literal.
Some syntactically valid intervals:
INTERVAL '1' DAY
INTERVAL '1-1' YEAR TO MONTH
INTERVAL '1' SECOND
INTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)
INTERVAL '1.1' SECOND (2, 2)
INTERVAL '1:1' HOUR (5) TO MINUTE (5)
Note that we do not currently attempt to parse the quoted value.
Parse an operator following an expression
Parses the parens following the [ NOT ] IN
operator
Parses BETWEEN <low> AND <high>
, assuming the BETWEEN
keyword was already consumed
Parse a postgresql casting style which is in the form of expr::datatype
Get the precedence of the next token
Return the first non-whitespace token that has not yet been processed (or None if reached end-of-file)
Return nth non-whitespace token that has not yet been processed
Return the first non-whitespace token that has not yet been processed (or None if reached end-of-file) and mark it as processed. OK to call repeatedly after reaching EOF.
Return the first unprocessed token, possibly whitespace.
Push back the last one non-whitespace token. Must be called after
next_token()
, otherwise might panic. OK to call after
next_token()
indicates an EOF.
Look for an expected keyword and consume it if it exists
Look for an expected sequence of keywords and consume them if they exist
Look for one of the given keywords and return the one that matches.
pub fn expect_one_of_keywords(
&mut self,
keywords: &[Keyword]
) -> Result<Keyword, ParserError>
pub fn expect_one_of_keywords(
&mut self,
keywords: &[Keyword]
) -> Result<Keyword, ParserError>
Bail out if the current token is not one of the expected keywords, or consume it if it is
Bail out if the current token is not an expected keyword, or consume it if it is
Bail out if the following tokens are not the expected sequence of keywords, or consume them if they are.
Consume the next token if it matches the expected token, otherwise return false
Bail out if the current token is not an expected keyword, or consume it if it is
pub fn parse_comma_separated<T, F>(
&mut self,
f: F
) -> Result<Vec<T>, ParserError> where
F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
pub fn parse_comma_separated<T, F>(
&mut self,
f: F
) -> Result<Vec<T>, ParserError> where
F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
Parse a comma-separated list of 1+ items accepted by F
Parse either ALL
or DISTINCT
. Returns true
if DISTINCT
is parsed and results in a
ParserError
if both ALL
and DISTINCT
are fround.
Parse a SQL CREATE statement
SQLite-specific CREATE VIRTUAL TABLE
pub fn parse_create_external_table(
&mut self,
or_replace: bool
) -> Result<CreateTable, ParserError>
pub fn parse_create_table(
&mut self,
or_replace: bool,
temporary: bool
) -> Result<CreateTable, ParserError>
pub fn parse_optional_table_constraint(
&mut self
) -> Result<Option<TableConstraint>, ParserError>
Parse a copy statement
Parse an unsigned literal integer/long
Parse a literal string
Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
pub fn parse_optional_alias(
&mut self,
reserved_kwds: &[Keyword]
) -> Result<Option<Ident>, ParserError>
pub fn parse_optional_alias(
&mut self,
reserved_kwds: &[Keyword]
) -> Result<Option<Ident>, ParserError>
Parse AS identifier
(or simply identifier
if it’s not a reserved keyword)
Some examples with aliases: SELECT 1 foo
, SELECT COUNT(*) AS cnt
,
SELECT ... FROM t1 foo, t2 bar
, SELECT ... FROM (...) AS bar
pub fn parse_optional_table_alias(
&mut self,
reserved_kwds: &[Keyword]
) -> Result<Option<TableAlias>, ParserError>
pub fn parse_optional_table_alias(
&mut self,
reserved_kwds: &[Keyword]
) -> Result<Option<TableAlias>, ParserError>
Parse AS identifier
when the AS is describing a table-valued object,
like in ... FROM generate_series(1, 10) AS t (col)
. In this case
the alias is allowed to optionally name the columns in the table, in
addition to the table itself.
Parse a possibly qualified, possibly quoted identifier, e.g.
foo
or `myschema.“table”
Parse identifiers
Parse a simple one-word identifier (possibly quoted, possibly a keyword)
pub fn parse_parenthesized_column_list(
&mut self,
optional: IsOptional
) -> Result<Vec<Ident>, ParserError>
pub fn parse_parenthesized_column_list(
&mut self,
optional: IsOptional
) -> Result<Vec<Ident>, ParserError>
Parse a parenthesized comma-separated list of unqualified, possibly quoted identifiers
pub fn parse_optional_precision_scale(
&mut self
) -> Result<(Option<u64>, Option<u64>), ParserError>
Parse a query expression, i.e. a SELECT
statement optionally
preceeded with some WITH
CTE declarations and optionally followed
by ORDER BY
. Unlike some other parse_… methods, this one doesn’t
expect the initial keyword to be already consumed
Parse a restricted SELECT
statement (no CTEs / UNION
/ ORDER BY
),
assuming the initial SELECT
was already consumed
A table name or a parenthesized subquery, followed by optional [AS] alias
pub fn parse_derived_table_factor(
&mut self,
lateral: IsLateral
) -> Result<TableFactor, ParserError>
Parse an INSERT statement
Parse a var = expr
assignment, used in an UPDATE statement
Parse a comma-delimited list of projections after SELECT
Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)
Parse a TOP clause, MSSQL equivalent of LIMIT, that follows after SELECT [DISTINCT].
Parse a LIMIT clause
Parse an OFFSET clause
Parse a FETCH clause