@@ -66,7 +66,8 @@ macro_rules! dialect_of {
6666/// Encapsulates the differences between SQL implementations.
6767///
6868/// # SQL Dialects
69- /// SQL implementations deviatiate from one another, either due to
69+ ///
70+ /// SQL implementations deviate from one another, either due to
7071/// custom extensions or various historical reasons. This trait
7172/// encapsulates the parsing differences between dialects.
7273///
@@ -114,16 +115,20 @@ pub trait Dialect: Debug + Any {
114115 fn is_delimited_identifier_start ( & self , ch : char ) -> bool {
115116 ch == '"' || ch == '`'
116117 }
118+
117119 /// Return the character used to quote identifiers.
118120 fn identifier_quote_style ( & self , _identifier : & str ) -> Option < char > {
119121 None
120122 }
123+
121124 /// Determine if quoted characters are proper for identifier
122125 fn is_proper_identifier_inside_quotes ( & self , mut _chars : Peekable < Chars < ' _ > > ) -> bool {
123126 true
124127 }
128+
125129 /// Determine if a character is a valid start character for an unquoted identifier
126130 fn is_identifier_start ( & self , ch : char ) -> bool ;
131+
127132 /// Determine if a character is a valid unquoted identifier character
128133 fn is_identifier_part ( & self , ch : char ) -> bool ;
129134
@@ -168,6 +173,7 @@ pub trait Dialect: Debug + Any {
168173 fn supports_filter_during_aggregation ( & self ) -> bool {
169174 false
170175 }
176+
171177 /// Returns true if the dialect supports referencing another named window
172178 /// within a window clause declaration.
173179 ///
@@ -179,45 +185,55 @@ pub trait Dialect: Debug + Any {
179185 fn supports_window_clause_named_window_reference ( & self ) -> bool {
180186 false
181187 }
188+
182189 /// Returns true if the dialect supports `ARRAY_AGG() [WITHIN GROUP (ORDER BY)]` expressions.
183190 /// Otherwise, the dialect should expect an `ORDER BY` without the `WITHIN GROUP` clause, e.g. [`ANSI`]
184191 ///
185192 /// [`ANSI`]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#array-aggregate-function
186193 fn supports_within_after_array_aggregation ( & self ) -> bool {
187194 false
188195 }
196+
189197 /// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
190198 fn supports_group_by_expr ( & self ) -> bool {
191199 false
192200 }
201+
193202 /// Returns true if the dialect supports CONNECT BY.
194203 fn supports_connect_by ( & self ) -> bool {
195204 false
196205 }
206+
197207 /// Returns true if the dialect supports the MATCH_RECOGNIZE operation.
198208 fn supports_match_recognize ( & self ) -> bool {
199209 false
200210 }
211+
201212 /// Returns true if the dialect supports `(NOT) IN ()` expressions
202213 fn supports_in_empty_list ( & self ) -> bool {
203214 false
204215 }
216+
205217 /// Returns true if the dialect supports `BEGIN {DEFERRED | IMMEDIATE | EXCLUSIVE} [TRANSACTION]` statements
206218 fn supports_start_transaction_modifier ( & self ) -> bool {
207219 false
208220 }
221+
209222 /// Returns true if the dialect supports named arguments of the form FUN(a = '1', b = '2').
210223 fn supports_named_fn_args_with_eq_operator ( & self ) -> bool {
211224 false
212225 }
226+
213227 /// Returns true if the dialect supports identifiers starting with a numeric
214- /// prefix such as tables named: `59901_user_login`
228+ /// prefix such as tables named `59901_user_login`
215229 fn supports_numeric_prefix ( & self ) -> bool {
216230 false
217231 }
232+
218233 /// Returns true if the dialects supports specifying null treatment
219- /// as part of a window function's parameter list. As opposed
234+ /// as part of a window function's parameter list as opposed
220235 /// to after the parameter list.
236+ ///
221237 /// i.e The following syntax returns true
222238 /// ```sql
223239 /// FIRST_VALUE(a IGNORE NULLS) OVER ()
@@ -229,16 +245,19 @@ pub trait Dialect: Debug + Any {
229245 fn supports_window_function_null_treatment_arg ( & self ) -> bool {
230246 false
231247 }
248+
232249 /// Returns true if the dialect supports defining structs or objects using a
233250 /// syntax like `{'x': 1, 'y': 2, 'z': 3}`.
234251 fn supports_dictionary_syntax ( & self ) -> bool {
235252 false
236253 }
254+
237255 /// Returns true if the dialect supports defining object using the
238256 /// syntax like `Map {1: 10, 2: 20}`.
239257 fn support_map_literal_syntax ( & self ) -> bool {
240258 false
241259 }
260+
242261 /// Returns true if the dialect supports lambda functions, for example:
243262 ///
244263 /// ```sql
@@ -247,6 +266,7 @@ pub trait Dialect: Debug + Any {
247266 fn supports_lambda_functions ( & self ) -> bool {
248267 false
249268 }
269+
250270 /// Returns true if the dialect supports multiple variable assignment
251271 /// using parentheses in a `SET` variable declaration.
252272 ///
@@ -256,6 +276,7 @@ pub trait Dialect: Debug + Any {
256276 fn supports_parenthesized_set_variables ( & self ) -> bool {
257277 false
258278 }
279+
259280 /// Returns true if the dialect supports an `EXCEPT` clause following a
260281 /// wildcard in a select list.
261282 ///
@@ -266,30 +287,40 @@ pub trait Dialect: Debug + Any {
266287 fn supports_select_wildcard_except ( & self ) -> bool {
267288 false
268289 }
290+
269291 /// Returns true if the dialect has a CONVERT function which accepts a type first
270292 /// and an expression second, e.g. `CONVERT(varchar, 1)`
271293 fn convert_type_before_value ( & self ) -> bool {
272294 false
273295 }
296+
274297 /// Returns true if the dialect supports triple quoted string
275298 /// e.g. `"""abc"""`
276299 fn supports_triple_quoted_string ( & self ) -> bool {
277300 false
278301 }
302+
279303 /// Dialect-specific prefix parser override
280304 fn parse_prefix ( & self , _parser : & mut Parser ) -> Option < Result < Expr , ParserError > > {
281305 // return None to fall back to the default behavior
282306 None
283307 }
308+
284309 /// Does the dialect support trailing commas around the query?
285310 fn supports_trailing_commas ( & self ) -> bool {
286311 false
287312 }
313+
288314 /// Does the dialect support trailing commas in the projection list?
289315 fn supports_projection_trailing_commas ( & self ) -> bool {
290316 self . supports_trailing_commas ( )
291317 }
318+
292319 /// Dialect-specific infix parser override
320+ ///
321+ /// This method is called to parse the next infix expression.
322+ ///
323+ /// If `None` is returned, falls back to the default behavior.
293324 fn parse_infix (
294325 & self ,
295326 _parser : & mut Parser ,
@@ -299,24 +330,33 @@ pub trait Dialect: Debug + Any {
299330 // return None to fall back to the default behavior
300331 None
301332 }
333+
302334 /// Dialect-specific precedence override
335+ ///
336+ /// This method is called to get the precedence of the next token.
337+ ///
338+ /// If `None` is returned, falls back to the default behavior.
303339 fn get_next_precedence ( & self , _parser : & Parser ) -> Option < Result < u8 , ParserError > > {
304340 // return None to fall back to the default behavior
305341 None
306342 }
307343
308- /// Get the precedence of the next token. This "full" method means all precedence logic and remain
309- /// in the dialect. while still allowing overriding the `get_next_precedence` method with the option to
310- /// fallback to the default behavior.
344+ /// Get the precedence of the next token, looking at the full token stream.
311345 ///
312- /// Higher number => higher precedence
346+ /// A higher number => higher precedence
347+ ///
348+ /// See [`Self::get_next_precedence`] to override the behavior for just the
349+ /// next token.
350+ ///
351+ /// The default implementation is used for many dialects, but can be
352+ /// overridden to provide dialect-specific behavior.
313353 fn get_next_precedence_full ( & self , parser : & Parser ) -> Result < u8 , ParserError > {
314354 if let Some ( precedence) = self . get_next_precedence ( parser) {
315355 return precedence;
316356 }
317357
318358 let token = parser. peek_token ( ) ;
319- debug ! ( "get_next_precedence () {:?}" , token) ;
359+ debug ! ( "get_next_precedence_full () {:?}" , token) ;
320360 match token. token {
321361 Token :: Word ( w) if w. keyword == Keyword :: OR => Ok ( OR_PREC ) ,
322362 Token :: Word ( w) if w. keyword == Keyword :: AND => Ok ( AND_PREC ) ,
@@ -408,37 +448,67 @@ pub trait Dialect: Debug + Any {
408448 }
409449
410450 /// Dialect-specific statement parser override
451+ ///
452+ /// This method is called to parse the next statement.
453+ ///
454+ /// If `None` is returned, falls back to the default behavior.
411455 fn parse_statement ( & self , _parser : & mut Parser ) -> Option < Result < Statement , ParserError > > {
412456 // return None to fall back to the default behavior
413457 None
414458 }
415459
416- /// The following precedence values are used directly by `Parse` or in dialects,
417- /// so have to be made public by the dialect.
460+ // The following precedence values are used directly by `Parse` or in dialects,
461+ // so have to be made public by the dialect.
462+
463+ /// Return the precedence of the `::` operator.
464+ ///
465+ /// Default is 50.
418466 fn prec_double_colon ( & self ) -> u8 {
419467 DOUBLE_COLON_PREC
420468 }
421469
470+ /// Return the precedence of `*`, `/`, and `%` operators.
471+ ///
472+ /// Default is 40.
422473 fn prec_mul_div_mod_op ( & self ) -> u8 {
423474 MUL_DIV_MOD_OP_PREC
424475 }
425476
477+ /// Return the precedence of the `+` and `-` operators.
478+ ///
479+ /// Default is 30.
426480 fn prec_plus_minus ( & self ) -> u8 {
427481 PLUS_MINUS_PREC
428482 }
429483
484+ /// Return the precedence of the `BETWEEN` operator.
485+ ///
486+ /// For example `BETWEEN <low> AND <high>`
487+ ///
488+ /// Default is 22.
430489 fn prec_between ( & self ) -> u8 {
431490 BETWEEN_PREC
432491 }
433492
493+ /// Return the precedence of the `LIKE` operator.
494+ ///
495+ /// Default is 19.
434496 fn prec_like ( & self ) -> u8 {
435497 LIKE_PREC
436498 }
437499
500+ /// Return the precedence of the unary `NOT` operator.
501+ ///
502+ /// For example `NOT (a OR b)`
503+ ///
504+ /// Default is 15.
438505 fn prec_unary_not ( & self ) -> u8 {
439506 UNARY_NOT_PREC
440507 }
441508
509+ /// Return the default (unknown) precedence.
510+ ///
511+ /// Default is 0.
442512 fn prec_unknown ( & self ) -> u8 {
443513 UNKNOWN_PREC
444514 }
0 commit comments