[−][src]Struct sql_ast::parser::Parser
SQL Parser
Implementations
impl Parser
[src]
pub fn new(tokens: Vec<Token>) -> Self
[src]
Parse the specified tokens
pub fn parse_sql(
dialect: &dyn Dialect,
sql: String
) -> Result<Vec<Statement>, ParserError>
[src]
dialect: &dyn Dialect,
sql: String
) -> Result<Vec<Statement>, ParserError>
Parse a SQL statement and produce an Abstract Syntax Tree (AST)
pub fn parse_statement(&mut self) -> Result<Statement, ParserError>
[src]
Parse a single top-level statement (such as SELECT, INSERT, CREATE, etc.), stopping before the statement separator, if any.
pub fn parse_expr(&mut self) -> Result<Expr, ParserError>
[src]
Parse a new expression
pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError>
[src]
Parse tokens until the precedence changes
pub fn parse_prefix(&mut self) -> Result<Expr, ParserError>
[src]
Parse an expression prefix
pub fn parse_function(&mut self, name: ObjectName) -> Result<Expr, ParserError>
[src]
pub fn parse_window_frame(&mut self) -> Result<WindowFrame, ParserError>
[src]
pub fn parse_window_frame_bound(
&mut self
) -> Result<WindowFrameBound, ParserError>
[src]
&mut self
) -> Result<WindowFrameBound, ParserError>
Parse CURRENT ROW
or { <positive number> | UNBOUNDED } { PRECEDING | FOLLOWING }
pub fn parse_case_expr(&mut self) -> Result<Expr, ParserError>
[src]
pub fn parse_cast_expr(&mut self) -> Result<Expr, ParserError>
[src]
Parse a SQL CAST function e.g. CAST(expr AS FLOAT)
pub fn parse_exists_expr(&mut self) -> Result<Expr, ParserError>
[src]
Parse a SQL EXISTS expression e.g. WHERE EXISTS(SELECT ...)
.
pub fn parse_extract_expr(&mut self) -> Result<Expr, ParserError>
[src]
pub fn parse_date_time_field(&mut self) -> Result<DateTimeField, ParserError>
[src]
pub fn parse_literal_interval(&mut self) -> Result<Expr, ParserError>
[src]
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.
pub fn parse_infix(
&mut self,
expr: Expr,
precedence: u8
) -> Result<Expr, ParserError>
[src]
&mut self,
expr: Expr,
precedence: u8
) -> Result<Expr, ParserError>
Parse an operator following an expression
pub fn parse_in(
&mut self,
expr: Expr,
negated: bool
) -> Result<Expr, ParserError>
[src]
&mut self,
expr: Expr,
negated: bool
) -> Result<Expr, ParserError>
Parses the parens following the [ NOT ] IN
operator
pub fn parse_between(
&mut self,
expr: Expr,
negated: bool
) -> Result<Expr, ParserError>
[src]
&mut self,
expr: Expr,
negated: bool
) -> Result<Expr, ParserError>
Parses BETWEEN <low> AND <high>
, assuming the BETWEEN
keyword was already consumed
pub fn parse_pg_cast(&mut self, expr: Expr) -> Result<Expr, ParserError>
[src]
Parse a postgresql casting style which is in the form of expr::datatype
pub fn get_next_precedence(&self) -> Result<u8, ParserError>
[src]
Get the precedence of the next token
pub fn peek_token(&self) -> Option<Token>
[src]
Return the first non-whitespace token that has not yet been processed (or None if reached end-of-file)
pub fn peek_nth_token(&self, n: usize) -> Option<Token>
[src]
Return nth non-whitespace token that has not yet been processed
pub fn next_token(&mut self) -> Option<Token>
[src]
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.
pub fn next_token_no_skip(&mut self) -> Option<&Token>
[src]
Return the first unprocessed token, possibly whitespace.
pub fn prev_token(&mut self)
[src]
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.
#[must_use]pub fn parse_keyword(&mut self, expected: &'static str) -> bool
[src]
Look for an expected keyword and consume it if it exists
#[must_use]pub fn parse_keywords(&mut self, keywords: Vec<&'static str>) -> bool
[src]
Look for an expected sequence of keywords and consume them if they exist
#[must_use]pub fn parse_one_of_keywords(
&mut self,
keywords: &[&'static str]
) -> Option<&'static str>
[src]
&mut self,
keywords: &[&'static str]
) -> Option<&'static str>
Look for one of the given keywords and return the one that matches.
#[must_use]pub fn expect_one_of_keywords(
&mut self,
keywords: &[&'static str]
) -> Result<&'static str, ParserError>
[src]
&mut self,
keywords: &[&'static str]
) -> Result<&'static str, ParserError>
Bail out if the current token is not one of the expected keywords, or consume it if it is
pub fn expect_keyword(
&mut self,
expected: &'static str
) -> Result<(), ParserError>
[src]
&mut self,
expected: &'static str
) -> Result<(), ParserError>
Bail out if the current token is not an expected keyword, or consume it if it is
pub fn expect_keywords(
&mut self,
expected: &[&'static str]
) -> Result<(), ParserError>
[src]
&mut self,
expected: &[&'static str]
) -> Result<(), ParserError>
Bail out if the following tokens are not the expected sequence of keywords, or consume them if they are.
#[must_use]pub fn consume_token(&mut self, expected: &Token) -> bool
[src]
Consume the next token if it matches the expected token, otherwise return false
pub fn expect_token(&mut self, expected: &Token) -> Result<(), ParserError>
[src]
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) -> Result<T, ParserError>,
[src]
&mut self,
f: F
) -> Result<Vec<T>, ParserError> where
F: FnMut(&mut Parser) -> Result<T, ParserError>,
Parse a comma-separated list of 1+ items accepted by F
pub fn parse_create(&mut self) -> Result<Statement, ParserError>
[src]
Parse a SQL CREATE statement
pub fn parse_create_external_table(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_create_view(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_drop(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_create_table(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_column_option_def(
&mut self
) -> Result<ColumnOptionDef, ParserError>
[src]
&mut self
) -> Result<ColumnOptionDef, ParserError>
pub fn parse_optional_table_constraint(
&mut self
) -> Result<Option<TableConstraint>, ParserError>
[src]
&mut self
) -> Result<Option<TableConstraint>, ParserError>
pub fn parse_with_options(&mut self) -> Result<Vec<SqlOption>, ParserError>
[src]
pub fn parse_sql_option(&mut self) -> Result<SqlOption, ParserError>
[src]
pub fn parse_alter(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_copy(&mut self) -> Result<Statement, ParserError>
[src]
Parse a copy statement
pub fn parse_number_value(&mut self) -> Result<Value, ParserError>
[src]
pub fn parse_literal_uint(&mut self) -> Result<u64, ParserError>
[src]
Parse an unsigned literal integer/long
pub fn parse_literal_string(&mut self) -> Result<String, ParserError>
[src]
Parse a literal string
pub fn parse_data_type(&mut self) -> Result<DataType, ParserError>
[src]
Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
pub fn parse_optional_alias(
&mut self,
reserved_kwds: &[&str]
) -> Result<Option<Ident>, ParserError>
[src]
&mut self,
reserved_kwds: &[&str]
) -> 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: &[&str]
) -> Result<Option<TableAlias>, ParserError>
[src]
&mut self,
reserved_kwds: &[&str]
) -> 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.
pub fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>
[src]
Parse a possibly qualified, possibly quoted identifier, e.g.
foo
or myschema."table"
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError>
[src]
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>
[src]
&mut self,
optional: IsOptional
) -> Result<Vec<Ident>, ParserError>
Parse a parenthesized comma-separated list of unqualified, possibly quoted identifiers
pub fn parse_optional_precision(&mut self) -> Result<Option<u64>, ParserError>
[src]
pub fn parse_optional_precision_scale(
&mut self
) -> Result<(Option<u64>, Option<u64>), ParserError>
[src]
&mut self
) -> Result<(Option<u64>, Option<u64>), ParserError>
pub fn parse_delete(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_query(&mut self) -> Result<Query, ParserError>
[src]
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
pub fn parse_select(&mut self) -> Result<Select, ParserError>
[src]
Parse a restricted SELECT
statement (no CTEs / UNION
/ ORDER BY
),
assuming the initial SELECT
was already consumed
pub fn parse_set(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_show(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError>
[src]
pub fn parse_table_factor(&mut self) -> Result<TableFactor, ParserError>
[src]
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>
[src]
&mut self,
lateral: IsLateral
) -> Result<TableFactor, ParserError>
pub fn parse_insert(&mut self) -> Result<Statement, ParserError>
[src]
Parse an INSERT statement
pub fn parse_update(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError>
[src]
Parse a var = expr
assignment, used in an UPDATE statement
pub fn parse_optional_args(&mut self) -> Result<Vec<Expr>, ParserError>
[src]
pub fn parse_select_item(&mut self) -> Result<SelectItem, ParserError>
[src]
Parse a comma-delimited list of projections after SELECT
pub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError>
[src]
Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)
pub fn parse_limit(&mut self) -> Result<Option<Expr>, ParserError>
[src]
Parse a LIMIT clause
pub fn parse_offset(&mut self) -> Result<Expr, ParserError>
[src]
Parse an OFFSET clause
pub fn parse_fetch(&mut self) -> Result<Fetch, ParserError>
[src]
Parse a FETCH clause
pub fn parse_values(&mut self) -> Result<Values, ParserError>
[src]
pub fn parse_start_transaction(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_begin(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_transaction_modes(
&mut self
) -> Result<Vec<TransactionMode>, ParserError>
[src]
&mut self
) -> Result<Vec<TransactionMode>, ParserError>
pub fn parse_commit(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_rollback(&mut self) -> Result<Statement, ParserError>
[src]
pub fn parse_commit_rollback_chain(&mut self) -> Result<bool, ParserError>
[src]
Auto Trait Implementations
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,