Struct Parser

Source
pub struct Parser<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub fn new(tokens: Vec<Token>, dialect: &'a dyn Dialect) -> Self

Parse the specified tokens

Source

pub fn parse_sql( dialect: &dyn Dialect, sql: &str, ) -> Result<Vec<Statement>, ParserError>

Parse a SQL statement and produce an Abstract Syntax Tree (AST)

Source

pub fn parse_statement(&mut self) -> Result<Statement, ParserError>

Parse a single top-level statement (such as SELECT, INSERT, CREATE, etc.), stopping before the statement separator, if any.

Source

pub fn parse_msck(&mut self) -> Result<Msck, ParserError>

Source

pub fn parse_truncate(&mut self) -> Result<Truncate, ParserError>

Source

pub fn parse_analyze(&mut self) -> Result<Analyze, ParserError>

Source

pub fn parse_expr(&mut self) -> Result<Expr, ParserError>

Parse a new expression

Source

pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError>

Parse tokens until the precedence changes

Source

pub fn parse_assert(&mut self) -> Result<Assert, ParserError>

Source

pub fn parse_prefix(&mut self) -> Result<Expr, ParserError>

Parse an expression prefix

Source

pub fn parse_function(&mut self, name: ObjectName) -> Result<Expr, ParserError>

Source

pub fn parse_window_frame_units( &mut self, ) -> Result<WindowFrameUnits, ParserError>

Source

pub fn parse_window_frame(&mut self) -> Result<WindowFrame, ParserError>

Source

pub fn parse_window_frame_bound( &mut self, ) -> Result<WindowFrameBound, ParserError>

Parse CURRENT ROW or { <positive number> | UNBOUNDED } { PRECEDING | FOLLOWING }

Source

pub fn parse_case_expr(&mut self) -> Result<Expr, ParserError>

Source

pub fn parse_cast_expr(&mut self) -> Result<Expr, ParserError>

Parse a SQL CAST function e.g. CAST(expr AS FLOAT)

Source

pub fn parse_try_cast_expr(&mut self) -> Result<Expr, ParserError>

Parse a SQL TRY_CAST function e.g. TRY_CAST(expr AS FLOAT)

Source

pub fn parse_exists_expr(&mut self) -> Result<Expr, ParserError>

Parse a SQL EXISTS expression e.g. WHERE EXISTS(SELECT ...).

Source

pub fn parse_extract_expr(&mut self) -> Result<Expr, ParserError>

Source

pub fn parse_substring_expr(&mut self) -> Result<Expr, ParserError>

Source

pub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError>

TRIM (WHERE ‘text’ FROM ‘text’)
TRIM (‘text’)

Source

pub fn parse_trim_where(&mut self) -> Result<TrimWhereField, ParserError>

Source

pub fn parse_listagg_expr(&mut self) -> Result<Expr, ParserError>

Parse a SQL LISTAGG expression, e.g. LISTAGG(...) WITHIN GROUP (ORDER BY ...).

Source

pub fn parse_date_time_field(&mut self) -> Result<DateTimeField, ParserError>

Source

pub fn parse_literal_interval(&mut self) -> Result<Expr, ParserError>

Parse an INTERVAL literal.

Some syntactically valid intervals:

  1. INTERVAL '1' DAY
  2. INTERVAL '1-1' YEAR TO MONTH
  3. INTERVAL '1' SECOND
  4. INTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)
  5. INTERVAL '1.1' SECOND (2, 2)
  6. INTERVAL '1:1' HOUR (5) TO MINUTE (5)

Note that we do not currently attempt to parse the quoted value.

Source

pub fn parse_infix( &mut self, expr: Expr, precedence: u8, ) -> Result<Expr, ParserError>

Parse an operator following an expression

Source

pub fn parse_map_access(&mut self, expr: Expr) -> Result<Expr, ParserError>

Source

pub fn parse_in( &mut self, expr: Expr, negated: bool, ) -> Result<Expr, ParserError>

Parses the parens following the [ NOT ] IN operator

Source

pub fn parse_between( &mut self, expr: Expr, negated: bool, ) -> Result<Expr, ParserError>

Parses BETWEEN <low> AND <high>, assuming the BETWEEN keyword was already consumed

Source

pub fn parse_pg_cast(&mut self, expr: Expr) -> Result<Expr, ParserError>

Parse a postgresql casting style which is in the form of expr::datatype

Source

pub fn get_next_precedence(&self) -> Result<u8, ParserError>

Get the precedence of the next token

Source

pub fn peek_token(&self) -> Token

Return the first non-whitespace token that has not yet been processed (or None if reached end-of-file)

Source

pub fn peek_nth_token(&self, n: usize) -> Token

Return nth non-whitespace token that has not yet been processed

Source

pub fn next_token(&mut self) -> Token

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.

Source

pub fn next_token_no_skip(&mut self) -> Option<&Token>

Return the first unprocessed token, possibly whitespace.

Source

pub fn prev_token(&mut self)

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.

Source

pub fn parse_keyword(&mut self, expected: Keyword) -> bool

Look for an expected keyword and consume it if it exists

Source

pub fn parse_keywords(&mut self, keywords: &[Keyword]) -> bool

Look for an expected sequence of keywords and consume them if they exist

Source

pub fn parse_one_of_keywords(&mut self, keywords: &[Keyword]) -> Option<Keyword>

Look for one of the given keywords and return the one that matches.

Source

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

Source

pub fn expect_keyword(&mut self, expected: Keyword) -> Result<(), ParserError>

Bail out if the current token is not an expected keyword, or consume it if it is

Source

pub fn expect_keywords( &mut self, expected: &[Keyword], ) -> Result<(), ParserError>

Bail out if the following tokens are not the expected sequence of keywords, or consume them if they are.

Source

pub fn consume_token(&mut self, expected: &Token) -> bool

Consume the next token if it matches the expected token, otherwise return false

Source

pub fn expect_token(&mut self, expected: &Token) -> Result<(), ParserError>

Bail out if the current token is not an expected keyword, or consume it if it is

Source

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

Source

pub fn parse_all_or_distinct(&mut self) -> Result<bool, ParserError>

Parse either ALL or DISTINCT. Returns true if DISTINCT is parsed and results in a ParserError if both ALL and DISTINCT are fround.

Source

pub fn parse_create(&mut self) -> Result<Statement, ParserError>

Parse a SQL CREATE statement

Source

pub fn parse_create_virtual_table( &mut self, ) -> Result<CreateVirtualTable, ParserError>

SQLite-specific CREATE VIRTUAL TABLE

Source

pub fn parse_create_schema(&mut self) -> Result<CreateSchema, ParserError>

Source

pub fn parse_create_database(&mut self) -> Result<CreateDatabase, ParserError>

Source

pub fn parse_create_external_table( &mut self, or_replace: bool, ) -> Result<CreateTable, ParserError>

Source

pub fn parse_file_format(&mut self) -> Result<FileFormat, ParserError>

Source

pub fn parse_create_view( &mut self, or_replace: bool, ) -> Result<CreateView, ParserError>

Source

pub fn parse_drop(&mut self) -> Result<Drop, ParserError>

Source

pub fn parse_create_index( &mut self, unique: bool, ) -> Result<CreateIndex, ParserError>

Source

pub fn parse_hive_distribution( &mut self, ) -> Result<HiveDistributionStyle, ParserError>

Source

pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError>

Source

pub fn parse_row_format(&mut self) -> Result<HiveRowFormat, ParserError>

Source

pub fn parse_create_table( &mut self, or_replace: bool, temporary: bool, ) -> Result<CreateTable, ParserError>

Source

pub fn parse_optional_column_option( &mut self, ) -> Result<Option<ColumnOption>, ParserError>

Source

pub fn parse_referential_action( &mut self, ) -> Result<ReferentialAction, ParserError>

Source

pub fn parse_optional_table_constraint( &mut self, ) -> Result<Option<TableConstraint>, ParserError>

Source

pub fn parse_options( &mut self, keyword: Keyword, ) -> Result<Vec<SqlOption>, ParserError>

Source

pub fn parse_sql_option(&mut self) -> Result<SqlOption, ParserError>

Source

pub fn parse_alter(&mut self) -> Result<AlterTable, ParserError>

Source

pub fn parse_copy(&mut self) -> Result<Copy, ParserError>

Parse a copy statement

Source

pub fn parse_number_value(&mut self) -> Result<Value, ParserError>

Source

pub fn parse_literal_uint(&mut self) -> Result<u64, ParserError>

Parse an unsigned literal integer/long

Source

pub fn parse_literal_string(&mut self) -> Result<String, ParserError>

Parse a literal string

Source

pub fn parse_data_type(&mut self) -> Result<DataType, ParserError>

Parse a SQL datatype (in the context of a CREATE TABLE statement for example)

Source

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

Source

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.

Source

pub fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>

Parse a possibly qualified, possibly quoted identifier, e.g. foo or `myschema.“table”

Source

pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError>

Parse identifiers

Source

pub fn parse_identifier(&mut self) -> Result<Ident, ParserError>

Parse a simple one-word identifier (possibly quoted, possibly a keyword)

Source

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

Source

pub fn parse_optional_precision(&mut self) -> Result<Option<u64>, ParserError>

Source

pub fn parse_optional_precision_scale( &mut self, ) -> Result<(Option<u64>, Option<u64>), ParserError>

Source

pub fn parse_delete(&mut self) -> Result<Delete, ParserError>

Source

pub fn parse_explain(&mut self) -> Result<Explain, ParserError>

Source

pub fn parse_query(&mut self) -> Result<Query, 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

Source

pub fn parse_select(&mut self) -> Result<Select, ParserError>

Parse a restricted SELECT statement (no CTEs / UNION / ORDER BY), assuming the initial SELECT was already consumed

Source

pub fn parse_set(&mut self) -> Result<Statement, ParserError>

Source

pub fn parse_show(&mut self) -> Result<Statement, ParserError>

Source

pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError>

Source

pub fn parse_table_factor(&mut self) -> Result<TableFactor, ParserError>

A table name or a parenthesized subquery, followed by optional [AS] alias

Source

pub fn parse_derived_table_factor( &mut self, lateral: IsLateral, ) -> Result<TableFactor, ParserError>

Source

pub fn parse_insert(&mut self) -> Result<Statement, ParserError>

Parse an INSERT statement

Source

pub fn parse_update(&mut self) -> Result<Update, ParserError>

Source

pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError>

Parse a var = expr assignment, used in an UPDATE statement

Source

pub fn parse_optional_args(&mut self) -> Result<Vec<FunctionArg>, ParserError>

Source

pub fn parse_select_item(&mut self) -> Result<SelectItem, ParserError>

Parse a comma-delimited list of projections after SELECT

Source

pub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError>

Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)

Source

pub fn parse_top(&mut self) -> Result<Top, ParserError>

Parse a TOP clause, MSSQL equivalent of LIMIT, that follows after SELECT [DISTINCT].

Source

pub fn parse_limit(&mut self) -> Result<Option<Expr>, ParserError>

Parse a LIMIT clause

Source

pub fn parse_offset(&mut self) -> Result<Offset, ParserError>

Parse an OFFSET clause

Source

pub fn parse_fetch(&mut self) -> Result<Fetch, ParserError>

Parse a FETCH clause

Source

pub fn parse_values(&mut self) -> Result<Values, ParserError>

Source

pub fn parse_start_transaction( &mut self, ) -> Result<StartTransaction, ParserError>

Source

pub fn parse_begin(&mut self) -> Result<StartTransaction, ParserError>

Source

pub fn parse_transaction_modes( &mut self, ) -> Result<Vec<TransactionMode>, ParserError>

Source

pub fn parse_commit(&mut self) -> Result<Commit, ParserError>

Source

pub fn parse_rollback(&mut self) -> Result<Rollback, ParserError>

Source

pub fn parse_commit_rollback_chain(&mut self) -> Result<bool, ParserError>

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> !RefUnwindSafe for Parser<'a>

§

impl<'a> !Send for Parser<'a>

§

impl<'a> !Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> !UnwindSafe for Parser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.