@@ -71,11 +71,11 @@ mod recursion {
71
71
use super :: ParserError ;
72
72
73
73
/// Tracks remaining recursion depth. This value is decremented on
74
- /// each call to ` try_decrease()`, when it reaches 0 an error will
74
+ /// each call to [`RecursionCounter:: try_decrease()`] , when it reaches 0 an error will
75
75
/// be returned.
76
76
///
77
- /// Note: Uses an Rc and Cell in order to satisfy the Rust
78
- /// borrow checker so the automatic DepthGuard decrement a
77
+ /// Note: Uses an [`std::rc::Rc`] and [`std::cell:: Cell`] in order to satisfy the Rust
78
+ /// borrow checker so the automatic [` DepthGuard`] decrement a
79
79
/// reference to the counter.
80
80
pub ( crate ) struct RecursionCounter {
81
81
remaining_depth : Rc < Cell < usize > > ,
@@ -92,7 +92,7 @@ mod recursion {
92
92
93
93
/// Decreases the remaining depth by 1.
94
94
///
95
- /// Returns `Err` if the remaining depth falls to 0.
95
+ /// Returns [ `Err`] if the remaining depth falls to 0.
96
96
///
97
97
/// Returns a [`DepthGuard`] which will adds 1 to the
98
98
/// remaining depth upon drop;
@@ -131,7 +131,7 @@ mod recursion {
131
131
/// Implementation [`RecursionCounter`] if std is NOT available (and does not
132
132
/// guard against stack overflow).
133
133
///
134
- /// Has the same API as the std RecursionCounter implementation
134
+ /// Has the same API as the std [` RecursionCounter`] implementation
135
135
/// but does not actually limit stack depth.
136
136
pub ( crate ) struct RecursionCounter { }
137
137
@@ -270,17 +270,17 @@ enum ParserState {
270
270
271
271
pub struct Parser < ' a > {
272
272
tokens : Vec < TokenWithLocation > ,
273
- /// The index of the first unprocessed token in `self. tokens`
273
+ /// The index of the first unprocessed token in [`Parser:: tokens`].
274
274
index : usize ,
275
275
/// The current state of the parser.
276
276
state : ParserState ,
277
- /// The current dialect to use
277
+ /// The current dialect to use.
278
278
dialect : & ' a dyn Dialect ,
279
279
/// Additional options that allow you to mix & match behavior
280
280
/// otherwise constrained to certain dialects (e.g. trailing
281
- /// commas) and/or format of parse (e.g. unescaping)
281
+ /// commas) and/or format of parse (e.g. unescaping).
282
282
options : ParserOptions ,
283
- /// ensure the stack does not overflow by limiting recursion depth
283
+ /// Ensure the stack does not overflow by limiting recursion depth.
284
284
recursion_counter : RecursionCounter ,
285
285
}
286
286
@@ -313,7 +313,6 @@ impl<'a> Parser<'a> {
313
313
314
314
/// Specify the maximum recursion limit while parsing.
315
315
///
316
- ///
317
316
/// [`Parser`] prevents stack overflows by returning
318
317
/// [`ParserError::RecursionLimitExceeded`] if the parser exceeds
319
318
/// this depth while processing the query.
@@ -338,7 +337,6 @@ impl<'a> Parser<'a> {
338
337
339
338
/// Specify additional parser options
340
339
///
341
- ///
342
340
/// [`Parser`] supports additional options ([`ParserOptions`])
343
341
/// that allow you to mix & match behavior otherwise constrained
344
342
/// to certain dialects (e.g. trailing commas).
@@ -824,7 +822,7 @@ impl<'a> Parser<'a> {
824
822
} )
825
823
}
826
824
827
- /// Parse a new expression including wildcard & qualified wildcard
825
+ /// Parse a new expression including wildcard & qualified wildcard.
828
826
pub fn parse_wildcard_expr ( & mut self ) -> Result < Expr , ParserError > {
829
827
let index = self . index ;
830
828
@@ -867,13 +865,13 @@ impl<'a> Parser<'a> {
867
865
self . parse_expr ( )
868
866
}
869
867
870
- /// Parse a new expression
868
+ /// Parse a new expression.
871
869
pub fn parse_expr ( & mut self ) -> Result < Expr , ParserError > {
872
870
let _guard = self . recursion_counter . try_decrease ( ) ?;
873
871
self . parse_subexpr ( 0 )
874
872
}
875
873
876
- /// Parse tokens until the precedence changes
874
+ /// Parse tokens until the precedence changes.
877
875
pub fn parse_subexpr ( & mut self , precedence : u8 ) -> Result < Expr , ParserError > {
878
876
debug ! ( "parsing expr" ) ;
879
877
let mut expr = self . parse_prefix ( ) ?;
@@ -908,8 +906,7 @@ impl<'a> Parser<'a> {
908
906
Ok ( expr)
909
907
}
910
908
911
- /// Get the precedence of the next token
912
- /// With AND, OR, and XOR
909
+ /// Get the precedence of the next token, with AND, OR, and XOR.
913
910
pub fn get_next_interval_precedence ( & self ) -> Result < u8 , ParserError > {
914
911
let token = self . peek_token ( ) ;
915
912
@@ -944,7 +941,7 @@ impl<'a> Parser<'a> {
944
941
Ok ( Statement :: ReleaseSavepoint { name } )
945
942
}
946
943
947
- /// Parse an expression prefix
944
+ /// Parse an expression prefix.
948
945
pub fn parse_prefix ( & mut self ) -> Result < Expr , ParserError > {
949
946
// allow the dialect to override prefix parsing
950
947
if let Some ( prefix) = self . dialect . parse_prefix ( self ) {
@@ -1456,8 +1453,7 @@ impl<'a> Parser<'a> {
1456
1453
}
1457
1454
}
1458
1455
1459
- /// parse a group by expr. a group by expr can be one of group sets, roll up, cube, or simple
1460
- /// expr.
1456
+ /// Parse a group by expr. Group by expr can be one of group sets, roll up, cube, or simple expr.
1461
1457
fn parse_group_by_expr ( & mut self ) -> Result < Expr , ParserError > {
1462
1458
if self . dialect . supports_group_by_expr ( ) {
1463
1459
if self . parse_keywords ( & [ Keyword :: GROUPING , Keyword :: SETS ] ) {
@@ -1484,7 +1480,7 @@ impl<'a> Parser<'a> {
1484
1480
}
1485
1481
}
1486
1482
1487
- /// parse a tuple with `(` and `)`.
1483
+ /// Parse a tuple with `(` and `)`.
1488
1484
/// If `lift_singleton` is true, then a singleton tuple is lifted to a tuple of length 1, otherwise it will fail.
1489
1485
/// If `allow_empty` is true, then an empty tuple is allowed.
1490
1486
fn parse_tuple (
@@ -1953,13 +1949,11 @@ impl<'a> Parser<'a> {
1953
1949
}
1954
1950
}
1955
1951
1956
- /// Parses fulltext expressions [(1) ]
1952
+ /// Parses fulltext expressions [`sqlparser::ast::Expr::MatchAgainst` ]
1957
1953
///
1958
1954
/// # Errors
1959
1955
/// This method will raise an error if the column list is empty or with invalid identifiers,
1960
1956
/// the match expression is not a literal string, or if the search modifier is not valid.
1961
- ///
1962
- /// [(1)]: Expr::MatchAgainst
1963
1957
pub fn parse_match_against ( & mut self ) -> Result < Expr , ParserError > {
1964
1958
let columns = self . parse_parenthesized_column_list ( Mandatory , false ) ?;
1965
1959
@@ -2004,17 +1998,19 @@ impl<'a> Parser<'a> {
2004
1998
} )
2005
1999
}
2006
2000
2007
- /// Parse an INTERVAL expression.
2001
+ /// Parse an ` INTERVAL` expression.
2008
2002
///
2009
2003
/// Some syntactically valid intervals:
2010
2004
///
2011
- /// 1. `INTERVAL '1' DAY`
2012
- /// 2. `INTERVAL '1-1' YEAR TO MONTH`
2013
- /// 3. `INTERVAL '1' SECOND`
2014
- /// 4. `INTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)`
2015
- /// 5. `INTERVAL '1.1' SECOND (2, 2)`
2016
- /// 6. `INTERVAL '1:1' HOUR (5) TO MINUTE (5)`
2017
- /// 7. (MySql and BigQuey only):`INTERVAL 1 DAY`
2005
+ /// ```sql
2006
+ /// 1. INTERVAL '1' DAY
2007
+ /// 2. INTERVAL '1-1' YEAR TO MONTH
2008
+ /// 3. INTERVAL '1' SECOND
2009
+ /// 4. INTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)
2010
+ /// 5. INTERVAL '1.1' SECOND (2, 2)
2011
+ /// 6. INTERVAL '1:1' HOUR (5) TO MINUTE (5)
2012
+ /// 7. (MySql & BigQuey only): INTERVAL 1 DAY
2013
+ /// ```
2018
2014
///
2019
2015
/// Note that we do not currently attempt to parse the quoted value.
2020
2016
pub fn parse_interval ( & mut self ) -> Result < Expr , ParserError > {
@@ -2210,15 +2206,15 @@ impl<'a> Parser<'a> {
2210
2206
) )
2211
2207
}
2212
2208
2213
- /// Parse a field definition in a struct [1 ] or tuple [2 ].
2209
+ /// Parse a field definition in a [struct ] or [tuple ].
2214
2210
/// Syntax:
2215
2211
///
2216
2212
/// ```sql
2217
2213
/// [field_name] field_type
2218
2214
/// ```
2219
2215
///
2220
- /// [1 ]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type
2221
- /// [2 ]: https://clickhouse.com/docs/en/sql-reference/data-types/tuple
2216
+ /// [struct ]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type
2217
+ /// [tuple ]: https://clickhouse.com/docs/en/sql-reference/data-types/tuple
2222
2218
fn parse_struct_field_def (
2223
2219
& mut self ,
2224
2220
) -> Result < ( StructField , MatchedTrailingBracket ) , ParserError > {
@@ -2272,15 +2268,15 @@ impl<'a> Parser<'a> {
2272
2268
Ok ( fields)
2273
2269
}
2274
2270
2275
- /// DuckDB specific: Parse a duckdb dictionary [1 ]
2271
+ /// DuckDB specific: Parse a duckdb [dictionary ]
2276
2272
///
2277
2273
/// Syntax:
2278
2274
///
2279
2275
/// ```sql
2280
2276
/// {'field_name': expr1[, ... ]}
2281
2277
/// ```
2282
2278
///
2283
- /// [1 ]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
2279
+ /// [dictionary ]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
2284
2280
fn parse_duckdb_struct_literal ( & mut self ) -> Result < Expr , ParserError > {
2285
2281
self . expect_token ( & Token :: LBrace ) ?;
2286
2282
@@ -2291,13 +2287,15 @@ impl<'a> Parser<'a> {
2291
2287
Ok ( Expr :: Dictionary ( fields) )
2292
2288
}
2293
2289
2294
- /// Parse a field for a duckdb dictionary [1]
2290
+ /// Parse a field for a duckdb [dictionary]
2291
+ ///
2295
2292
/// Syntax
2293
+ ///
2296
2294
/// ```sql
2297
2295
/// 'name': expr
2298
2296
/// ```
2299
2297
///
2300
- /// [1 ]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
2298
+ /// [dictionary ]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
2301
2299
fn parse_duckdb_dictionary_field ( & mut self ) -> Result < DictionaryField , ParserError > {
2302
2300
let key = self . parse_identifier ( false ) ?;
2303
2301
@@ -2311,13 +2309,15 @@ impl<'a> Parser<'a> {
2311
2309
} )
2312
2310
}
2313
2311
2314
- /// Parse clickhouse map [1]
2312
+ /// Parse clickhouse [map]
2313
+ ///
2315
2314
/// Syntax
2315
+ ///
2316
2316
/// ```sql
2317
2317
/// Map(key_data_type, value_data_type)
2318
2318
/// ```
2319
2319
///
2320
- /// [1 ]: https://clickhouse.com/docs/en/sql-reference/data-types/map
2320
+ /// [map ]: https://clickhouse.com/docs/en/sql-reference/data-types/map
2321
2321
fn parse_click_house_map_def ( & mut self ) -> Result < ( DataType , DataType ) , ParserError > {
2322
2322
self . expect_keyword ( Keyword :: MAP ) ?;
2323
2323
self . expect_token ( & Token :: LParen ) ?;
@@ -2329,13 +2329,15 @@ impl<'a> Parser<'a> {
2329
2329
Ok ( ( key_data_type, value_data_type) )
2330
2330
}
2331
2331
2332
- /// Parse clickhouse tuple [1]
2332
+ /// Parse clickhouse [tuple]
2333
+ ///
2333
2334
/// Syntax
2335
+ ///
2334
2336
/// ```sql
2335
2337
/// Tuple([field_name] field_type, ...)
2336
2338
/// ```
2337
2339
///
2338
- /// [1 ]: https://clickhouse.com/docs/en/sql-reference/data-types/tuple
2340
+ /// [tuple ]: https://clickhouse.com/docs/en/sql-reference/data-types/tuple
2339
2341
fn parse_click_house_tuple_def ( & mut self ) -> Result < Vec < StructField > , ParserError > {
2340
2342
self . expect_keyword ( Keyword :: TUPLE ) ?;
2341
2343
self . expect_token ( & Token :: LParen ) ?;
@@ -2649,7 +2651,7 @@ impl<'a> Parser<'a> {
2649
2651
}
2650
2652
}
2651
2653
2652
- /// parse the ESCAPE CHAR portion of LIKE, ILIKE, and SIMILAR TO
2654
+ /// Parse the ` ESCAPE CHAR` portion of ` LIKE`, ` ILIKE` , and ` SIMILAR TO`
2653
2655
pub fn parse_escape_char ( & mut self ) -> Result < Option < String > , ParserError > {
2654
2656
if self . parse_keyword ( Keyword :: ESCAPE ) {
2655
2657
Ok ( Some ( self . parse_literal_string ( ) ?) )
@@ -2836,7 +2838,7 @@ impl<'a> Parser<'a> {
2836
2838
} )
2837
2839
}
2838
2840
2839
- /// Parses the parens following the `[ NOT ] IN` operator
2841
+ /// Parses the parens following the `[ NOT ] IN` operator.
2840
2842
pub fn parse_in ( & mut self , expr : Expr , negated : bool ) -> Result < Expr , ParserError > {
2841
2843
// BigQuery allows `IN UNNEST(array_expression)`
2842
2844
// https://cloud.google.com/bigquery/docs/reference/standard-sql/operators#in_operators
@@ -2873,7 +2875,7 @@ impl<'a> Parser<'a> {
2873
2875
Ok ( in_op)
2874
2876
}
2875
2877
2876
- /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was already consumed
2878
+ /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was already consumed.
2877
2879
pub fn parse_between ( & mut self , expr : Expr , negated : bool ) -> Result < Expr , ParserError > {
2878
2880
// Stop parsing subexpressions for <low> and <high> on tokens with
2879
2881
// precedence lower than that of `BETWEEN`, such as `AND`, `IS`, etc.
@@ -2888,7 +2890,7 @@ impl<'a> Parser<'a> {
2888
2890
} )
2889
2891
}
2890
2892
2891
- /// Parse a postgresql casting style which is in the form of `expr::datatype`
2893
+ /// Parse a postgresql casting style which is in the form of `expr::datatype`.
2892
2894
pub fn parse_pg_cast ( & mut self , expr : Expr ) -> Result < Expr , ParserError > {
2893
2895
Ok ( Expr :: Cast {
2894
2896
kind : CastKind :: DoubleColon ,
@@ -2898,7 +2900,7 @@ impl<'a> Parser<'a> {
2898
2900
} )
2899
2901
}
2900
2902
2901
- // use https://www.postgresql.org/docs/7.0/operators.htm#AEN2026 as a reference
2903
+ // Use https://www.postgresql.org/docs/7.0/operators.htm#AEN2026 as a reference
2902
2904
// higher number = higher precedence
2903
2905
//
2904
2906
// NOTE: The pg documentation is incomplete, e.g. the AT TIME ZONE operator
@@ -3217,7 +3219,7 @@ impl<'a> Parser<'a> {
3217
3219
3218
3220
/// If the current token is one of the given `keywords`, consume the token
3219
3221
/// and return the keyword that matches. Otherwise, no tokens are consumed
3220
- /// and returns `None`.
3222
+ /// and returns [ `None`] .
3221
3223
#[ must_use]
3222
3224
pub fn parse_one_of_keywords ( & mut self , keywords : & [ Keyword ] ) -> Option < Keyword > {
3223
3225
match self . peek_token ( ) . token {
@@ -3393,8 +3395,7 @@ impl<'a> Parser<'a> {
3393
3395
self . parse_comma_separated ( f)
3394
3396
}
3395
3397
3396
- /// Run a parser method `f`, reverting back to the current position
3397
- /// if unsuccessful.
3398
+ /// Run a parser method `f`, reverting back to the current position if unsuccessful.
3398
3399
#[ must_use]
3399
3400
fn maybe_parse < T , F > ( & mut self , mut f : F ) -> Option < T >
3400
3401
where
@@ -3409,8 +3410,8 @@ impl<'a> Parser<'a> {
3409
3410
}
3410
3411
}
3411
3412
3412
- /// Parse either `ALL`, `DISTINCT` or `DISTINCT ON (...)`. Returns `None` if `ALL` is parsed
3413
- /// and results in a `ParserError` if both `ALL` and `DISTINCT` are found.
3413
+ /// Parse either `ALL`, `DISTINCT` or `DISTINCT ON (...)`. Returns [ `None`] if `ALL` is parsed
3414
+ /// and results in a [ `ParserError`] if both `ALL` and `DISTINCT` are found.
3414
3415
pub fn parse_all_or_distinct ( & mut self ) -> Result < Option < Distinct > , ParserError > {
3415
3416
let loc = self . peek_token ( ) . location ;
3416
3417
let all = self . parse_keyword ( Keyword :: ALL ) ;
0 commit comments