[][src]Struct sqlparser::sqlparser::Parser

pub struct Parser { /* fields omitted */ }

SQL Parser

Methods

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<SQLStatement>, ParserError>
[src]

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

pub fn parse_statement(&mut self) -> Result<SQLStatement, 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<ASTNode, ParserError>[src]

Parse a new expression

pub fn parse_subexpr(&mut self, precedence: u8) -> Result<ASTNode, ParserError>[src]

Parse tokens until the precedence changes

pub fn parse_default_expr(
    &mut self,
    precedence: u8
) -> Result<ASTNode, ParserError>
[src]

Parse expression for DEFAULT clause in CREATE TABLE

pub fn parse_prefix(&mut self) -> Result<ASTNode, ParserError>[src]

Parse an expression prefix

pub fn parse_function(&mut self, id: SQLIdent) -> Result<ASTNode, ParserError>[src]

pub fn parse_case_expression(&mut self) -> Result<ASTNode, ParserError>[src]

pub fn parse_cast_expression(&mut self) -> Result<ASTNode, ParserError>[src]

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

pub fn parse_infix(
    &mut self,
    expr: ASTNode,
    precedence: u8
) -> Result<ASTNode, ParserError>
[src]

Parse an expression infix (typically an operator)

pub fn parse_in(
    &mut self,
    expr: ASTNode,
    negated: bool
) -> Result<ASTNode, ParserError>
[src]

Parses the parens following the [ NOT ] IN operator

pub fn parse_between(
    &mut self,
    expr: ASTNode,
    negated: bool
) -> Result<ASTNode, ParserError>
[src]

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

pub fn parse_pg_cast(&mut self, expr: ASTNode) -> Result<ASTNode, ParserError>[src]

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

pub fn to_sql_operator(&self, tok: &Token) -> Result<SQLOperator, ParserError>[src]

Convert a token operator to an AST operator

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

Get the precedence of the next token

pub fn get_precedence(&self, tok: &Token) -> Result<u8, ParserError>[src]

Get the precedence of a token

pub fn peek_token(&self) -> Option<Token>[src]

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

pub fn next_token(&mut self) -> Option<Token>[src]

Get the next token skipping whitespace and increment the token index

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

pub fn prev_token(&mut self) -> Option<Token>[src]

Push back the last one non-whitespace token

#[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

pub fn expect_keyword(
    &mut self,
    expected: &'static str
) -> Result<(), ParserError>
[src]

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

#[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_create(&mut self) -> Result<SQLStatement, ParserError>[src]

Parse a SQL CREATE statement

pub fn parse_create_view(&mut self) -> Result<SQLStatement, ParserError>[src]

pub fn parse_create_table(&mut self) -> Result<SQLStatement, ParserError>[src]

pub fn parse_table_key(
    &mut self,
    constraint_name: SQLIdent
) -> Result<TableKey, ParserError>
[src]

pub fn parse_alter(&mut self) -> Result<SQLStatement, ParserError>[src]

pub fn parse_copy(&mut self) -> Result<SQLStatement, ParserError>[src]

Parse a copy statement

pub fn parse_literal_int(&mut self) -> Result<i64, ParserError>[src]

Parse a literal integer/long

pub fn parse_literal_double(&mut self) -> Result<f64, ParserError>[src]

Parse a literal double

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

Parse a literal string

pub fn parse_timezone_offset(&mut self) -> Result<i8, ParserError>[src]

pub fn parse_timestamp_value(&mut self) -> Result<Value, ParserError>[src]

pub fn parse_date(&mut self, year: i64) -> Result<NaiveDate, ParserError>[src]

pub fn parse_time(&mut self) -> Result<NaiveTime, ParserError>[src]

pub fn parse_data_type(&mut self) -> Result<SQLType, 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<SQLIdent>, ParserError>
[src]

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_list_of_ids(
    &mut self,
    separator: &Token
) -> Result<Vec<SQLIdent>, ParserError>
[src]

Parse one or more identifiers with the specified separator between them

pub fn parse_object_name(&mut self) -> Result<SQLObjectName, ParserError>[src]

Parse a possibly qualified, possibly quoted identifier, e.g. foo or myschema."table"

pub fn parse_identifier(&mut self) -> Result<SQLIdent, ParserError>[src]

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

pub fn parse_column_names(&mut self) -> Result<Vec<SQLIdent>, ParserError>[src]

Parse a comma-separated list of unqualified, possibly quoted identifiers

pub fn parse_precision(&mut self) -> Result<usize, ParserError>[src]

pub fn parse_optional_precision(&mut self) -> Result<Option<usize>, ParserError>[src]

pub fn parse_optional_precision_scale(
    &mut self
) -> Result<(Option<usize>, Option<usize>), ParserError>
[src]

pub fn parse_delete(&mut self) -> Result<SQLStatement, ParserError>[src]

pub fn parse_query(&mut self) -> Result<SQLQuery, 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<SQLSelect, ParserError>[src]

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

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_insert(&mut self) -> Result<SQLStatement, ParserError>[src]

Parse an INSERT statement

pub fn parse_expr_list(&mut self) -> Result<Vec<ASTNode>, ParserError>[src]

Parse a comma-delimited list of SQL expressions

pub fn parse_select_list(&mut self) -> Result<Vec<SQLSelectItem>, ParserError>[src]

Parse a comma-delimited list of projections after SELECT

pub fn parse_order_by_expr_list(
    &mut self
) -> Result<Vec<SQLOrderByExpr>, ParserError>
[src]

Parse a comma-delimited list of SQL ORDER BY expressions

pub fn parse_limit(&mut self) -> Result<Option<ASTNode>, ParserError>[src]

Parse a LIMIT clause

Auto Trait Implementations

impl Send for Parser

impl Sync for Parser

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.