@@ -276,19 +276,58 @@ enum ParserState {
276
276
ConnectBy,
277
277
}
278
278
279
+ /// A SQL Parser
280
+ ///
281
+ /// This struct is the main entry point for parsing SQL queries.
282
+ ///
283
+ /// # Functionality:
284
+ /// * Parsing SQL: see examples on [`Parser::new`] and [`Parser::parse_sql`]
285
+ /// * Controlling recursion: See [`Parser::with_recursion_limit`]
286
+ /// * Controlling parser options: See [`Parser::with_options`]
287
+ /// * Providing your own tokens: See [`Parser::with_tokens`]
288
+ ///
289
+ /// # Internals
290
+ ///
291
+ /// The parser uses a [`Tokenizer`] to tokenize the input SQL string into a
292
+ /// `Vec` of [`TokenWithSpan`]s and maintains an `index` to the current token
293
+ /// being processed. The token vec may contain multiple SQL statements.
294
+ ///
295
+ /// * The "current" token is the token at `index - 1`
296
+ /// * The "next" token is the token at `index`
297
+ /// * The "previous" token is the token at `index - 2`
298
+ ///
299
+ /// If `index` is equal to the length of the token stream, the 'next' token is
300
+ /// [`Token::EOF`].
301
+ ///
302
+ /// For example, the SQL string "SELECT * FROM foo" will be tokenized into
303
+ /// following tokens:
304
+ /// ```text
305
+ /// [
306
+ /// "SELECT", // token index 0
307
+ /// " ", // whitespace
308
+ /// "*",
309
+ /// " ",
310
+ /// "FROM",
311
+ /// " ",
312
+ /// "foo"
313
+ /// ]
314
+ /// ```
315
+ ///
316
+ ///
279
317
pub struct Parser<'a> {
318
+ /// The tokens
280
319
tokens: Vec<TokenWithSpan>,
281
320
/// The index of the first unprocessed token in [`Parser::tokens`].
282
321
index: usize,
283
322
/// The current state of the parser.
284
323
state: ParserState,
285
- /// The current dialect to use.
324
+ /// The SQL dialect to use.
286
325
dialect: &'a dyn Dialect,
287
326
/// Additional options that allow you to mix & match behavior
288
327
/// otherwise constrained to certain dialects (e.g. trailing
289
328
/// commas) and/or format of parse (e.g. unescaping).
290
329
options: ParserOptions,
291
- /// Ensure the stack does not overflow by limiting recursion depth.
330
+ /// Ensures the stack does not overflow by limiting recursion depth.
292
331
recursion_counter: RecursionCounter,
293
332
}
294
333
0 commit comments