mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-27 01:14:07 +00:00
Improve Parser documentation (#1617)
This commit is contained in:
parent
df3c5652b1
commit
d89cf801dd
1 changed files with 41 additions and 2 deletions
|
@ -276,19 +276,58 @@ enum ParserState {
|
||||||
ConnectBy,
|
ConnectBy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A SQL Parser
|
||||||
|
///
|
||||||
|
/// This struct is the main entry point for parsing SQL queries.
|
||||||
|
///
|
||||||
|
/// # Functionality:
|
||||||
|
/// * Parsing SQL: see examples on [`Parser::new`] and [`Parser::parse_sql`]
|
||||||
|
/// * Controlling recursion: See [`Parser::with_recursion_limit`]
|
||||||
|
/// * Controlling parser options: See [`Parser::with_options`]
|
||||||
|
/// * Providing your own tokens: See [`Parser::with_tokens`]
|
||||||
|
///
|
||||||
|
/// # Internals
|
||||||
|
///
|
||||||
|
/// The parser uses a [`Tokenizer`] to tokenize the input SQL string into a
|
||||||
|
/// `Vec` of [`TokenWithSpan`]s and maintains an `index` to the current token
|
||||||
|
/// being processed. The token vec may contain multiple SQL statements.
|
||||||
|
///
|
||||||
|
/// * The "current" token is the token at `index - 1`
|
||||||
|
/// * The "next" token is the token at `index`
|
||||||
|
/// * The "previous" token is the token at `index - 2`
|
||||||
|
///
|
||||||
|
/// If `index` is equal to the length of the token stream, the 'next' token is
|
||||||
|
/// [`Token::EOF`].
|
||||||
|
///
|
||||||
|
/// For example, the SQL string "SELECT * FROM foo" will be tokenized into
|
||||||
|
/// following tokens:
|
||||||
|
/// ```text
|
||||||
|
/// [
|
||||||
|
/// "SELECT", // token index 0
|
||||||
|
/// " ", // whitespace
|
||||||
|
/// "*",
|
||||||
|
/// " ",
|
||||||
|
/// "FROM",
|
||||||
|
/// " ",
|
||||||
|
/// "foo"
|
||||||
|
/// ]
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
///
|
||||||
pub struct Parser<'a> {
|
pub struct Parser<'a> {
|
||||||
|
/// The tokens
|
||||||
tokens: Vec<TokenWithSpan>,
|
tokens: Vec<TokenWithSpan>,
|
||||||
/// The index of the first unprocessed token in [`Parser::tokens`].
|
/// The index of the first unprocessed token in [`Parser::tokens`].
|
||||||
index: usize,
|
index: usize,
|
||||||
/// The current state of the parser.
|
/// The current state of the parser.
|
||||||
state: ParserState,
|
state: ParserState,
|
||||||
/// The current dialect to use.
|
/// The SQL dialect to use.
|
||||||
dialect: &'a dyn Dialect,
|
dialect: &'a dyn Dialect,
|
||||||
/// Additional options that allow you to mix & match behavior
|
/// Additional options that allow you to mix & match behavior
|
||||||
/// otherwise constrained to certain dialects (e.g. trailing
|
/// otherwise constrained to certain dialects (e.g. trailing
|
||||||
/// commas) and/or format of parse (e.g. unescaping).
|
/// commas) and/or format of parse (e.g. unescaping).
|
||||||
options: ParserOptions,
|
options: ParserOptions,
|
||||||
/// Ensure the stack does not overflow by limiting recursion depth.
|
/// Ensures the stack does not overflow by limiting recursion depth.
|
||||||
recursion_counter: RecursionCounter,
|
recursion_counter: RecursionCounter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue