sqruff_lib_dialects/
ansi.rs

1use itertools::Itertools;
2use sqruff_lib_core::dialects::Dialect;
3use sqruff_lib_core::dialects::syntax::SyntaxKind;
4use sqruff_lib_core::helpers::{Config, ToMatchable};
5use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed};
6use sqruff_lib_core::parser::grammar::conditional::Conditional;
7use sqruff_lib_core::parser::grammar::delimited::Delimited;
8use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence};
9use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref};
10use sqruff_lib_core::parser::lexer::{Cursor, Matcher, Pattern};
11use sqruff_lib_core::parser::lookahead::LookaheadExclude;
12use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait};
13use sqruff_lib_core::parser::node_matcher::NodeMatcher;
14use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser};
15use sqruff_lib_core::parser::segments::bracketed::BracketedSegmentMatcher;
16use sqruff_lib_core::parser::segments::generator::SegmentGenerator;
17use sqruff_lib_core::parser::segments::meta::MetaSegment;
18use sqruff_lib_core::parser::types::ParseMode;
19
20use super::ansi_keywords::{ANSI_RESERVED_KEYWORDS, ANSI_UNRESERVED_KEYWORDS};
21
22pub fn dialect() -> Dialect {
23    raw_dialect().config(|this| this.expand())
24}
25
26pub fn raw_dialect() -> Dialect {
27    let mut ansi_dialect = Dialect::new();
28
29    ansi_dialect.set_lexer_matchers(lexer_matchers());
30
31    // Set the bare functions
32    ansi_dialect.sets_mut("bare_functions").extend([
33        "current_timestamp",
34        "current_time",
35        "current_date",
36    ]);
37
38    // Set the datetime units
39    ansi_dialect.sets_mut("datetime_units").extend([
40        "DAY",
41        "DAYOFYEAR",
42        "HOUR",
43        "MILLISECOND",
44        "MINUTE",
45        "MONTH",
46        "QUARTER",
47        "SECOND",
48        "WEEK",
49        "WEEKDAY",
50        "YEAR",
51    ]);
52
53    ansi_dialect
54        .sets_mut("date_part_function_name")
55        .extend(["DATEADD"]);
56
57    // Set Keywords
58    ansi_dialect
59        .update_keywords_set_from_multiline_string("unreserved_keywords", ANSI_UNRESERVED_KEYWORDS);
60    ansi_dialect
61        .update_keywords_set_from_multiline_string("reserved_keywords", ANSI_RESERVED_KEYWORDS);
62
63    // Bracket pairs (a set of tuples).
64    // (name, startref, endref, persists)
65    // NOTE: The `persists` value controls whether this type
66    // of bracket is persisted during matching to speed up other
67    // parts of the matching process. Round brackets are the most
68    // common and match the largest areas and so are sufficient.
69    ansi_dialect.update_bracket_sets(
70        "bracket_pairs",
71        vec![
72            ("round", "StartBracketSegment", "EndBracketSegment", true),
73            (
74                "square",
75                "StartSquareBracketSegment",
76                "EndSquareBracketSegment",
77                false,
78            ),
79            (
80                "curly",
81                "StartCurlyBracketSegment",
82                "EndCurlyBracketSegment",
83                false,
84            ),
85        ],
86    );
87
88    // Set the value table functions. These are functions that, if they appear as
89    // an item in "FROM", are treated as returning a COLUMN, not a TABLE.
90    // Apparently, among dialects supported by SQLFluff, only BigQuery has this
91    // concept, but this set is defined in the ANSI dialect because:
92    // - It impacts core linter rules (see AL04 and several other rules that
93    //   subclass from it) and how they interpret the contents of table_expressions
94    // - At least one other database (DB2) has the same value table function,
95    //   UNNEST(), as BigQuery. DB2 is not currently supported by SQLFluff.
96    ansi_dialect.sets_mut("value_table_functions");
97
98    ansi_dialect.add([
99        (
100            "ArrayTypeSchemaSegment".into(),
101            NodeMatcher::new(SyntaxKind::ArrayType, |_| Nothing::new().to_matchable())
102                .to_matchable()
103                .into(),
104        ),
105        (
106            "ObjectReferenceSegment".into(),
107            NodeMatcher::new(SyntaxKind::ObjectReference, |_| {
108                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
109                    .config(|this| {
110                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
111                        this.disallow_gaps();
112                        this.terminators =
113                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
114                    })
115                    .to_matchable()
116            })
117            .to_matchable()
118            .into(),
119        ),
120    ]);
121
122    ansi_dialect.add([
123        // Real segments
124        (
125            "DelimiterGrammar".into(),
126            Ref::new("SemicolonSegment").to_matchable().into(),
127        ),
128        (
129            "SemicolonSegment".into(),
130            StringParser::new(";", SyntaxKind::StatementTerminator)
131                .to_matchable()
132                .into(),
133        ),
134        (
135            "ColonSegment".into(),
136            StringParser::new(":", SyntaxKind::Colon)
137                .to_matchable()
138                .into(),
139        ),
140        (
141            "SliceSegment".into(),
142            StringParser::new(":", SyntaxKind::Slice)
143                .to_matchable()
144                .into(),
145        ),
146        // NOTE: The purpose of the colon_delimiter is that it has different layout rules.
147        // It assumes no whitespace on either side.
148        (
149            "ColonDelimiterSegment".into(),
150            StringParser::new(":", SyntaxKind::ColonDelimiter)
151                .to_matchable()
152                .into(),
153        ),
154        (
155            "StartBracketSegment".into(),
156            StringParser::new("(", SyntaxKind::StartBracket)
157                .to_matchable()
158                .into(),
159        ),
160        (
161            "EndBracketSegment".into(),
162            StringParser::new(")", SyntaxKind::EndBracket)
163                .to_matchable()
164                .into(),
165        ),
166        (
167            "StartSquareBracketSegment".into(),
168            StringParser::new("[", SyntaxKind::StartSquareBracket)
169                .to_matchable()
170                .into(),
171        ),
172        (
173            "EndSquareBracketSegment".into(),
174            StringParser::new("]", SyntaxKind::EndSquareBracket)
175                .to_matchable()
176                .into(),
177        ),
178        (
179            "StartCurlyBracketSegment".into(),
180            StringParser::new("{", SyntaxKind::StartCurlyBracket)
181                .to_matchable()
182                .into(),
183        ),
184        (
185            "EndCurlyBracketSegment".into(),
186            StringParser::new("}", SyntaxKind::EndCurlyBracket)
187                .to_matchable()
188                .into(),
189        ),
190        (
191            "CommaSegment".into(),
192            StringParser::new(",", SyntaxKind::Comma)
193                .to_matchable()
194                .into(),
195        ),
196        (
197            "DotSegment".into(),
198            StringParser::new(".", SyntaxKind::Dot)
199                .to_matchable()
200                .into(),
201        ),
202        (
203            "StarSegment".into(),
204            StringParser::new("*", SyntaxKind::Star)
205                .to_matchable()
206                .into(),
207        ),
208        (
209            "TildeSegment".into(),
210            StringParser::new("~", SyntaxKind::Tilde)
211                .to_matchable()
212                .into(),
213        ),
214        (
215            "ParameterSegment".into(),
216            StringParser::new("?", SyntaxKind::Parameter)
217                .to_matchable()
218                .into(),
219        ),
220        (
221            "CastOperatorSegment".into(),
222            StringParser::new("::", SyntaxKind::CastingOperator)
223                .to_matchable()
224                .into(),
225        ),
226        (
227            "PlusSegment".into(),
228            StringParser::new("+", SyntaxKind::BinaryOperator)
229                .to_matchable()
230                .into(),
231        ),
232        (
233            "MinusSegment".into(),
234            StringParser::new("-", SyntaxKind::BinaryOperator)
235                .to_matchable()
236                .into(),
237        ),
238        (
239            "PositiveSegment".into(),
240            StringParser::new("+", SyntaxKind::SignIndicator)
241                .to_matchable()
242                .into(),
243        ),
244        (
245            "NegativeSegment".into(),
246            StringParser::new("-", SyntaxKind::SignIndicator)
247                .to_matchable()
248                .into(),
249        ),
250        (
251            "DivideSegment".into(),
252            StringParser::new("/", SyntaxKind::BinaryOperator)
253                .to_matchable()
254                .into(),
255        ),
256        (
257            "MultiplySegment".into(),
258            StringParser::new("*", SyntaxKind::BinaryOperator)
259                .to_matchable()
260                .into(),
261        ),
262        (
263            "ModuloSegment".into(),
264            StringParser::new("%", SyntaxKind::BinaryOperator)
265                .to_matchable()
266                .into(),
267        ),
268        (
269            "SlashSegment".into(),
270            StringParser::new("/", SyntaxKind::Slash)
271                .to_matchable()
272                .into(),
273        ),
274        (
275            "AmpersandSegment".into(),
276            StringParser::new("&", SyntaxKind::Ampersand)
277                .to_matchable()
278                .into(),
279        ),
280        (
281            "PipeSegment".into(),
282            StringParser::new("|", SyntaxKind::Pipe)
283                .to_matchable()
284                .into(),
285        ),
286        (
287            "BitwiseXorSegment".into(),
288            StringParser::new("^", SyntaxKind::BinaryOperator)
289                .to_matchable()
290                .into(),
291        ),
292        (
293            "LikeOperatorSegment".into(),
294            TypedParser::new(SyntaxKind::LikeOperator, SyntaxKind::ComparisonOperator)
295                .to_matchable()
296                .into(),
297        ),
298        (
299            "RawNotSegment".into(),
300            StringParser::new("!", SyntaxKind::RawComparisonOperator)
301                .to_matchable()
302                .into(),
303        ),
304        (
305            "RawEqualsSegment".into(),
306            StringParser::new("=", SyntaxKind::RawComparisonOperator)
307                .to_matchable()
308                .into(),
309        ),
310        (
311            "RawGreaterThanSegment".into(),
312            StringParser::new(">", SyntaxKind::RawComparisonOperator)
313                .to_matchable()
314                .into(),
315        ),
316        (
317            "RawLessThanSegment".into(),
318            StringParser::new("<", SyntaxKind::RawComparisonOperator)
319                .to_matchable()
320                .into(),
321        ),
322        (
323            // The following functions can be called without parentheses per ANSI specification
324            "BareFunctionSegment".into(),
325            SegmentGenerator::new(|dialect| {
326                MultiStringParser::new(
327                    dialect
328                        .sets("bare_functions")
329                        .into_iter()
330                        .map_into()
331                        .collect_vec(),
332                    SyntaxKind::BareFunction,
333                )
334                .to_matchable()
335            })
336            .into(),
337        ),
338        // The strange regex here it to make sure we don't accidentally match numeric
339        // literals. We also use a regex to explicitly exclude disallowed keywords.
340        (
341            "NakedIdentifierSegment".into(),
342            SegmentGenerator::new(|dialect| {
343                // Generate the anti template from the set of reserved keywords
344                let reserved_keywords = dialect.sets("reserved_keywords");
345                let pattern = reserved_keywords.iter().join("|");
346                let anti_template = format!("^({pattern})$");
347
348                RegexParser::new("[A-Z0-9_]*[A-Z][A-Z0-9_]*", SyntaxKind::NakedIdentifier)
349                    .anti_template(&anti_template)
350                    .to_matchable()
351            })
352            .into(),
353        ),
354        (
355            "ParameterNameSegment".into(),
356            RegexParser::new(r#"\"?[A-Z][A-Z0-9_]*\"?"#, SyntaxKind::Parameter)
357                .to_matchable()
358                .into(),
359        ),
360        (
361            "FunctionNameIdentifierSegment".into(),
362            TypedParser::new(SyntaxKind::Word, SyntaxKind::FunctionNameIdentifier)
363                .to_matchable()
364                .into(),
365        ),
366        // Maybe data types should be more restrictive?
367        (
368            "DatatypeIdentifierSegment".into(),
369            SegmentGenerator::new(|_| {
370                // Generate the anti template from the set of reserved keywords
371                // TODO - this is a stopgap until we implement explicit data types
372                let anti_template = format!("^({})$", "NOT");
373
374                one_of(vec![
375                    RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::DataTypeIdentifier)
376                        .anti_template(&anti_template)
377                        .to_matchable(),
378                    Ref::new("SingleIdentifierGrammar")
379                        .exclude(Ref::new("NakedIdentifierSegment"))
380                        .to_matchable(),
381                ])
382                .to_matchable()
383            })
384            .into(),
385        ),
386        // Ansi Intervals
387        (
388            "DatetimeUnitSegment".into(),
389            SegmentGenerator::new(|dialect| {
390                MultiStringParser::new(
391                    dialect
392                        .sets("datetime_units")
393                        .into_iter()
394                        .map_into()
395                        .collect_vec(),
396                    SyntaxKind::DatePart,
397                )
398                .to_matchable()
399            })
400            .into(),
401        ),
402        (
403            "DatePartFunctionName".into(),
404            SegmentGenerator::new(|dialect| {
405                MultiStringParser::new(
406                    dialect
407                        .sets("date_part_function_name")
408                        .into_iter()
409                        .map_into()
410                        .collect::<Vec<_>>(),
411                    SyntaxKind::FunctionNameIdentifier,
412                )
413                .to_matchable()
414            })
415            .into(),
416        ),
417        (
418            "QuotedIdentifierSegment".into(),
419            TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier)
420                .to_matchable()
421                .into(),
422        ),
423        (
424            "QuotedLiteralSegment".into(),
425            TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
426                .to_matchable()
427                .into(),
428        ),
429        (
430            "SingleQuotedIdentifierSegment".into(),
431            TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedIdentifier)
432                .to_matchable()
433                .into(),
434        ),
435        (
436            "NumericLiteralSegment".into(),
437            TypedParser::new(SyntaxKind::NumericLiteral, SyntaxKind::NumericLiteral)
438                .to_matchable()
439                .into(),
440        ),
441        // NullSegment is defined separately to the keyword, so we can give it a different
442        // type
443        (
444            "NullLiteralSegment".into(),
445            StringParser::new("null", SyntaxKind::NullLiteral)
446                .to_matchable()
447                .into(),
448        ),
449        (
450            "NanLiteralSegment".into(),
451            StringParser::new("nan", SyntaxKind::NullLiteral)
452                .to_matchable()
453                .into(),
454        ),
455        (
456            "TrueSegment".into(),
457            StringParser::new("true", SyntaxKind::BooleanLiteral)
458                .to_matchable()
459                .into(),
460        ),
461        (
462            "FalseSegment".into(),
463            StringParser::new("false", SyntaxKind::BooleanLiteral)
464                .to_matchable()
465                .into(),
466        ),
467        // We use a GRAMMAR here not a Segment. Otherwise, we get an unnecessary layer
468        (
469            "SingleIdentifierGrammar".into(),
470            one_of(vec![
471                Ref::new("NakedIdentifierSegment").to_matchable(),
472                Ref::new("QuotedIdentifierSegment").to_matchable(),
473            ])
474            .config(|this| this.terminators = vec![Ref::new("DotSegment").to_matchable()])
475            .to_matchable()
476            .into(),
477        ),
478        (
479            "BooleanLiteralGrammar".into(),
480            one_of(vec![
481                Ref::new("TrueSegment").to_matchable(),
482                Ref::new("FalseSegment").to_matchable(),
483            ])
484            .to_matchable()
485            .into(),
486        ),
487        // We specifically define a group of arithmetic operators to make it easier to
488        // override this if some dialects have different available operators
489        (
490            "ArithmeticBinaryOperatorGrammar".into(),
491            one_of(vec![
492                Ref::new("PlusSegment").to_matchable(),
493                Ref::new("MinusSegment").to_matchable(),
494                Ref::new("DivideSegment").to_matchable(),
495                Ref::new("MultiplySegment").to_matchable(),
496                Ref::new("ModuloSegment").to_matchable(),
497                Ref::new("BitwiseAndSegment").to_matchable(),
498                Ref::new("BitwiseOrSegment").to_matchable(),
499                Ref::new("BitwiseXorSegment").to_matchable(),
500                Ref::new("BitwiseLShiftSegment").to_matchable(),
501                Ref::new("BitwiseRShiftSegment").to_matchable(),
502            ])
503            .to_matchable()
504            .into(),
505        ),
506        (
507            "SignedSegmentGrammar".into(),
508            one_of(vec![
509                Ref::new("PositiveSegment").to_matchable(),
510                Ref::new("NegativeSegment").to_matchable(),
511            ])
512            .to_matchable()
513            .into(),
514        ),
515        (
516            "StringBinaryOperatorGrammar".into(),
517            one_of(vec![Ref::new("ConcatSegment").to_matchable()])
518                .to_matchable()
519                .into(),
520        ),
521        (
522            "BooleanBinaryOperatorGrammar".into(),
523            one_of(vec![
524                Ref::new("AndOperatorGrammar").to_matchable(),
525                Ref::new("OrOperatorGrammar").to_matchable(),
526            ])
527            .to_matchable()
528            .into(),
529        ),
530        (
531            "ComparisonOperatorGrammar".into(),
532            one_of(vec![
533                Ref::new("EqualsSegment").to_matchable(),
534                Ref::new("GreaterThanSegment").to_matchable(),
535                Ref::new("LessThanSegment").to_matchable(),
536                Ref::new("GreaterThanOrEqualToSegment").to_matchable(),
537                Ref::new("LessThanOrEqualToSegment").to_matchable(),
538                Ref::new("NotEqualToSegment").to_matchable(),
539                Ref::new("LikeOperatorSegment").to_matchable(),
540                Sequence::new(vec![
541                    Ref::keyword("IS").to_matchable(),
542                    Ref::keyword("DISTINCT").to_matchable(),
543                    Ref::keyword("FROM").to_matchable(),
544                ])
545                .to_matchable(),
546                Sequence::new(vec![
547                    Ref::keyword("IS").to_matchable(),
548                    Ref::keyword("NOT").to_matchable(),
549                    Ref::keyword("DISTINCT").to_matchable(),
550                    Ref::keyword("FROM").to_matchable(),
551                ])
552                .to_matchable(),
553            ])
554            .to_matchable()
555            .into(),
556        ),
557        // hookpoint for other dialects
558        // e.g. EXASOL str to date cast with DATE '2021-01-01'
559        // Give it a different type as needs to be single quotes and
560        // should not be changed by rules (e.g. rule CV10)
561        (
562            "DateTimeLiteralGrammar".into(),
563            Sequence::new(vec![
564                one_of(vec![
565                    Ref::keyword("DATE").to_matchable(),
566                    Ref::keyword("TIME").to_matchable(),
567                    Ref::keyword("TIMESTAMP").to_matchable(),
568                    Ref::keyword("INTERVAL").to_matchable(),
569                ])
570                .to_matchable(),
571                TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral)
572                    .to_matchable(),
573            ])
574            .to_matchable()
575            .into(),
576        ),
577        // Hookpoint for other dialects
578        // e.g. INTO is optional in BIGQUERY
579        (
580            "MergeIntoLiteralGrammar".into(),
581            Sequence::new(vec![
582                Ref::keyword("MERGE").to_matchable(),
583                Ref::keyword("INTO").to_matchable(),
584            ])
585            .to_matchable()
586            .into(),
587        ),
588        (
589            "LiteralGrammar".into(),
590            one_of(vec![
591                Ref::new("QuotedLiteralSegment").to_matchable(),
592                Ref::new("NumericLiteralSegment").to_matchable(),
593                Ref::new("BooleanLiteralGrammar").to_matchable(),
594                Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
595                // NB: Null is included in the literals, because it is a keyword which
596                // can otherwise be easily mistaken for an identifier.
597                Ref::new("NullLiteralSegment").to_matchable(),
598                Ref::new("DateTimeLiteralGrammar").to_matchable(),
599                Ref::new("ArrayLiteralSegment").to_matchable(),
600                Ref::new("TypedArrayLiteralSegment").to_matchable(),
601                Ref::new("ObjectLiteralSegment").to_matchable(),
602            ])
603            .to_matchable()
604            .into(),
605        ),
606        (
607            "AndOperatorGrammar".into(),
608            StringParser::new("AND", SyntaxKind::BinaryOperator)
609                .to_matchable()
610                .into(),
611        ),
612        (
613            "OrOperatorGrammar".into(),
614            StringParser::new("OR", SyntaxKind::BinaryOperator)
615                .to_matchable()
616                .into(),
617        ),
618        (
619            "NotOperatorGrammar".into(),
620            StringParser::new("NOT", SyntaxKind::Keyword)
621                .to_matchable()
622                .into(),
623        ),
624        (
625            // This is a placeholder for other dialects.
626            "PreTableFunctionKeywordsGrammar".into(),
627            Nothing::new().to_matchable().into(),
628        ),
629        (
630            "BinaryOperatorGrammar".into(),
631            one_of(vec![
632                Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(),
633                Ref::new("StringBinaryOperatorGrammar").to_matchable(),
634                Ref::new("BooleanBinaryOperatorGrammar").to_matchable(),
635                Ref::new("ComparisonOperatorGrammar").to_matchable(),
636            ])
637            .to_matchable()
638            .into(),
639        ),
640        // This pattern is used in a lot of places.
641        // Defined here to avoid repetition.
642        (
643            "BracketedColumnReferenceListGrammar".into(),
644            Bracketed::new(vec![
645                Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
646                    .to_matchable(),
647            ])
648            .to_matchable()
649            .into(),
650        ),
651        (
652            "OrReplaceGrammar".into(),
653            Sequence::new(vec![
654                Ref::keyword("OR").to_matchable(),
655                Ref::keyword("REPLACE").to_matchable(),
656            ])
657            .to_matchable()
658            .into(),
659        ),
660        (
661            "TemporaryTransientGrammar".into(),
662            one_of(vec![
663                Ref::keyword("TRANSIENT").to_matchable(),
664                Ref::new("TemporaryGrammar").to_matchable(),
665            ])
666            .to_matchable()
667            .into(),
668        ),
669        (
670            "TemporaryGrammar".into(),
671            one_of(vec![
672                Ref::keyword("TEMP").to_matchable(),
673                Ref::keyword("TEMPORARY").to_matchable(),
674            ])
675            .to_matchable()
676            .into(),
677        ),
678        (
679            "IfExistsGrammar".into(),
680            Sequence::new(vec![
681                Ref::keyword("IF").to_matchable(),
682                Ref::keyword("EXISTS").to_matchable(),
683            ])
684            .to_matchable()
685            .into(),
686        ),
687        (
688            "IfNotExistsGrammar".into(),
689            Sequence::new(vec![
690                Ref::keyword("IF").to_matchable(),
691                Ref::keyword("NOT").to_matchable(),
692                Ref::keyword("EXISTS").to_matchable(),
693            ])
694            .to_matchable()
695            .into(),
696        ),
697        (
698            "LikeGrammar".into(),
699            one_of(vec![
700                Ref::keyword("LIKE").to_matchable(),
701                Ref::keyword("RLIKE").to_matchable(),
702                Ref::keyword("ILIKE").to_matchable(),
703            ])
704            .to_matchable()
705            .into(),
706        ),
707        (
708            "UnionGrammar".into(),
709            Sequence::new(vec![
710                Ref::keyword("UNION").to_matchable(),
711                one_of(vec![
712                    Ref::keyword("DISTINCT").to_matchable(),
713                    Ref::keyword("ALL").to_matchable(),
714                ])
715                .config(|this| this.optional())
716                .to_matchable(),
717            ])
718            .to_matchable()
719            .into(),
720        ),
721        (
722            "IsClauseGrammar".into(),
723            one_of(vec![
724                Ref::new("NullLiteralSegment").to_matchable(),
725                Ref::new("NanLiteralSegment").to_matchable(),
726                Ref::new("BooleanLiteralGrammar").to_matchable(),
727            ])
728            .to_matchable()
729            .into(),
730        ),
731        (
732            "InOperatorGrammar".into(),
733            Sequence::new(vec![
734                Ref::keyword("NOT").optional().to_matchable(),
735                Ref::keyword("IN").to_matchable(),
736                one_of(vec![
737                    Bracketed::new(vec![
738                        one_of(vec![
739                            Delimited::new(vec![Ref::new("Expression_A_Grammar").to_matchable()])
740                                .to_matchable(),
741                            Ref::new("SelectableGrammar").to_matchable(),
742                        ])
743                        .to_matchable(),
744                    ])
745                    .config(|this| this.parse_mode(ParseMode::Greedy))
746                    .to_matchable(),
747                    Ref::new("FunctionSegment").to_matchable(),
748                ])
749                .to_matchable(),
750            ])
751            .to_matchable()
752            .into(),
753        ),
754        (
755            "SelectClauseTerminatorGrammar".into(),
756            one_of(select_clause_terminators()).to_matchable().into(),
757        ),
758        // Define these as grammars to allow child dialects to enable them (since they are
759        // non-standard keywords)
760        ("IsNullGrammar".into(), Nothing::new().to_matchable().into()),
761        (
762            "NotNullGrammar".into(),
763            Nothing::new().to_matchable().into(),
764        ),
765        (
766            "CollateGrammar".into(),
767            Nothing::new().to_matchable().into(),
768        ),
769        (
770            "FromClauseTerminatorGrammar".into(),
771            one_of(vec![
772                Ref::keyword("WHERE").to_matchable(),
773                Ref::keyword("LIMIT").to_matchable(),
774                Sequence::new(vec![
775                    Ref::keyword("GROUP").to_matchable(),
776                    Ref::keyword("BY").to_matchable(),
777                ])
778                .to_matchable(),
779                Sequence::new(vec![
780                    Ref::keyword("ORDER").to_matchable(),
781                    Ref::keyword("BY").to_matchable(),
782                ])
783                .to_matchable(),
784                Ref::keyword("HAVING").to_matchable(),
785                Ref::keyword("QUALIFY").to_matchable(),
786                Ref::keyword("WINDOW").to_matchable(),
787                Ref::new("SetOperatorSegment").to_matchable(),
788                Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
789                Ref::new("WithDataClauseSegment").to_matchable(),
790                Ref::keyword("FETCH").to_matchable(),
791            ])
792            .to_matchable()
793            .into(),
794        ),
795        (
796            "WhereClauseTerminatorGrammar".into(),
797            one_of(vec![
798                Ref::keyword("LIMIT").to_matchable(),
799                Sequence::new(vec![
800                    Ref::keyword("GROUP").to_matchable(),
801                    Ref::keyword("BY").to_matchable(),
802                ])
803                .to_matchable(),
804                Sequence::new(vec![
805                    Ref::keyword("ORDER").to_matchable(),
806                    Ref::keyword("BY").to_matchable(),
807                ])
808                .to_matchable(),
809                Ref::keyword("HAVING").to_matchable(),
810                Ref::keyword("QUALIFY").to_matchable(),
811                Ref::keyword("WINDOW").to_matchable(),
812                Ref::keyword("OVERLAPS").to_matchable(),
813                Ref::keyword("FETCH").to_matchable(),
814            ])
815            .to_matchable()
816            .into(),
817        ),
818        (
819            "GroupByClauseTerminatorGrammar".into(),
820            one_of(vec![
821                Sequence::new(vec![
822                    Ref::keyword("ORDER").to_matchable(),
823                    Ref::keyword("BY").to_matchable(),
824                ])
825                .to_matchable(),
826                Ref::keyword("LIMIT").to_matchable(),
827                Ref::keyword("HAVING").to_matchable(),
828                Ref::keyword("QUALIFY").to_matchable(),
829                Ref::keyword("WINDOW").to_matchable(),
830                Ref::keyword("FETCH").to_matchable(),
831            ])
832            .to_matchable()
833            .into(),
834        ),
835        (
836            "HavingClauseTerminatorGrammar".into(),
837            one_of(vec![
838                Sequence::new(vec![
839                    Ref::keyword("ORDER").to_matchable(),
840                    Ref::keyword("BY").to_matchable(),
841                ])
842                .to_matchable(),
843                Ref::keyword("LIMIT").to_matchable(),
844                Ref::keyword("QUALIFY").to_matchable(),
845                Ref::keyword("WINDOW").to_matchable(),
846                Ref::keyword("FETCH").to_matchable(),
847            ])
848            .to_matchable()
849            .into(),
850        ),
851        (
852            "OrderByClauseTerminators".into(),
853            one_of(vec![
854                Ref::keyword("LIMIT").to_matchable(),
855                Ref::keyword("HAVING").to_matchable(),
856                Ref::keyword("QUALIFY").to_matchable(),
857                Ref::keyword("WINDOW").to_matchable(),
858                Ref::new("FrameClauseUnitGrammar").to_matchable(),
859                Ref::keyword("SEPARATOR").to_matchable(),
860                Ref::keyword("FETCH").to_matchable(),
861            ])
862            .to_matchable()
863            .into(),
864        ),
865        (
866            "PrimaryKeyGrammar".into(),
867            Sequence::new(vec![
868                Ref::keyword("PRIMARY").to_matchable(),
869                Ref::keyword("KEY").to_matchable(),
870            ])
871            .to_matchable()
872            .into(),
873        ),
874        (
875            "ForeignKeyGrammar".into(),
876            Sequence::new(vec![
877                Ref::keyword("FOREIGN").to_matchable(),
878                Ref::keyword("KEY").to_matchable(),
879            ])
880            .to_matchable()
881            .into(),
882        ),
883        (
884            "UniqueKeyGrammar".into(),
885            Sequence::new(vec![Ref::keyword("UNIQUE").to_matchable()])
886                .to_matchable()
887                .into(),
888        ),
889        // Odd syntax, but prevents eager parameters being confused for data types
890        (
891            "FunctionParameterGrammar".into(),
892            one_of(vec![
893                Sequence::new(vec![
894                    Ref::new("ParameterNameSegment").optional().to_matchable(),
895                    one_of(vec![
896                        Sequence::new(vec![
897                            Ref::keyword("ANY").to_matchable(),
898                            Ref::keyword("TYPE").to_matchable(),
899                        ])
900                        .to_matchable(),
901                        Ref::new("DatatypeSegment").to_matchable(),
902                    ])
903                    .to_matchable(),
904                ])
905                .to_matchable(),
906                one_of(vec![
907                    Sequence::new(vec![
908                        Ref::keyword("ANY").to_matchable(),
909                        Ref::keyword("TYPE").to_matchable(),
910                    ])
911                    .to_matchable(),
912                    Ref::new("DatatypeSegment").to_matchable(),
913                ])
914                .to_matchable(),
915            ])
916            .to_matchable()
917            .into(),
918        ),
919        (
920            "AutoIncrementGrammar".into(),
921            Sequence::new(vec![Ref::keyword("AUTO_INCREMENT").to_matchable()])
922                .to_matchable()
923                .into(),
924        ),
925        // Base Expression element is the right thing to reference for everything
926        // which functions as an expression, but could include literals.
927        (
928            "BaseExpressionElementGrammar".into(),
929            one_of(vec![
930                Ref::new("LiteralGrammar").to_matchable(),
931                Ref::new("BareFunctionSegment").to_matchable(),
932                Ref::new("IntervalExpressionSegment").to_matchable(),
933                Ref::new("FunctionSegment").to_matchable(),
934                Ref::new("ColumnReferenceSegment").to_matchable(),
935                Ref::new("ExpressionSegment").to_matchable(),
936                Sequence::new(vec![
937                    Ref::new("DatatypeSegment").to_matchable(),
938                    Ref::new("LiteralGrammar").to_matchable(),
939                ])
940                .to_matchable(),
941            ])
942            .config(|this| {
943                // These terminators allow better performance by giving a signal
944                // of a likely complete match if they come after a match. For
945                // example "123," only needs to match against the LiteralGrammar
946                // and because a comma follows, never be matched against
947                // ExpressionSegment or FunctionSegment, which are both much
948                // more complicated.
949
950                this.terminators = vec![
951                    Ref::new("CommaSegment").to_matchable(),
952                    Ref::keyword("AS").to_matchable(),
953                ];
954            })
955            .to_matchable()
956            .into(),
957        ),
958        (
959            "FilterClauseGrammar".into(),
960            Sequence::new(vec![
961                Ref::keyword("FILTER").to_matchable(),
962                Bracketed::new(vec![
963                    Sequence::new(vec![
964                        Ref::keyword("WHERE").to_matchable(),
965                        Ref::new("ExpressionSegment").to_matchable(),
966                    ])
967                    .to_matchable(),
968                ])
969                .to_matchable(),
970            ])
971            .to_matchable()
972            .into(),
973        ),
974        (
975            "IgnoreRespectNullsGrammar".into(),
976            Sequence::new(vec![
977                one_of(vec![
978                    Ref::keyword("IGNORE").to_matchable(),
979                    Ref::keyword("RESPECT").to_matchable(),
980                ])
981                .to_matchable(),
982                Ref::keyword("NULLS").to_matchable(),
983            ])
984            .to_matchable()
985            .into(),
986        ),
987        (
988            "FrameClauseUnitGrammar".into(),
989            one_of(vec![
990                Ref::keyword("ROWS").to_matchable(),
991                Ref::keyword("RANGE").to_matchable(),
992            ])
993            .to_matchable()
994            .into(),
995        ),
996        (
997            "JoinTypeKeywordsGrammar".into(),
998            one_of(vec![
999                Ref::keyword("CROSS").to_matchable(),
1000                Ref::keyword("INNER").to_matchable(),
1001                Sequence::new(vec![
1002                    one_of(vec![
1003                        Ref::keyword("FULL").to_matchable(),
1004                        Ref::keyword("LEFT").to_matchable(),
1005                        Ref::keyword("RIGHT").to_matchable(),
1006                    ])
1007                    .to_matchable(),
1008                    Ref::keyword("OUTER").optional().to_matchable(),
1009                ])
1010                .to_matchable(),
1011            ])
1012            .config(|this| this.optional())
1013            .to_matchable()
1014            .into(),
1015        ),
1016        (
1017            // It's as a sequence to allow to parametrize that in Postgres dialect with LATERAL
1018            "JoinKeywordsGrammar".into(),
1019            Sequence::new(vec![Ref::keyword("JOIN").to_matchable()])
1020                .to_matchable()
1021                .into(),
1022        ),
1023        (
1024            // NATURAL joins are not supported in all dialects (e.g. not in Bigquery
1025            // or T-SQL). So define here to allow override with Nothing() for those.
1026            "NaturalJoinKeywordsGrammar".into(),
1027            Sequence::new(vec![
1028                Ref::keyword("NATURAL").to_matchable(),
1029                one_of(vec![
1030                    // Note: NATURAL joins do not support CROSS joins
1031                    Ref::keyword("INNER").to_matchable(),
1032                    Sequence::new(vec![
1033                        one_of(vec![
1034                            Ref::keyword("LEFT").to_matchable(),
1035                            Ref::keyword("RIGHT").to_matchable(),
1036                            Ref::keyword("FULL").to_matchable(),
1037                        ])
1038                        .to_matchable(),
1039                        Ref::keyword("OUTER").optional().to_matchable(),
1040                    ])
1041                    .config(|this| this.optional())
1042                    .to_matchable(),
1043                ])
1044                .config(|this| this.optional())
1045                .to_matchable(),
1046            ])
1047            .to_matchable()
1048            .into(),
1049        ),
1050        // This can be overwritten by dialects
1051        (
1052            "ExtendedNaturalJoinKeywordsGrammar".into(),
1053            Nothing::new().to_matchable().into(),
1054        ),
1055        (
1056            "NestedJoinGrammar".into(),
1057            Nothing::new().to_matchable().into(),
1058        ),
1059        (
1060            "ReferentialActionGrammar".into(),
1061            one_of(vec![
1062                Ref::keyword("RESTRICT").to_matchable(),
1063                Ref::keyword("CASCADE").to_matchable(),
1064                Sequence::new(vec![
1065                    Ref::keyword("SET").to_matchable(),
1066                    Ref::keyword("NULL").to_matchable(),
1067                ])
1068                .to_matchable(),
1069                Sequence::new(vec![
1070                    Ref::keyword("NO").to_matchable(),
1071                    Ref::keyword("ACTION").to_matchable(),
1072                ])
1073                .to_matchable(),
1074                Sequence::new(vec![
1075                    Ref::keyword("SET").to_matchable(),
1076                    Ref::keyword("DEFAULT").to_matchable(),
1077                ])
1078                .to_matchable(),
1079            ])
1080            .to_matchable()
1081            .into(),
1082        ),
1083        (
1084            "DropBehaviorGrammar".into(),
1085            one_of(vec![
1086                Ref::keyword("RESTRICT").to_matchable(),
1087                Ref::keyword("CASCADE").to_matchable(),
1088            ])
1089            .config(|this| this.optional())
1090            .to_matchable()
1091            .into(),
1092        ),
1093        (
1094            "ColumnConstraintDefaultGrammar".into(),
1095            one_of(vec![
1096                Ref::new("ShorthandCastSegment").to_matchable(),
1097                Ref::new("LiteralGrammar").to_matchable(),
1098                Ref::new("FunctionSegment").to_matchable(),
1099                Ref::new("BareFunctionSegment").to_matchable(),
1100            ])
1101            .to_matchable()
1102            .into(),
1103        ),
1104        (
1105            "ReferenceDefinitionGrammar".into(),
1106            Sequence::new(vec![
1107                Ref::keyword("REFERENCES").to_matchable(),
1108                Ref::new("TableReferenceSegment").to_matchable(),
1109                // Foreign columns making up FOREIGN KEY constraint
1110                Ref::new("BracketedColumnReferenceListGrammar")
1111                    .optional()
1112                    .to_matchable(),
1113                Sequence::new(vec![
1114                    Ref::keyword("MATCH").to_matchable(),
1115                    one_of(vec![
1116                        Ref::keyword("FULL").to_matchable(),
1117                        Ref::keyword("PARTIAL").to_matchable(),
1118                        Ref::keyword("SIMPLE").to_matchable(),
1119                    ])
1120                    .to_matchable(),
1121                ])
1122                .config(|this| this.optional())
1123                .to_matchable(),
1124                AnyNumberOf::new(vec![
1125                    // ON DELETE clause, e.g. ON DELETE NO ACTION
1126                    Sequence::new(vec![
1127                        Ref::keyword("ON").to_matchable(),
1128                        Ref::keyword("DELETE").to_matchable(),
1129                        Ref::new("ReferentialActionGrammar").to_matchable(),
1130                    ])
1131                    .to_matchable(),
1132                    Sequence::new(vec![
1133                        Ref::keyword("ON").to_matchable(),
1134                        Ref::keyword("UPDATE").to_matchable(),
1135                        Ref::new("ReferentialActionGrammar").to_matchable(),
1136                    ])
1137                    .to_matchable(),
1138                ])
1139                .to_matchable(),
1140            ])
1141            .to_matchable()
1142            .into(),
1143        ),
1144        (
1145            "TrimParametersGrammar".into(),
1146            one_of(vec![
1147                Ref::keyword("BOTH").to_matchable(),
1148                Ref::keyword("LEADING").to_matchable(),
1149                Ref::keyword("TRAILING").to_matchable(),
1150            ])
1151            .to_matchable()
1152            .into(),
1153        ),
1154        (
1155            "DefaultValuesGrammar".into(),
1156            Sequence::new(vec![
1157                Ref::keyword("DEFAULT").to_matchable(),
1158                Ref::keyword("VALUES").to_matchable(),
1159            ])
1160            .to_matchable()
1161            .into(),
1162        ),
1163        (
1164            "ObjectReferenceDelimiterGrammar".into(),
1165            one_of(vec![
1166                Ref::new("DotSegment").to_matchable(),
1167                // NOTE: The double dot syntax allows for default values.
1168                Sequence::new(vec![
1169                    Ref::new("DotSegment").to_matchable(),
1170                    Ref::new("DotSegment").to_matchable(),
1171                ])
1172                .to_matchable(),
1173            ])
1174            .to_matchable()
1175            .into(),
1176        ),
1177        (
1178            "ObjectReferenceTerminatorGrammar".into(),
1179            one_of(vec![
1180                Ref::keyword("ON").to_matchable(),
1181                Ref::keyword("AS").to_matchable(),
1182                Ref::keyword("USING").to_matchable(),
1183                Ref::new("CommaSegment").to_matchable(),
1184                Ref::new("CastOperatorSegment").to_matchable(),
1185                Ref::new("StartSquareBracketSegment").to_matchable(),
1186                Ref::new("StartBracketSegment").to_matchable(),
1187                Ref::new("BinaryOperatorGrammar").to_matchable(),
1188                Ref::new("ColonSegment").to_matchable(),
1189                Ref::new("DelimiterGrammar").to_matchable(),
1190                Ref::new("JoinLikeClauseGrammar").to_matchable(),
1191                Bracketed::new(vec![]).to_matchable(),
1192            ])
1193            .to_matchable()
1194            .into(),
1195        ),
1196        (
1197            "AlterTableDropColumnGrammar".into(),
1198            Sequence::new(vec![
1199                Ref::keyword("DROP").to_matchable(),
1200                Ref::keyword("COLUMN").optional().to_matchable(),
1201                Ref::new("IfExistsGrammar").optional().to_matchable(),
1202                Ref::new("SingleIdentifierGrammar").to_matchable(),
1203            ])
1204            .to_matchable()
1205            .into(),
1206        ),
1207        (
1208            "AlterTableOptionsGrammar".into(),
1209            one_of(vec![
1210                // Table options
1211                Sequence::new(vec![
1212                    Ref::new("ParameterNameSegment").to_matchable(),
1213                    Ref::new("EqualsSegment").optional().to_matchable(),
1214                    one_of(vec![
1215                        Ref::new("LiteralGrammar").to_matchable(),
1216                        Ref::new("NakedIdentifierSegment").to_matchable(),
1217                    ])
1218                    .to_matchable(),
1219                ])
1220                .to_matchable(),
1221                // Add things
1222                Sequence::new(vec![
1223                    one_of(vec![
1224                        Ref::keyword("ADD").to_matchable(),
1225                        Ref::keyword("MODIFY").to_matchable(),
1226                    ])
1227                    .to_matchable(),
1228                    Ref::keyword("COLUMN").optional().to_matchable(),
1229                    Ref::new("ColumnDefinitionSegment").to_matchable(),
1230                    one_of(vec![
1231                        Sequence::new(vec![
1232                            one_of(vec![
1233                                Ref::keyword("FIRST").to_matchable(),
1234                                Ref::keyword("AFTER").to_matchable(),
1235                                Ref::new("ColumnReferenceSegment").to_matchable(),
1236                                // Bracketed Version of the same
1237                                Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
1238                            ])
1239                            .to_matchable(),
1240                        ])
1241                        .to_matchable(),
1242                    ])
1243                    .config(|this| this.optional())
1244                    .to_matchable(),
1245                ])
1246                .to_matchable(),
1247                // Drop Column
1248                Ref::new("AlterTableDropColumnGrammar").to_matchable(),
1249                // Rename
1250                Sequence::new(vec![
1251                    Ref::keyword("RENAME").to_matchable(),
1252                    one_of(vec![
1253                        Ref::keyword("AS").to_matchable(),
1254                        Ref::keyword("TO").to_matchable(),
1255                    ])
1256                    .config(|this| this.optional())
1257                    .to_matchable(),
1258                    Ref::new("TableReferenceSegment").to_matchable(),
1259                ])
1260                .to_matchable(),
1261            ])
1262            .to_matchable()
1263            .into(),
1264        ),
1265    ]);
1266
1267    ansi_dialect.add([
1268        (
1269            "FileSegment".into(),
1270            NodeMatcher::new(SyntaxKind::File, |_| {
1271                Delimited::new(vec![Ref::new("StatementSegment").to_matchable()])
1272                    .config(|this| {
1273                        this.allow_trailing();
1274                        this.delimiter(
1275                            AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()])
1276                                .config(|config| config.min_times(1)),
1277                        );
1278                    })
1279                    .to_matchable()
1280            })
1281            .to_matchable()
1282            .into(),
1283        ),
1284        (
1285            "ColumnReferenceSegment".into(),
1286            NodeMatcher::new(SyntaxKind::ColumnReference, |_| {
1287                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1288                    .config(|this| this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")))
1289                    .to_matchable()
1290            })
1291            .to_matchable()
1292            .into(),
1293        ),
1294        (
1295            "ExpressionSegment".into(),
1296            NodeMatcher::new(SyntaxKind::Expression, |_| {
1297                Ref::new("Expression_A_Grammar").to_matchable()
1298            })
1299            .to_matchable()
1300            .into(),
1301        ),
1302        (
1303            "WildcardIdentifierSegment".into(),
1304            NodeMatcher::new(SyntaxKind::WildcardIdentifier, |_| {
1305                Sequence::new(vec![
1306                    AnyNumberOf::new(vec![
1307                        Sequence::new(vec![
1308                            Ref::new("SingleIdentifierGrammar").to_matchable(),
1309                            Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(),
1310                        ])
1311                        .to_matchable(),
1312                    ])
1313                    .to_matchable(),
1314                    Ref::new("StarSegment").to_matchable(),
1315                ])
1316                .allow_gaps(false)
1317                .to_matchable()
1318            })
1319            .to_matchable()
1320            .into(),
1321        ),
1322        (
1323            "NamedWindowExpressionSegment".into(),
1324            NodeMatcher::new(SyntaxKind::NamedWindowExpression, |_| {
1325                Sequence::new(vec![
1326                    Ref::new("SingleIdentifierGrammar").to_matchable(),
1327                    Ref::keyword("AS").to_matchable(),
1328                    one_of(vec![
1329                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1330                        Bracketed::new(vec![Ref::new("WindowSpecificationSegment").to_matchable()])
1331                            .config(|this| this.parse_mode(ParseMode::Greedy))
1332                            .to_matchable(),
1333                    ])
1334                    .to_matchable(),
1335                ])
1336                .to_matchable()
1337            })
1338            .to_matchable()
1339            .into(),
1340        ),
1341        (
1342            // DateTimeFunctionContentsSegment(BaseSegment):
1343            //     """Datetime function contents."""
1344            //
1345            //     type = "function_contents"
1346            //
1347            //     match_grammar = Sequence(
1348            //         Bracketed(
1349            //             Delimited(
1350            //                 Ref("DatetimeUnitSegment"),
1351            //                 Ref(
1352            //                     "FunctionContentsGrammar",
1353            //                     # The brackets might be empty for some functions...
1354            //                     optional=True,
1355            //                 ),
1356            //             ),
1357            //         ),
1358            //     )
1359            "DateTimeFunctionContentsSegment".into(),
1360            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
1361                Sequence::new(vec![
1362                    Bracketed::new(vec![
1363                        Delimited::new(vec![
1364                            Ref::new("DatetimeUnitSegment").to_matchable(),
1365                            Ref::new("FunctionContentsGrammar")
1366                                .optional()
1367                                .to_matchable(),
1368                        ])
1369                        .to_matchable(),
1370                    ])
1371                    .to_matchable(),
1372                ])
1373                .to_matchable()
1374            })
1375            .to_matchable()
1376            .into(),
1377        ),
1378        (
1379            "FunctionSegment".into(),
1380            NodeMatcher::new(SyntaxKind::Function, |_| {
1381                one_of(vec![
1382                    Sequence::new(vec![
1383                        Ref::new("DatePartFunctionNameSegment").to_matchable(),
1384                        Ref::new("DateTimeFunctionContentsSegment").to_matchable(),
1385                    ])
1386                    .to_matchable(),
1387                    Sequence::new(vec![
1388                        Sequence::new(vec![
1389                            Ref::new("FunctionNameSegment")
1390                                .exclude(one_of(vec![
1391                                    Ref::new("DatePartFunctionNameSegment").to_matchable(),
1392                                    Ref::new("ValuesClauseSegment").to_matchable(),
1393                                ]))
1394                                .to_matchable(),
1395                            Ref::new("FunctionContentsSegment").to_matchable(),
1396                        ])
1397                        .to_matchable(),
1398                        Ref::new("PostFunctionGrammar").optional().to_matchable(),
1399                    ])
1400                    .to_matchable(),
1401                ])
1402                .to_matchable()
1403            })
1404            .to_matchable()
1405            .into(),
1406        ),
1407        (
1408            "HavingClauseSegment".into(),
1409            NodeMatcher::new(SyntaxKind::HavingClause, |_| {
1410                Sequence::new(vec![
1411                    Ref::keyword("HAVING").to_matchable(),
1412                    MetaSegment::implicit_indent().to_matchable(),
1413                    optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()])
1414                        .to_matchable(),
1415                    MetaSegment::dedent().to_matchable(),
1416                ])
1417                .to_matchable()
1418            })
1419            .to_matchable()
1420            .into(),
1421        ),
1422        (
1423            "PathSegment".into(),
1424            NodeMatcher::new(SyntaxKind::PathSegment, |_| {
1425                one_of(vec![
1426                    Sequence::new(vec![
1427                        Ref::new("SlashSegment").to_matchable(),
1428                        Delimited::new(vec![
1429                            TypedParser::new(SyntaxKind::Word, SyntaxKind::PathSegment)
1430                                .to_matchable(),
1431                        ])
1432                        .config(|this| {
1433                            this.allow_gaps = false;
1434                            this.delimiter(Ref::new("SlashSegment"));
1435                        })
1436                        .to_matchable(),
1437                    ])
1438                    .to_matchable(),
1439                    Ref::new("QuotedLiteralSegment").to_matchable(),
1440                ])
1441                .to_matchable()
1442            })
1443            .to_matchable()
1444            .into(),
1445        ),
1446        (
1447            "LimitClauseSegment".into(),
1448            NodeMatcher::new(SyntaxKind::LimitClause, |_| {
1449                Sequence::new(vec![
1450                    Ref::keyword("LIMIT").to_matchable(),
1451                    MetaSegment::indent().to_matchable(),
1452                    optionally_bracketed(vec![
1453                        one_of(vec![
1454                            Ref::new("NumericLiteralSegment").to_matchable(),
1455                            Ref::new("ExpressionSegment").to_matchable(),
1456                            Ref::keyword("ALL").to_matchable(),
1457                        ])
1458                        .to_matchable(),
1459                    ])
1460                    .to_matchable(),
1461                    one_of(vec![
1462                        Sequence::new(vec![
1463                            Ref::keyword("OFFSET").to_matchable(),
1464                            one_of(vec![
1465                                Ref::new("NumericLiteralSegment").to_matchable(),
1466                                Ref::new("ExpressionSegment").to_matchable(),
1467                            ])
1468                            .to_matchable(),
1469                        ])
1470                        .to_matchable(),
1471                        Sequence::new(vec![
1472                            Ref::new("CommaSegment").to_matchable(),
1473                            Ref::new("NumericLiteralSegment").to_matchable(),
1474                        ])
1475                        .to_matchable(),
1476                    ])
1477                    .config(|this| this.optional())
1478                    .to_matchable(),
1479                    MetaSegment::dedent().to_matchable(),
1480                ])
1481                .to_matchable()
1482            })
1483            .to_matchable()
1484            .into(),
1485        ),
1486        (
1487            "CubeRollupClauseSegment".into(),
1488            NodeMatcher::new(SyntaxKind::CubeRollupClause, |_| {
1489                Sequence::new(vec![
1490                    one_of(vec![
1491                        Ref::new("CubeFunctionNameSegment").to_matchable(),
1492                        Ref::new("RollupFunctionNameSegment").to_matchable(),
1493                    ])
1494                    .to_matchable(),
1495                    Bracketed::new(vec![Ref::new("GroupingExpressionList").to_matchable()])
1496                        .to_matchable(),
1497                ])
1498                .to_matchable()
1499            })
1500            .to_matchable()
1501            .into(),
1502        ),
1503        (
1504            "RollupFunctionNameSegment".into(),
1505            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
1506                StringParser::new("ROLLUP", SyntaxKind::FunctionNameIdentifier).to_matchable()
1507            })
1508            .to_matchable()
1509            .into(),
1510        ),
1511        (
1512            "CubeFunctionNameSegment".into(),
1513            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
1514                StringParser::new("CUBE", SyntaxKind::FunctionNameIdentifier).to_matchable()
1515            })
1516            .to_matchable()
1517            .into(),
1518        ),
1519        (
1520            "GroupingSetsClauseSegment".into(),
1521            NodeMatcher::new(SyntaxKind::GroupingSetsClause, |_| {
1522                Sequence::new(vec![
1523                    Ref::keyword("GROUPING").to_matchable(),
1524                    Ref::keyword("SETS").to_matchable(),
1525                    Bracketed::new(vec![
1526                        Delimited::new(vec![
1527                            Ref::new("CubeRollupClauseSegment").to_matchable(),
1528                            Ref::new("GroupingExpressionList").to_matchable(),
1529                        ])
1530                        .to_matchable(),
1531                    ])
1532                    .to_matchable(),
1533                ])
1534                .to_matchable()
1535            })
1536            .to_matchable()
1537            .into(),
1538        ),
1539        (
1540            "GroupingExpressionList".into(),
1541            NodeMatcher::new(SyntaxKind::GroupingExpressionList, |_| {
1542                Sequence::new(vec![
1543                    MetaSegment::indent().to_matchable(),
1544                    Delimited::new(vec![
1545                        one_of(vec![
1546                            Ref::new("ColumnReferenceSegment").to_matchable(),
1547                            Ref::new("NumericLiteralSegment").to_matchable(),
1548                            Ref::new("ExpressionSegment").to_matchable(),
1549                            Bracketed::new(vec![]).to_matchable(),
1550                        ])
1551                        .to_matchable(),
1552                        Ref::new("GroupByClauseTerminatorGrammar").to_matchable(),
1553                    ])
1554                    .to_matchable(),
1555                    MetaSegment::dedent().to_matchable(),
1556                ])
1557                .to_matchable()
1558            })
1559            .to_matchable()
1560            .into(),
1561        ),
1562        (
1563            "SetClauseSegment".into(),
1564            NodeMatcher::new(SyntaxKind::SetClause, |_| {
1565                Sequence::new(vec![
1566                    Ref::new("ColumnReferenceSegment").to_matchable(),
1567                    Ref::new("EqualsSegment").to_matchable(),
1568                    one_of(vec![
1569                        Ref::new("LiteralGrammar").to_matchable(),
1570                        Ref::new("BareFunctionSegment").to_matchable(),
1571                        Ref::new("FunctionSegment").to_matchable(),
1572                        Ref::new("ColumnReferenceSegment").to_matchable(),
1573                        Ref::new("ExpressionSegment").to_matchable(),
1574                        Ref::new("ValuesClauseSegment").to_matchable(),
1575                        Ref::keyword("DEFAULT").to_matchable(),
1576                    ])
1577                    .to_matchable(),
1578                ])
1579                .to_matchable()
1580            })
1581            .to_matchable()
1582            .into(),
1583        ),
1584        (
1585            "FetchClauseSegment".into(),
1586            NodeMatcher::new(SyntaxKind::FetchClause, |_| {
1587                Sequence::new(vec![
1588                    Ref::keyword("FETCH").to_matchable(),
1589                    one_of(vec![
1590                        Ref::keyword("FIRST").to_matchable(),
1591                        Ref::keyword("NEXT").to_matchable(),
1592                    ])
1593                    .to_matchable(),
1594                    Ref::new("NumericLiteralSegment").optional().to_matchable(),
1595                    one_of(vec![
1596                        Ref::keyword("ROW").to_matchable(),
1597                        Ref::keyword("ROWS").to_matchable(),
1598                    ])
1599                    .to_matchable(),
1600                    Ref::keyword("ONLY").to_matchable(),
1601                ])
1602                .to_matchable()
1603            })
1604            .to_matchable()
1605            .into(),
1606        ),
1607        (
1608            "FunctionDefinitionGrammar".into(),
1609            NodeMatcher::new(SyntaxKind::FunctionDefinition, |_| {
1610                Sequence::new(vec![
1611                    Ref::keyword("AS").to_matchable(),
1612                    Ref::new("QuotedLiteralSegment").to_matchable(),
1613                    Sequence::new(vec![
1614                        Ref::keyword("LANGUAGE").to_matchable(),
1615                        Ref::new("NakedIdentifierSegment").to_matchable(),
1616                    ])
1617                    .config(|this| this.optional())
1618                    .to_matchable(),
1619                ])
1620                .to_matchable()
1621            })
1622            .to_matchable()
1623            .into(),
1624        ),
1625        (
1626            "AlterSequenceOptionsSegment".into(),
1627            NodeMatcher::new(SyntaxKind::AlterSequenceOptionsSegment, |_| {
1628                one_of(vec![
1629                    Sequence::new(vec![
1630                        Ref::keyword("INCREMENT").to_matchable(),
1631                        Ref::keyword("BY").to_matchable(),
1632                        Ref::new("NumericLiteralSegment").to_matchable(),
1633                    ])
1634                    .to_matchable(),
1635                    one_of(vec![
1636                        Sequence::new(vec![
1637                            Ref::keyword("MINVALUE").to_matchable(),
1638                            Ref::new("NumericLiteralSegment").to_matchable(),
1639                        ])
1640                        .to_matchable(),
1641                        Sequence::new(vec![
1642                            Ref::keyword("NO").to_matchable(),
1643                            Ref::keyword("MINVALUE").to_matchable(),
1644                        ])
1645                        .to_matchable(),
1646                    ])
1647                    .to_matchable(),
1648                    one_of(vec![
1649                        Sequence::new(vec![
1650                            Ref::keyword("MAXVALUE").to_matchable(),
1651                            Ref::new("NumericLiteralSegment").to_matchable(),
1652                        ])
1653                        .to_matchable(),
1654                        Sequence::new(vec![
1655                            Ref::keyword("NO").to_matchable(),
1656                            Ref::keyword("MAXVALUE").to_matchable(),
1657                        ])
1658                        .to_matchable(),
1659                    ])
1660                    .to_matchable(),
1661                    one_of(vec![
1662                        Sequence::new(vec![
1663                            Ref::keyword("CACHE").to_matchable(),
1664                            Ref::new("NumericLiteralSegment").to_matchable(),
1665                        ])
1666                        .to_matchable(),
1667                        Ref::keyword("NOCACHE").to_matchable(),
1668                    ])
1669                    .to_matchable(),
1670                    one_of(vec![
1671                        Ref::keyword("CYCLE").to_matchable(),
1672                        Ref::keyword("NOCYCLE").to_matchable(),
1673                    ])
1674                    .to_matchable(),
1675                    one_of(vec![
1676                        Ref::keyword("ORDER").to_matchable(),
1677                        Ref::keyword("NOORDER").to_matchable(),
1678                    ])
1679                    .to_matchable(),
1680                ])
1681                .to_matchable()
1682            })
1683            .to_matchable()
1684            .into(),
1685        ),
1686        (
1687            "RoleReferenceSegment".into(),
1688            NodeMatcher::new(SyntaxKind::RoleReference, |_| {
1689                Ref::new("SingleIdentifierGrammar").to_matchable()
1690            })
1691            .to_matchable()
1692            .into(),
1693        ),
1694        (
1695            "TablespaceReferenceSegment".into(),
1696            NodeMatcher::new(SyntaxKind::TablespaceReference, |_| {
1697                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1698                    .config(|this| {
1699                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
1700                        this.disallow_gaps();
1701                        this.terminators =
1702                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
1703                    })
1704                    .to_matchable()
1705            })
1706            .to_matchable()
1707            .into(),
1708        ),
1709        (
1710            "ExtensionReferenceSegment".into(),
1711            NodeMatcher::new(SyntaxKind::ExtensionReference, |_| {
1712                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1713                    .config(|this| {
1714                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
1715                        this.disallow_gaps();
1716                        this.terminators =
1717                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
1718                    })
1719                    .to_matchable()
1720            })
1721            .to_matchable()
1722            .into(),
1723        ),
1724        (
1725            "TagReferenceSegment".into(),
1726            NodeMatcher::new(SyntaxKind::TagReference, |_| {
1727                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1728                    .config(|this| {
1729                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
1730                        this.disallow_gaps();
1731                        this.terminators =
1732                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
1733                    })
1734                    .to_matchable()
1735            })
1736            .to_matchable()
1737            .into(),
1738        ),
1739        (
1740            "ColumnDefinitionSegment".into(),
1741            NodeMatcher::new(SyntaxKind::ColumnDefinition, |_| {
1742                Sequence::new(vec![
1743                    Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name
1744                    Ref::new("DatatypeSegment").to_matchable(),         // Column type,
1745                    Bracketed::new(vec![Anything::new().to_matchable()])
1746                        .config(|this| this.optional())
1747                        .to_matchable(),
1748                    AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
1749                        .config(|this| this.optional())
1750                        .to_matchable(),
1751                ])
1752                .to_matchable()
1753            })
1754            .to_matchable()
1755            .into(),
1756        ),
1757        (
1758            "ColumnConstraintSegment".into(),
1759            NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_| {
1760                Sequence::new(vec![
1761                    Sequence::new(vec![
1762                        Ref::keyword("CONSTRAINT").to_matchable(),
1763                        Ref::new("ObjectReferenceSegment").to_matchable(),
1764                    ])
1765                    .config(|this| this.optional())
1766                    .to_matchable(),
1767                    one_of(vec![
1768                        Sequence::new(vec![
1769                            Ref::keyword("NOT").optional().to_matchable(),
1770                            Ref::keyword("NULL").to_matchable(),
1771                        ])
1772                        .to_matchable(),
1773                        Sequence::new(vec![
1774                            Ref::keyword("CHECK").to_matchable(),
1775                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
1776                                .to_matchable(),
1777                        ])
1778                        .to_matchable(),
1779                        Sequence::new(vec![
1780                            Ref::keyword("DEFAULT").to_matchable(),
1781                            Ref::new("ColumnConstraintDefaultGrammar").to_matchable(),
1782                        ])
1783                        .to_matchable(),
1784                        Ref::new("PrimaryKeyGrammar").to_matchable(),
1785                        Ref::new("UniqueKeyGrammar").to_matchable(), // UNIQUE
1786                        Ref::new("AutoIncrementGrammar").to_matchable(),
1787                        Ref::new("ReferenceDefinitionGrammar").to_matchable(), /* REFERENCES reftable [ (
1788                                                                                * refcolumn) ] */
1789                        Ref::new("CommentClauseSegment").to_matchable(),
1790                        Sequence::new(vec![
1791                            Ref::keyword("COLLATE").to_matchable(),
1792                            Ref::new("CollationReferenceSegment").to_matchable(),
1793                        ])
1794                        .to_matchable(),
1795                    ])
1796                    .to_matchable(),
1797                ])
1798                .to_matchable()
1799            })
1800            .to_matchable()
1801            .into(),
1802        ),
1803        (
1804            "CommentClauseSegment".into(),
1805            NodeMatcher::new(SyntaxKind::CommentClause, |_| {
1806                Sequence::new(vec![
1807                    Ref::keyword("COMMENT").to_matchable(),
1808                    Ref::new("QuotedLiteralSegment").to_matchable(),
1809                ])
1810                .to_matchable()
1811            })
1812            .to_matchable()
1813            .into(),
1814        ),
1815        (
1816            "TableEndClauseSegment".into(),
1817            NodeMatcher::new(SyntaxKind::TableEndClause, |_| {
1818                Nothing::new().to_matchable()
1819            })
1820            .to_matchable()
1821            .into(),
1822        ),
1823        (
1824            "MergeMatchSegment".into(),
1825            NodeMatcher::new(SyntaxKind::MergeMatch, |_| {
1826                AnyNumberOf::new(vec![
1827                    Ref::new("MergeMatchedClauseSegment").to_matchable(),
1828                    Ref::new("MergeNotMatchedClauseSegment").to_matchable(),
1829                ])
1830                .config(|this| this.min_times(1))
1831                .to_matchable()
1832            })
1833            .to_matchable()
1834            .into(),
1835        ),
1836        (
1837            "MergeMatchedClauseSegment".into(),
1838            NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_| {
1839                Sequence::new(vec![
1840                    Ref::keyword("WHEN").to_matchable(),
1841                    Ref::keyword("MATCHED").to_matchable(),
1842                    Sequence::new(vec![
1843                        Ref::keyword("AND").to_matchable(),
1844                        Ref::new("ExpressionSegment").to_matchable(),
1845                    ])
1846                    .config(|this| this.optional())
1847                    .to_matchable(),
1848                    Ref::keyword("THEN").to_matchable(),
1849                    MetaSegment::indent().to_matchable(),
1850                    one_of(vec![
1851                        Ref::new("MergeUpdateClauseSegment").to_matchable(),
1852                        Ref::new("MergeDeleteClauseSegment").to_matchable(),
1853                    ])
1854                    .to_matchable(),
1855                    MetaSegment::dedent().to_matchable(),
1856                ])
1857                .to_matchable()
1858            })
1859            .to_matchable()
1860            .into(),
1861        ),
1862        (
1863            "MergeNotMatchedClauseSegment".into(),
1864            NodeMatcher::new(SyntaxKind::MergeWhenNotMatchedClause, |_| {
1865                Sequence::new(vec![
1866                    Ref::keyword("WHEN").to_matchable(),
1867                    Ref::keyword("NOT").to_matchable(),
1868                    Ref::keyword("MATCHED").to_matchable(),
1869                    Sequence::new(vec![
1870                        Ref::keyword("AND").to_matchable(),
1871                        Ref::new("ExpressionSegment").to_matchable(),
1872                    ])
1873                    .config(|this| this.optional())
1874                    .to_matchable(),
1875                    Ref::keyword("THEN").to_matchable(),
1876                    MetaSegment::indent().to_matchable(),
1877                    Ref::new("MergeInsertClauseSegment").to_matchable(),
1878                    MetaSegment::dedent().to_matchable(),
1879                ])
1880                .to_matchable()
1881            })
1882            .to_matchable()
1883            .into(),
1884        ),
1885        (
1886            "MergeInsertClauseSegment".into(),
1887            NodeMatcher::new(SyntaxKind::MergeInsertClause, |_| {
1888                Sequence::new(vec![
1889                    Ref::keyword("INSERT").to_matchable(),
1890                    MetaSegment::indent().to_matchable(),
1891                    Ref::new("BracketedColumnReferenceListGrammar")
1892                        .optional()
1893                        .to_matchable(),
1894                    MetaSegment::dedent().to_matchable(),
1895                    Ref::new("ValuesClauseSegment").optional().to_matchable(),
1896                ])
1897                .to_matchable()
1898            })
1899            .to_matchable()
1900            .into(),
1901        ),
1902        (
1903            "MergeUpdateClauseSegment".into(),
1904            NodeMatcher::new(SyntaxKind::MergeUpdateClause, |_| {
1905                Sequence::new(vec![
1906                    Ref::keyword("UPDATE").to_matchable(),
1907                    MetaSegment::indent().to_matchable(),
1908                    Ref::new("SetClauseListSegment").to_matchable(),
1909                    MetaSegment::dedent().to_matchable(),
1910                ])
1911                .to_matchable()
1912            })
1913            .to_matchable()
1914            .into(),
1915        ),
1916        (
1917            "MergeDeleteClauseSegment".into(),
1918            NodeMatcher::new(SyntaxKind::MergeDeleteClause, |_| {
1919                Ref::keyword("DELETE").to_matchable()
1920            })
1921            .to_matchable()
1922            .into(),
1923        ),
1924        (
1925            "SetClauseListSegment".into(),
1926            NodeMatcher::new(SyntaxKind::SetClauseList, |_| {
1927                Sequence::new(vec![
1928                    Ref::keyword("SET").to_matchable(),
1929                    MetaSegment::indent().to_matchable(),
1930                    Ref::new("SetClauseSegment").to_matchable(),
1931                    AnyNumberOf::new(vec![
1932                        Ref::new("CommaSegment").to_matchable(),
1933                        Ref::new("SetClauseSegment").to_matchable(),
1934                    ])
1935                    .to_matchable(),
1936                    MetaSegment::dedent().to_matchable(),
1937                ])
1938                .to_matchable()
1939            })
1940            .to_matchable()
1941            .into(),
1942        ),
1943        (
1944            "TableReferenceSegment".into(),
1945            NodeMatcher::new(SyntaxKind::TableReference, |ansi_dialect| {
1946                ansi_dialect
1947                    .grammar("ObjectReferenceSegment")
1948                    .match_grammar(ansi_dialect)
1949                    .unwrap()
1950                    .clone()
1951            })
1952            .to_matchable()
1953            .into(),
1954        ),
1955        (
1956            "SchemaReferenceSegment".into(),
1957            NodeMatcher::new(SyntaxKind::TableReference, |_| {
1958                Ref::new("ObjectReferenceSegment").to_matchable()
1959            })
1960            .to_matchable()
1961            .into(),
1962        ),
1963        (
1964            "SingleIdentifierListSegment".into(),
1965            NodeMatcher::new(SyntaxKind::IdentifierList, |_| {
1966                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1967                    .config(|this| this.optional())
1968                    .to_matchable()
1969            })
1970            .to_matchable()
1971            .into(),
1972        ),
1973        (
1974            "GroupByClauseSegment".into(),
1975            NodeMatcher::new(SyntaxKind::GroupbyClause, |_| {
1976                Sequence::new(vec![
1977                    Ref::keyword("GROUP").to_matchable(),
1978                    Ref::keyword("BY").to_matchable(),
1979                    one_of(vec![
1980                        Ref::new("CubeRollupClauseSegment").to_matchable(),
1981                        Sequence::new(vec![
1982                            MetaSegment::indent().to_matchable(),
1983                            Delimited::new(vec![
1984                                one_of(vec![
1985                                    Ref::new("ColumnReferenceSegment").to_matchable(),
1986                                    Ref::new("NumericLiteralSegment").to_matchable(),
1987                                    Ref::new("ExpressionSegment").to_matchable(),
1988                                ])
1989                                .to_matchable(),
1990                            ])
1991                            .config(|this| {
1992                                this.terminators =
1993                                    vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()];
1994                            })
1995                            .to_matchable(),
1996                            MetaSegment::dedent().to_matchable(),
1997                        ])
1998                        .to_matchable(),
1999                    ])
2000                    .to_matchable(),
2001                ])
2002                .to_matchable()
2003            })
2004            .to_matchable()
2005            .into(),
2006        ),
2007        (
2008            "FrameClauseSegment".into(),
2009            NodeMatcher::new(SyntaxKind::FrameClause, |_| {
2010                Sequence::new(vec![
2011                    Ref::new("FrameClauseUnitGrammar").to_matchable(),
2012                    one_of(vec![
2013                        frame_extent().to_matchable(),
2014                        Sequence::new(vec![
2015                            Ref::keyword("BETWEEN").to_matchable(),
2016                            frame_extent().to_matchable(),
2017                            Ref::keyword("AND").to_matchable(),
2018                            frame_extent().to_matchable(),
2019                        ])
2020                        .to_matchable(),
2021                    ])
2022                    .to_matchable(),
2023                ])
2024                .to_matchable()
2025            })
2026            .to_matchable()
2027            .into(),
2028        ),
2029        (
2030            "WithCompoundStatementSegment".into(),
2031            NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_| {
2032                Sequence::new(vec![
2033                    Ref::keyword("WITH").to_matchable(),
2034                    Ref::keyword("RECURSIVE").optional().to_matchable(),
2035                    Conditional::new(MetaSegment::indent())
2036                        .indented_ctes()
2037                        .to_matchable(),
2038                    Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()])
2039                        .config(|this| {
2040                            this.terminators = vec![Ref::keyword("SELECT").to_matchable()];
2041                            this.allow_trailing();
2042                        })
2043                        .to_matchable(),
2044                    Conditional::new(MetaSegment::dedent())
2045                        .indented_ctes()
2046                        .to_matchable(),
2047                    Ref::new("NonWithSelectableGrammar").to_matchable(),
2048                ])
2049                .to_matchable()
2050            })
2051            .to_matchable()
2052            .into(),
2053        ),
2054        (
2055            "WithCompoundNonSelectStatementSegment".into(),
2056            NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_| {
2057                Sequence::new(vec![
2058                    Ref::keyword("WITH").to_matchable(),
2059                    Ref::keyword("RECURSIVE").optional().to_matchable(),
2060                    Conditional::new(MetaSegment::indent())
2061                        .indented_ctes()
2062                        .to_matchable(),
2063                    Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()])
2064                        .config(|this| {
2065                            this.terminators = vec![Ref::keyword("SELECT").to_matchable()];
2066                            this.allow_trailing();
2067                        })
2068                        .to_matchable(),
2069                    Conditional::new(MetaSegment::dedent())
2070                        .indented_ctes()
2071                        .to_matchable(),
2072                    Ref::new("NonWithNonSelectableGrammar").to_matchable(),
2073                ])
2074                .to_matchable()
2075            })
2076            .to_matchable()
2077            .into(),
2078        ),
2079        (
2080            "CTEDefinitionSegment".into(),
2081            NodeMatcher::new(SyntaxKind::CommonTableExpression, |_| {
2082                Sequence::new(vec![
2083                    Ref::new("SingleIdentifierGrammar").to_matchable(),
2084                    Ref::new("CTEColumnList").optional().to_matchable(),
2085                    Ref::keyword("AS").optional().to_matchable(),
2086                    Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
2087                        .to_matchable(),
2088                ])
2089                .to_matchable()
2090            })
2091            .to_matchable()
2092            .into(),
2093        ),
2094        (
2095            "CTEColumnList".into(),
2096            NodeMatcher::new(SyntaxKind::CTEColumnList, |_| {
2097                Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()])
2098                    .to_matchable()
2099            })
2100            .to_matchable()
2101            .into(),
2102        ),
2103        (
2104            "SequenceReferenceSegment".into(),
2105            NodeMatcher::new(SyntaxKind::ColumnReference, |_| {
2106                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
2107                    .config(|this| {
2108                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
2109                        this.disallow_gaps();
2110                        this.terminators =
2111                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
2112                    })
2113                    .to_matchable()
2114            })
2115            .to_matchable()
2116            .into(),
2117        ),
2118        (
2119            "TriggerReferenceSegment".into(),
2120            NodeMatcher::new(SyntaxKind::TriggerReference, |_| {
2121                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
2122                    .config(|this| {
2123                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
2124                        this.disallow_gaps();
2125                        this.terminators =
2126                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
2127                    })
2128                    .to_matchable()
2129            })
2130            .to_matchable()
2131            .into(),
2132        ),
2133        (
2134            "TableConstraintSegment".into(),
2135            NodeMatcher::new(SyntaxKind::TableConstraint, |_| {
2136                Sequence::new(vec![
2137                    Sequence::new(vec![
2138                        Ref::keyword("CONSTRAINT").to_matchable(),
2139                        Ref::new("ObjectReferenceSegment").to_matchable(),
2140                    ])
2141                    .config(|this| this.optional())
2142                    .to_matchable(),
2143                    one_of(vec![
2144                        Sequence::new(vec![
2145                            Ref::keyword("UNIQUE").to_matchable(),
2146                            Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
2147                        ])
2148                        .to_matchable(),
2149                        Sequence::new(vec![
2150                            Ref::new("PrimaryKeyGrammar").to_matchable(),
2151                            Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
2152                        ])
2153                        .to_matchable(),
2154                        Sequence::new(vec![
2155                            Ref::new("ForeignKeyGrammar").to_matchable(),
2156                            Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
2157                            Ref::new("ReferenceDefinitionGrammar").to_matchable(),
2158                        ])
2159                        .to_matchable(),
2160                    ])
2161                    .to_matchable(),
2162                ])
2163                .to_matchable()
2164            })
2165            .to_matchable()
2166            .into(),
2167        ),
2168        (
2169            "JoinOnConditionSegment".into(),
2170            NodeMatcher::new(SyntaxKind::JoinOnCondition, |_| {
2171                Sequence::new(vec![
2172                    Ref::keyword("ON").to_matchable(),
2173                    Conditional::new(MetaSegment::implicit_indent())
2174                        .indented_on_contents()
2175                        .to_matchable(),
2176                    optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()])
2177                        .to_matchable(),
2178                    Conditional::new(MetaSegment::dedent())
2179                        .indented_on_contents()
2180                        .to_matchable(),
2181                ])
2182                .to_matchable()
2183            })
2184            .to_matchable()
2185            .into(),
2186        ),
2187        (
2188            "DatabaseReferenceSegment".into(),
2189            NodeMatcher::new(SyntaxKind::DatabaseReference, |_| {
2190                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
2191                    .config(|this| {
2192                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
2193                        this.disallow_gaps();
2194                        this.terminators =
2195                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
2196                    })
2197                    .to_matchable()
2198            })
2199            .to_matchable()
2200            .into(),
2201        ),
2202        (
2203            "IndexReferenceSegment".into(),
2204            NodeMatcher::new(SyntaxKind::DatabaseReference, |_| {
2205                Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
2206                    .config(|this| {
2207                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
2208                        this.disallow_gaps();
2209                        this.terminators =
2210                            vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
2211                    })
2212                    .to_matchable()
2213            })
2214            .to_matchable()
2215            .into(),
2216        ),
2217        (
2218            "CollationReferenceSegment".into(),
2219            NodeMatcher::new(SyntaxKind::CollationReference, |_| {
2220                one_of(vec![
2221                    Ref::new("QuotedLiteralSegment").to_matchable(),
2222                    Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
2223                        .config(|this| {
2224                            this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
2225                            this.terminators =
2226                                vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()];
2227                            this.allow_gaps = false;
2228                        })
2229                        .to_matchable(),
2230                ])
2231                .to_matchable()
2232            })
2233            .to_matchable()
2234            .into(),
2235        ),
2236        (
2237            "OverClauseSegment".into(),
2238            NodeMatcher::new(SyntaxKind::OverClause, |_| {
2239                Sequence::new(vec![
2240                    MetaSegment::indent().to_matchable(),
2241                    Ref::new("IgnoreRespectNullsGrammar")
2242                        .optional()
2243                        .to_matchable(),
2244                    Ref::keyword("OVER").to_matchable(),
2245                    one_of(vec![
2246                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2247                        Bracketed::new(vec![
2248                            Ref::new("WindowSpecificationSegment")
2249                                .optional()
2250                                .to_matchable(),
2251                        ])
2252                        .config(|this| this.parse_mode(ParseMode::Greedy))
2253                        .to_matchable(),
2254                    ])
2255                    .to_matchable(),
2256                    MetaSegment::dedent().to_matchable(),
2257                ])
2258                .to_matchable()
2259            })
2260            .to_matchable()
2261            .into(),
2262        ),
2263        (
2264            "NamedWindowSegment".into(),
2265            NodeMatcher::new(SyntaxKind::NamedWindow, |_| {
2266                Sequence::new(vec![
2267                    Ref::keyword("WINDOW").to_matchable(),
2268                    MetaSegment::indent().to_matchable(),
2269                    Delimited::new(vec![
2270                        Ref::new("NamedWindowExpressionSegment").to_matchable(),
2271                    ])
2272                    .to_matchable(),
2273                    MetaSegment::dedent().to_matchable(),
2274                ])
2275                .to_matchable()
2276            })
2277            .to_matchable()
2278            .into(),
2279        ),
2280        (
2281            "WindowSpecificationSegment".into(),
2282            NodeMatcher::new(SyntaxKind::WindowSpecification, |_| {
2283                Sequence::new(vec![
2284                    Ref::new("SingleIdentifierGrammar")
2285                        .optional()
2286                        .exclude(one_of(vec![
2287                            Ref::keyword("PARTITION").to_matchable(),
2288                            Ref::keyword("ORDER").to_matchable(),
2289                        ]))
2290                        .to_matchable(),
2291                    Ref::new("PartitionClauseSegment").optional().to_matchable(),
2292                    Ref::new("OrderByClauseSegment").optional().to_matchable(),
2293                    Ref::new("FrameClauseSegment").optional().to_matchable(),
2294                ])
2295                .config(|this| this.optional())
2296                .to_matchable()
2297            })
2298            .to_matchable()
2299            .into(),
2300        ),
2301        (
2302            "PartitionClauseSegment".into(),
2303            NodeMatcher::new(SyntaxKind::PartitionbyClause, |_| {
2304                Sequence::new(vec![
2305                    Ref::keyword("PARTITION").to_matchable(),
2306                    Ref::keyword("BY").to_matchable(),
2307                    MetaSegment::indent().to_matchable(),
2308                    optionally_bracketed(vec![
2309                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
2310                            .to_matchable(),
2311                    ])
2312                    .to_matchable(),
2313                    MetaSegment::dedent().to_matchable(),
2314                ])
2315                .to_matchable()
2316            })
2317            .to_matchable()
2318            .into(),
2319        ),
2320        (
2321            "JoinClauseSegment".into(),
2322            NodeMatcher::new(SyntaxKind::JoinClause, |_| {
2323                one_of(vec![
2324                    Sequence::new(vec![
2325                        Ref::new("JoinTypeKeywordsGrammar")
2326                            .optional()
2327                            .to_matchable(),
2328                        Ref::new("JoinKeywordsGrammar").to_matchable(),
2329                        MetaSegment::indent().to_matchable(),
2330                        Ref::new("FromExpressionElementSegment").to_matchable(),
2331                        AnyNumberOf::new(vec![Ref::new("NestedJoinGrammar").to_matchable()])
2332                            .to_matchable(),
2333                        MetaSegment::dedent().to_matchable(),
2334                        Sequence::new(vec![
2335                            Conditional::new(MetaSegment::indent())
2336                                .indented_using_on()
2337                                .to_matchable(),
2338                            one_of(vec![
2339                                Ref::new("JoinOnConditionSegment").to_matchable(),
2340                                Sequence::new(vec![
2341                                    Ref::keyword("USING").to_matchable(),
2342                                    MetaSegment::indent().to_matchable(),
2343                                    Bracketed::new(vec![
2344                                        Delimited::new(vec![
2345                                            Ref::new("SingleIdentifierGrammar").to_matchable(),
2346                                        ])
2347                                        .to_matchable(),
2348                                    ])
2349                                    .config(|this| this.parse_mode = ParseMode::Greedy)
2350                                    .to_matchable(),
2351                                    MetaSegment::dedent().to_matchable(),
2352                                ])
2353                                .to_matchable(),
2354                            ])
2355                            .to_matchable(),
2356                            Conditional::new(MetaSegment::dedent())
2357                                .indented_using_on()
2358                                .to_matchable(),
2359                        ])
2360                        .config(|this| this.optional())
2361                        .to_matchable(),
2362                    ])
2363                    .to_matchable(),
2364                    Sequence::new(vec![
2365                        Ref::new("NaturalJoinKeywordsGrammar").to_matchable(),
2366                        Ref::new("JoinKeywordsGrammar").to_matchable(),
2367                        MetaSegment::indent().to_matchable(),
2368                        Ref::new("FromExpressionElementSegment").to_matchable(),
2369                        MetaSegment::dedent().to_matchable(),
2370                    ])
2371                    .to_matchable(),
2372                    Sequence::new(vec![
2373                        Ref::new("ExtendedNaturalJoinKeywordsGrammar").to_matchable(),
2374                        MetaSegment::indent().to_matchable(),
2375                        Ref::new("FromExpressionElementSegment").to_matchable(),
2376                        MetaSegment::dedent().to_matchable(),
2377                    ])
2378                    .to_matchable(),
2379                ])
2380                .to_matchable()
2381            })
2382            .to_matchable()
2383            .into(),
2384        ),
2385        (
2386            "DropTriggerStatementSegment".into(),
2387            NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_| {
2388                Sequence::new(vec![
2389                    Ref::keyword("DROP").to_matchable(),
2390                    Ref::keyword("TRIGGER").to_matchable(),
2391                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2392                    Ref::new("TriggerReferenceSegment").to_matchable(),
2393                ])
2394                .to_matchable()
2395            })
2396            .to_matchable()
2397            .into(),
2398        ),
2399        (
2400            "SamplingExpressionSegment".into(),
2401            NodeMatcher::new(SyntaxKind::SampleExpression, |_| {
2402                Sequence::new(vec![
2403                    Ref::keyword("TABLESAMPLE").to_matchable(),
2404                    one_of(vec![
2405                        Ref::keyword("BERNOULLI").to_matchable(),
2406                        Ref::keyword("SYSTEM").to_matchable(),
2407                    ])
2408                    .to_matchable(),
2409                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
2410                        .to_matchable(),
2411                    Sequence::new(vec![
2412                        Ref::keyword("REPEATABLE").to_matchable(),
2413                        Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
2414                            .to_matchable(),
2415                    ])
2416                    .config(|this| this.optional())
2417                    .to_matchable(),
2418                ])
2419                .to_matchable()
2420            })
2421            .to_matchable()
2422            .into(),
2423        ),
2424        (
2425            "TableExpressionSegment".into(),
2426            NodeMatcher::new(SyntaxKind::TableExpression, |_| {
2427                one_of(vec![
2428                    Ref::new("ValuesClauseSegment").to_matchable(),
2429                    Ref::new("BareFunctionSegment").to_matchable(),
2430                    Ref::new("FunctionSegment").to_matchable(),
2431                    Ref::new("TableReferenceSegment").to_matchable(),
2432                    Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
2433                        .to_matchable(),
2434                    Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()])
2435                        .to_matchable(),
2436                ])
2437                .to_matchable()
2438            })
2439            .to_matchable()
2440            .into(),
2441        ),
2442        (
2443            "DropTriggerStatementSegment".into(),
2444            NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_| {
2445                Sequence::new(vec![
2446                    Ref::keyword("DROP").to_matchable(),
2447                    Ref::keyword("TRIGGER").to_matchable(),
2448                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2449                    Ref::new("TriggerReferenceSegment").to_matchable(),
2450                ])
2451                .to_matchable()
2452            })
2453            .to_matchable()
2454            .into(),
2455        ),
2456        (
2457            "SamplingExpressionSegment".into(),
2458            NodeMatcher::new(SyntaxKind::SampleExpression, |_| {
2459                Sequence::new(vec![
2460                    Ref::keyword("TABLESAMPLE").to_matchable(),
2461                    one_of(vec![
2462                        Ref::keyword("BERNOULLI").to_matchable(),
2463                        Ref::keyword("SYSTEM").to_matchable(),
2464                    ])
2465                    .to_matchable(),
2466                    Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
2467                        .to_matchable(),
2468                    Sequence::new(vec![
2469                        Ref::keyword("REPEATABLE").to_matchable(),
2470                        Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
2471                            .to_matchable(),
2472                    ])
2473                    .config(|this| this.optional())
2474                    .to_matchable(),
2475                ])
2476                .to_matchable()
2477            })
2478            .to_matchable()
2479            .into(),
2480        ),
2481        (
2482            "TableExpressionSegment".into(),
2483            NodeMatcher::new(SyntaxKind::TableExpression, |_| {
2484                one_of(vec![
2485                    Ref::new("ValuesClauseSegment").to_matchable(),
2486                    Ref::new("BareFunctionSegment").to_matchable(),
2487                    Ref::new("FunctionSegment").to_matchable(),
2488                    Ref::new("TableReferenceSegment").to_matchable(),
2489                    Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
2490                        .to_matchable(),
2491                    Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()])
2492                        .to_matchable(),
2493                ])
2494                .to_matchable()
2495            })
2496            .to_matchable()
2497            .into(),
2498        ),
2499        (
2500            "CreateTriggerStatementSegment".into(),
2501            NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_| {
2502                Sequence::new(vec![
2503                    Ref::keyword("CREATE").to_matchable(),
2504                    Ref::keyword("TRIGGER").to_matchable(),
2505                    Ref::new("TriggerReferenceSegment").to_matchable(),
2506                    one_of(vec![
2507                        Ref::keyword("BEFORE").to_matchable(),
2508                        Ref::keyword("AFTER").to_matchable(),
2509                        Sequence::new(vec![
2510                            Ref::keyword("INSTEAD").to_matchable(),
2511                            Ref::keyword("OF").to_matchable(),
2512                        ])
2513                        .to_matchable(),
2514                    ])
2515                    .config(|this| this.optional())
2516                    .to_matchable(),
2517                    Delimited::new(vec![
2518                        Ref::keyword("INSERT").to_matchable(),
2519                        Ref::keyword("DELETE").to_matchable(),
2520                        Sequence::new(vec![
2521                            Ref::keyword("UPDATE").to_matchable(),
2522                            Ref::keyword("OF").to_matchable(),
2523                            Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()])
2524                                //.with_terminators(vec!["OR", "ON"])
2525                                .to_matchable(),
2526                        ])
2527                        .to_matchable(),
2528                    ])
2529                    .config(|this| {
2530                        this.delimiter(Ref::keyword("OR"));
2531                        // .with_terminators(vec!["ON"]);
2532                    })
2533                    .to_matchable(),
2534                    Ref::keyword("ON").to_matchable(),
2535                    Ref::new("TableReferenceSegment").to_matchable(),
2536                    AnyNumberOf::new(vec![
2537                        Sequence::new(vec![
2538                            Ref::keyword("REFERENCING").to_matchable(),
2539                            Ref::keyword("OLD").to_matchable(),
2540                            Ref::keyword("ROW").to_matchable(),
2541                            Ref::keyword("AS").to_matchable(),
2542                            Ref::new("ParameterNameSegment").to_matchable(),
2543                            Ref::keyword("NEW").to_matchable(),
2544                            Ref::keyword("ROW").to_matchable(),
2545                            Ref::keyword("AS").to_matchable(),
2546                            Ref::new("ParameterNameSegment").to_matchable(),
2547                        ])
2548                        .to_matchable(),
2549                        Sequence::new(vec![
2550                            Ref::keyword("FROM").to_matchable(),
2551                            Ref::new("TableReferenceSegment").to_matchable(),
2552                        ])
2553                        .to_matchable(),
2554                        one_of(vec![
2555                            Sequence::new(vec![
2556                                Ref::keyword("NOT").to_matchable(),
2557                                Ref::keyword("DEFERRABLE").to_matchable(),
2558                            ])
2559                            .to_matchable(),
2560                            Sequence::new(vec![
2561                                Ref::keyword("DEFERRABLE").optional().to_matchable(),
2562                                one_of(vec![
2563                                    Sequence::new(vec![
2564                                        Ref::keyword("INITIALLY").to_matchable(),
2565                                        Ref::keyword("IMMEDIATE").to_matchable(),
2566                                    ])
2567                                    .to_matchable(),
2568                                    Sequence::new(vec![
2569                                        Ref::keyword("INITIALLY").to_matchable(),
2570                                        Ref::keyword("DEFERRED").to_matchable(),
2571                                    ])
2572                                    .to_matchable(),
2573                                ])
2574                                .to_matchable(),
2575                            ])
2576                            .to_matchable(),
2577                        ])
2578                        .to_matchable(),
2579                        Sequence::new(vec![
2580                            Ref::keyword("FOR").to_matchable(),
2581                            Ref::keyword("EACH").optional().to_matchable(),
2582                            one_of(vec![
2583                                Ref::keyword("ROW").to_matchable(),
2584                                Ref::keyword("STATEMENT").to_matchable(),
2585                            ])
2586                            .to_matchable(),
2587                        ])
2588                        .to_matchable(),
2589                        Sequence::new(vec![
2590                            Ref::keyword("WHEN").to_matchable(),
2591                            Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()])
2592                                .to_matchable(),
2593                        ])
2594                        .to_matchable(),
2595                    ])
2596                    .to_matchable(),
2597                    Sequence::new(vec![
2598                        Ref::keyword("EXECUTE").to_matchable(),
2599                        Ref::keyword("PROCEDURE").to_matchable(),
2600                        Ref::new("FunctionNameIdentifierSegment").to_matchable(),
2601                        Ref::new("FunctionContentsSegment").to_matchable(),
2602                    ])
2603                    .config(|this| this.optional())
2604                    .to_matchable(),
2605                ])
2606                .to_matchable()
2607            })
2608            .to_matchable()
2609            .into(),
2610        ),
2611        (
2612            "DropModelStatementSegment".into(),
2613            NodeMatcher::new(SyntaxKind::DropModelStatement, |_| {
2614                Sequence::new(vec![
2615                    Ref::keyword("DROP").to_matchable(),
2616                    Ref::keyword("MODEL").to_matchable(),
2617                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2618                    Ref::new("ObjectReferenceSegment").to_matchable(),
2619                ])
2620                .to_matchable()
2621            })
2622            .to_matchable()
2623            .into(),
2624        ),
2625        (
2626            "DescribeStatementSegment".into(),
2627            NodeMatcher::new(SyntaxKind::DescribeStatement, |_| {
2628                Sequence::new(vec![
2629                    Ref::keyword("DESCRIBE").to_matchable(),
2630                    Ref::new("NakedIdentifierSegment").to_matchable(),
2631                    Ref::new("ObjectReferenceSegment").to_matchable(),
2632                ])
2633                .to_matchable()
2634            })
2635            .to_matchable()
2636            .into(),
2637        ),
2638        (
2639            "UseStatementSegment".into(),
2640            NodeMatcher::new(SyntaxKind::UseStatement, |_| {
2641                Sequence::new(vec![
2642                    Ref::keyword("USE").to_matchable(),
2643                    Ref::new("DatabaseReferenceSegment").to_matchable(),
2644                ])
2645                .to_matchable()
2646            })
2647            .to_matchable()
2648            .into(),
2649        ),
2650        (
2651            "ExplainStatementSegment".into(),
2652            NodeMatcher::new(SyntaxKind::ExplainStatement, |_| {
2653                Sequence::new(vec![
2654                    Ref::keyword("EXPLAIN").to_matchable(),
2655                    one_of(vec![
2656                        Ref::new("SelectableGrammar").to_matchable(),
2657                        Ref::new("InsertStatementSegment").to_matchable(),
2658                        Ref::new("UpdateStatementSegment").to_matchable(),
2659                        Ref::new("DeleteStatementSegment").to_matchable(),
2660                    ])
2661                    .to_matchable(),
2662                ])
2663                .to_matchable()
2664            })
2665            .to_matchable()
2666            .into(),
2667        ),
2668        (
2669            "CreateSequenceStatementSegment".into(),
2670            NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| {
2671                Sequence::new(vec![
2672                    Ref::keyword("CREATE").to_matchable(),
2673                    Ref::keyword("SEQUENCE").to_matchable(),
2674                    Ref::new("SequenceReferenceSegment").to_matchable(),
2675                    AnyNumberOf::new(vec![
2676                        Ref::new("CreateSequenceOptionsSegment").to_matchable(),
2677                    ])
2678                    .config(|this| this.optional())
2679                    .to_matchable(),
2680                ])
2681                .to_matchable()
2682            })
2683            .to_matchable()
2684            .into(),
2685        ),
2686        (
2687            "CreateSequenceOptionsSegment".into(),
2688            NodeMatcher::new(SyntaxKind::CreateSequenceOptionsSegment, |_| {
2689                one_of(vec![
2690                    Sequence::new(vec![
2691                        Ref::keyword("INCREMENT").to_matchable(),
2692                        Ref::keyword("BY").to_matchable(),
2693                        Ref::new("NumericLiteralSegment").to_matchable(),
2694                    ])
2695                    .to_matchable(),
2696                    Sequence::new(vec![
2697                        Ref::keyword("START").to_matchable(),
2698                        Ref::keyword("WITH").optional().to_matchable(),
2699                        Ref::new("NumericLiteralSegment").to_matchable(),
2700                    ])
2701                    .to_matchable(),
2702                    one_of(vec![
2703                        Sequence::new(vec![
2704                            Ref::keyword("MINVALUE").to_matchable(),
2705                            Ref::new("NumericLiteralSegment").to_matchable(),
2706                        ])
2707                        .to_matchable(),
2708                        Sequence::new(vec![
2709                            Ref::keyword("NO").to_matchable(),
2710                            Ref::keyword("MINVALUE").to_matchable(),
2711                        ])
2712                        .to_matchable(),
2713                    ])
2714                    .to_matchable(),
2715                    one_of(vec![
2716                        Sequence::new(vec![
2717                            Ref::keyword("MAXVALUE").to_matchable(),
2718                            Ref::new("NumericLiteralSegment").to_matchable(),
2719                        ])
2720                        .to_matchable(),
2721                        Sequence::new(vec![
2722                            Ref::keyword("NO").to_matchable(),
2723                            Ref::keyword("MAXVALUE").to_matchable(),
2724                        ])
2725                        .to_matchable(),
2726                    ])
2727                    .to_matchable(),
2728                    one_of(vec![
2729                        Sequence::new(vec![
2730                            Ref::keyword("CACHE").to_matchable(),
2731                            Ref::new("NumericLiteralSegment").to_matchable(),
2732                        ])
2733                        .to_matchable(),
2734                        Ref::keyword("NOCACHE").to_matchable(),
2735                    ])
2736                    .to_matchable(),
2737                    one_of(vec![
2738                        Ref::keyword("CYCLE").to_matchable(),
2739                        Ref::keyword("NOCYCLE").to_matchable(),
2740                    ])
2741                    .to_matchable(),
2742                    one_of(vec![
2743                        Ref::keyword("ORDER").to_matchable(),
2744                        Ref::keyword("NOORDER").to_matchable(),
2745                    ])
2746                    .to_matchable(),
2747                ])
2748                .to_matchable()
2749            })
2750            .to_matchable()
2751            .into(),
2752        ),
2753        (
2754            "AlterSequenceStatementSegment".into(),
2755            NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_| {
2756                Sequence::new(vec![
2757                    Ref::keyword("ALTER").to_matchable(),
2758                    Ref::keyword("SEQUENCE").to_matchable(),
2759                    Ref::new("SequenceReferenceSegment").to_matchable(),
2760                    AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()])
2761                        .to_matchable(),
2762                ])
2763                .to_matchable()
2764            })
2765            .to_matchable()
2766            .into(),
2767        ),
2768        (
2769            "DropSequenceStatementSegment".into(),
2770            NodeMatcher::new(SyntaxKind::DropSequenceStatement, |_| {
2771                Sequence::new(vec![
2772                    Ref::keyword("DROP").to_matchable(),
2773                    Ref::keyword("SEQUENCE").to_matchable(),
2774                    Ref::new("SequenceReferenceSegment").to_matchable(),
2775                ])
2776                .to_matchable()
2777            })
2778            .to_matchable()
2779            .into(),
2780        ),
2781        (
2782            "DropCastStatementSegment".into(),
2783            NodeMatcher::new(SyntaxKind::DropCastStatement, |_| {
2784                Sequence::new(vec![
2785                    Ref::keyword("DROP").to_matchable(),
2786                    Ref::keyword("CAST").to_matchable(),
2787                    Bracketed::new(vec![
2788                        Ref::new("DatatypeSegment").to_matchable(),
2789                        Ref::keyword("AS").to_matchable(),
2790                        Ref::new("DatatypeSegment").to_matchable(),
2791                    ])
2792                    .to_matchable(),
2793                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
2794                ])
2795                .to_matchable()
2796            })
2797            .to_matchable()
2798            .into(),
2799        ),
2800        (
2801            "CreateFunctionStatementSegment".into(),
2802            NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_| {
2803                Sequence::new(vec![
2804                    Ref::keyword("CREATE").to_matchable(),
2805                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
2806                    Ref::new("TemporaryGrammar").optional().to_matchable(),
2807                    Ref::keyword("FUNCTION").to_matchable(),
2808                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2809                    Ref::new("FunctionNameSegment").to_matchable(),
2810                    Ref::new("FunctionParameterListGrammar").to_matchable(),
2811                    Sequence::new(vec![
2812                        Ref::keyword("RETURNS").to_matchable(),
2813                        Ref::new("DatatypeSegment").to_matchable(),
2814                    ])
2815                    .config(|this| this.optional())
2816                    .to_matchable(),
2817                    Ref::new("FunctionDefinitionGrammar").to_matchable(),
2818                ])
2819                .to_matchable()
2820            })
2821            .to_matchable()
2822            .into(),
2823        ),
2824        (
2825            "DropFunctionStatementSegment".into(),
2826            NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| {
2827                Sequence::new(vec![
2828                    Ref::keyword("DROP").to_matchable(),
2829                    Ref::keyword("FUNCTION").to_matchable(),
2830                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2831                    Ref::new("FunctionNameSegment").to_matchable(),
2832                ])
2833                .to_matchable()
2834            })
2835            .to_matchable()
2836            .into(),
2837        ),
2838        (
2839            "CreateModelStatementSegment".into(),
2840            NodeMatcher::new(SyntaxKind::CreateModelStatement, |_| {
2841                Sequence::new(vec![
2842                    Ref::keyword("CREATE").to_matchable(),
2843                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
2844                    Ref::keyword("MODEL").to_matchable(),
2845                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2846                    Ref::new("ObjectReferenceSegment").to_matchable(),
2847                    Sequence::new(vec![
2848                        Ref::keyword("OPTIONS").to_matchable(),
2849                        Bracketed::new(vec![
2850                            Delimited::new(vec![
2851                                Sequence::new(vec![
2852                                    Ref::new("ParameterNameSegment").to_matchable(),
2853                                    Ref::new("EqualsSegment").to_matchable(),
2854                                    one_of(vec![
2855                                        Ref::new("LiteralGrammar").to_matchable(), // Single value
2856                                        Bracketed::new(vec![
2857                                            Delimited::new(vec![
2858                                                Ref::new("QuotedLiteralSegment").to_matchable(),
2859                                            ])
2860                                            .to_matchable(),
2861                                        ])
2862                                        .config(|this| {
2863                                            this.bracket_type("square");
2864                                            this.optional();
2865                                        })
2866                                        .to_matchable(),
2867                                    ])
2868                                    .to_matchable(),
2869                                ])
2870                                .to_matchable(),
2871                            ])
2872                            .to_matchable(),
2873                        ])
2874                        .to_matchable(),
2875                    ])
2876                    .config(|this| this.optional())
2877                    .to_matchable(),
2878                    Ref::keyword("AS").to_matchable(),
2879                    Ref::new("SelectableGrammar").to_matchable(),
2880                ])
2881                .to_matchable()
2882            })
2883            .to_matchable()
2884            .into(),
2885        ),
2886        (
2887            "CreateViewStatementSegment".into(),
2888            NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| {
2889                Sequence::new(vec![
2890                    Ref::keyword("CREATE").to_matchable(),
2891                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
2892                    Ref::keyword("VIEW").to_matchable(),
2893                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2894                    Ref::new("TableReferenceSegment").to_matchable(),
2895                    Ref::new("BracketedColumnReferenceListGrammar")
2896                        .optional()
2897                        .to_matchable(),
2898                    Ref::keyword("AS").to_matchable(),
2899                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
2900                        .to_matchable(),
2901                    Ref::new("WithNoSchemaBindingClauseSegment")
2902                        .optional()
2903                        .to_matchable(),
2904                ])
2905                .to_matchable()
2906            })
2907            .to_matchable()
2908            .into(),
2909        ),
2910        (
2911            "DeleteStatementSegment".into(),
2912            NodeMatcher::new(SyntaxKind::DeleteStatement, |_| {
2913                Sequence::new(vec![
2914                    Ref::keyword("DELETE").to_matchable(),
2915                    Ref::new("FromClauseSegment").to_matchable(),
2916                    Ref::new("WhereClauseSegment").optional().to_matchable(),
2917                ])
2918                .to_matchable()
2919            })
2920            .to_matchable()
2921            .into(),
2922        ),
2923        (
2924            "UpdateStatementSegment".into(),
2925            NodeMatcher::new(SyntaxKind::UpdateStatement, |_| {
2926                Sequence::new(vec![
2927                    Ref::keyword("UPDATE").to_matchable(),
2928                    Ref::new("TableReferenceSegment").to_matchable(),
2929                    Ref::new("AliasExpressionSegment")
2930                        .exclude(Ref::keyword("SET"))
2931                        .optional()
2932                        .to_matchable(),
2933                    Ref::new("SetClauseListSegment").to_matchable(),
2934                    Ref::new("FromClauseSegment").optional().to_matchable(),
2935                    Ref::new("WhereClauseSegment").optional().to_matchable(),
2936                ])
2937                .to_matchable()
2938            })
2939            .to_matchable()
2940            .into(),
2941        ),
2942        (
2943            "CreateCastStatementSegment".into(),
2944            NodeMatcher::new(SyntaxKind::CreateCastStatement, |_| {
2945                Sequence::new(vec![
2946                    Ref::keyword("CREATE").to_matchable(),
2947                    Ref::keyword("CAST").to_matchable(),
2948                    Bracketed::new(vec![
2949                        Ref::new("DatatypeSegment").to_matchable(),
2950                        Ref::keyword("AS").to_matchable(),
2951                        Ref::new("DatatypeSegment").to_matchable(),
2952                    ])
2953                    .to_matchable(),
2954                    Ref::keyword("WITH").to_matchable(),
2955                    Ref::keyword("SPECIFIC").optional().to_matchable(),
2956                    one_of(vec![
2957                        Ref::keyword("ROUTINE").to_matchable(),
2958                        Ref::keyword("FUNCTION").to_matchable(),
2959                        Ref::keyword("PROCEDURE").to_matchable(),
2960                        Sequence::new(vec![
2961                            one_of(vec![
2962                                Ref::keyword("INSTANCE").to_matchable(),
2963                                Ref::keyword("STATIC").to_matchable(),
2964                                Ref::keyword("CONSTRUCTOR").to_matchable(),
2965                            ])
2966                            .config(|this| this.optional())
2967                            .to_matchable(),
2968                            Ref::keyword("METHOD").to_matchable(),
2969                        ])
2970                        .to_matchable(),
2971                    ])
2972                    .to_matchable(),
2973                    Ref::new("FunctionNameSegment").to_matchable(),
2974                    Ref::new("FunctionParameterListGrammar")
2975                        .optional()
2976                        .to_matchable(),
2977                    Sequence::new(vec![
2978                        Ref::keyword("FOR").to_matchable(),
2979                        Ref::new("ObjectReferenceSegment").to_matchable(),
2980                    ])
2981                    .config(|this| this.optional())
2982                    .to_matchable(),
2983                    Sequence::new(vec![
2984                        Ref::keyword("AS").to_matchable(),
2985                        Ref::keyword("ASSIGNMENT").to_matchable(),
2986                    ])
2987                    .config(|this| this.optional())
2988                    .to_matchable(),
2989                ])
2990                .to_matchable()
2991            })
2992            .to_matchable()
2993            .into(),
2994        ),
2995        (
2996            "CreateRoleStatementSegment".into(),
2997            NodeMatcher::new(SyntaxKind::CreateRoleStatement, |_| {
2998                Sequence::new(vec![
2999                    Ref::keyword("CREATE").to_matchable(),
3000                    Ref::keyword("ROLE").to_matchable(),
3001                    Ref::new("RoleReferenceSegment").to_matchable(),
3002                ])
3003                .to_matchable()
3004            })
3005            .to_matchable()
3006            .into(),
3007        ),
3008        (
3009            "DropRoleStatementSegment".into(),
3010            NodeMatcher::new(SyntaxKind::DropRoleStatement, |_| {
3011                Sequence::new(vec![
3012                    Ref::keyword("DROP").to_matchable(),
3013                    Ref::keyword("ROLE").to_matchable(),
3014                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3015                    Ref::new("SingleIdentifierGrammar").to_matchable(),
3016                ])
3017                .to_matchable()
3018            })
3019            .to_matchable()
3020            .into(),
3021        ),
3022        (
3023            "AlterTableStatementSegment".into(),
3024            NodeMatcher::new(SyntaxKind::AlterTableStatement, |_| {
3025                Sequence::new(vec![
3026                    Ref::keyword("ALTER").to_matchable(),
3027                    Ref::keyword("TABLE").to_matchable(),
3028                    Ref::new("TableReferenceSegment").to_matchable(),
3029                    Delimited::new(vec![Ref::new("AlterTableOptionsGrammar").to_matchable()])
3030                        .to_matchable(),
3031                ])
3032                .to_matchable()
3033            })
3034            .to_matchable()
3035            .into(),
3036        ),
3037        (
3038            "SetSchemaStatementSegment".into(),
3039            NodeMatcher::new(SyntaxKind::SetSchemaStatement, |_| {
3040                Sequence::new(vec![
3041                    Ref::keyword("SET").to_matchable(),
3042                    Ref::keyword("SCHEMA").to_matchable(),
3043                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3044                    Ref::new("SchemaReferenceSegment").to_matchable(),
3045                ])
3046                .to_matchable()
3047            })
3048            .to_matchable()
3049            .into(),
3050        ),
3051        (
3052            "DropSchemaStatementSegment".into(),
3053            NodeMatcher::new(SyntaxKind::DropSchemaStatement, |_| {
3054                Sequence::new(vec![
3055                    Ref::keyword("DROP").to_matchable(),
3056                    Ref::keyword("SCHEMA").to_matchable(),
3057                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3058                    Ref::new("SchemaReferenceSegment").to_matchable(),
3059                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3060                ])
3061                .to_matchable()
3062            })
3063            .to_matchable()
3064            .into(),
3065        ),
3066        (
3067            "DropTypeStatementSegment".into(),
3068            NodeMatcher::new(SyntaxKind::DropTypeStatement, |_| {
3069                Sequence::new(vec![
3070                    Ref::keyword("DROP").to_matchable(),
3071                    Ref::keyword("TYPE").to_matchable(),
3072                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3073                    Ref::new("ObjectReferenceSegment").to_matchable(),
3074                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3075                ])
3076                .to_matchable()
3077            })
3078            .to_matchable()
3079            .into(),
3080        ),
3081        (
3082            "CreateDatabaseStatementSegment".into(),
3083            NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_| {
3084                Sequence::new(vec![
3085                    Ref::keyword("CREATE").to_matchable(),
3086                    Ref::keyword("DATABASE").to_matchable(),
3087                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3088                    Ref::new("DatabaseReferenceSegment").to_matchable(),
3089                ])
3090                .to_matchable()
3091            })
3092            .to_matchable()
3093            .into(),
3094        ),
3095        (
3096            "DropDatabaseStatementSegment".into(),
3097            NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_| {
3098                Sequence::new(vec![
3099                    Ref::keyword("DROP").to_matchable(),
3100                    Ref::keyword("DATABASE").to_matchable(),
3101                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3102                    Ref::new("DatabaseReferenceSegment").to_matchable(),
3103                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3104                ])
3105                .to_matchable()
3106            })
3107            .to_matchable()
3108            .into(),
3109        ),
3110        (
3111            "FunctionParameterListGrammar".into(),
3112            NodeMatcher::new(SyntaxKind::FunctionParameterList, |_| {
3113                Bracketed::new(vec![
3114                    Delimited::new(vec![Ref::new("FunctionParameterGrammar").to_matchable()])
3115                        .config(|this| this.optional())
3116                        .to_matchable(),
3117                ])
3118                .to_matchable()
3119            })
3120            .to_matchable()
3121            .into(),
3122        ),
3123        (
3124            "CreateIndexStatementSegment".into(),
3125            NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_| {
3126                Sequence::new(vec![
3127                    Ref::keyword("CREATE").to_matchable(),
3128                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
3129                    Ref::keyword("UNIQUE").optional().to_matchable(),
3130                    Ref::keyword("INDEX").to_matchable(),
3131                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3132                    Ref::new("IndexReferenceSegment").to_matchable(),
3133                    Ref::keyword("ON").to_matchable(),
3134                    Ref::new("TableReferenceSegment").to_matchable(),
3135                    Bracketed::new(vec![
3136                        Delimited::new(vec![
3137                            Ref::new("IndexColumnDefinitionSegment").to_matchable(),
3138                        ])
3139                        .to_matchable(),
3140                    ])
3141                    .to_matchable(),
3142                ])
3143                .to_matchable()
3144            })
3145            .to_matchable()
3146            .into(),
3147        ),
3148        (
3149            "DropIndexStatementSegment".into(),
3150            NodeMatcher::new(SyntaxKind::DropIndexStatement, |_| {
3151                Sequence::new(vec![
3152                    Ref::keyword("DROP").to_matchable(),
3153                    Ref::keyword("INDEX").to_matchable(),
3154                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3155                    Ref::new("IndexReferenceSegment").to_matchable(),
3156                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3157                ])
3158                .to_matchable()
3159            })
3160            .to_matchable()
3161            .into(),
3162        ),
3163        (
3164            "CreateTableStatementSegment".into(),
3165            NodeMatcher::new(SyntaxKind::CreateTableStatement, |_| {
3166                Sequence::new(vec![
3167                    Ref::keyword("CREATE").to_matchable(),
3168                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
3169                    Ref::new("TemporaryTransientGrammar")
3170                        .optional()
3171                        .to_matchable(),
3172                    Ref::keyword("TABLE").to_matchable(),
3173                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
3174                    Ref::new("TableReferenceSegment").to_matchable(),
3175                    one_of(vec![
3176                        // Columns and comment syntax
3177                        Sequence::new(vec![
3178                            Bracketed::new(vec![
3179                                Delimited::new(vec![
3180                                    one_of(vec![
3181                                        Ref::new("TableConstraintSegment").to_matchable(),
3182                                        Ref::new("ColumnDefinitionSegment").to_matchable(),
3183                                    ])
3184                                    .to_matchable(),
3185                                ])
3186                                .to_matchable(),
3187                            ])
3188                            .to_matchable(),
3189                            Ref::new("CommentClauseSegment").optional().to_matchable(),
3190                        ])
3191                        .to_matchable(),
3192                        // Create AS syntax:
3193                        Sequence::new(vec![
3194                            Ref::keyword("AS").to_matchable(),
3195                            optionally_bracketed(vec![
3196                                Ref::new("SelectableGrammar").to_matchable(),
3197                            ])
3198                            .to_matchable(),
3199                        ])
3200                        .to_matchable(),
3201                        // Create LIKE syntax
3202                        Sequence::new(vec![
3203                            Ref::keyword("LIKE").to_matchable(),
3204                            Ref::new("TableReferenceSegment").to_matchable(),
3205                        ])
3206                        .to_matchable(),
3207                    ])
3208                    .to_matchable(),
3209                    Ref::new("TableEndClauseSegment").optional().to_matchable(),
3210                ])
3211                .to_matchable()
3212            })
3213            .to_matchable()
3214            .into(),
3215        ),
3216        (
3217            "AccessStatementSegment".into(),
3218            NodeMatcher::new(SyntaxKind::AccessStatement, |_| {
3219                {
3220                    let global_permissions = one_of(vec![
3221                        Sequence::new(vec![
3222                            Ref::keyword("CREATE").to_matchable(),
3223                            one_of(vec![
3224                                Ref::keyword("ROLE").to_matchable(),
3225                                Ref::keyword("USER").to_matchable(),
3226                                Ref::keyword("WAREHOUSE").to_matchable(),
3227                                Ref::keyword("DATABASE").to_matchable(),
3228                                Ref::keyword("INTEGRATION").to_matchable(),
3229                            ])
3230                            .to_matchable(),
3231                        ])
3232                        .to_matchable(),
3233                        Sequence::new(vec![
3234                            Ref::keyword("APPLY").to_matchable(),
3235                            Ref::keyword("MASKING").to_matchable(),
3236                            Ref::keyword("POLICY").to_matchable(),
3237                        ])
3238                        .to_matchable(),
3239                        Sequence::new(vec![
3240                            Ref::keyword("EXECUTE").to_matchable(),
3241                            Ref::keyword("TASK").to_matchable(),
3242                        ])
3243                        .to_matchable(),
3244                        Sequence::new(vec![
3245                            Ref::keyword("MANAGE").to_matchable(),
3246                            Ref::keyword("GRANTS").to_matchable(),
3247                        ])
3248                        .to_matchable(),
3249                        Sequence::new(vec![
3250                            Ref::keyword("MONITOR").to_matchable(),
3251                            one_of(vec![
3252                                Ref::keyword("EXECUTION").to_matchable(),
3253                                Ref::keyword("USAGE").to_matchable(),
3254                            ])
3255                            .to_matchable(),
3256                        ])
3257                        .to_matchable(),
3258                    ]);
3259
3260                    let schema_object_types = one_of(vec![
3261                        Ref::keyword("TABLE").to_matchable(),
3262                        Ref::keyword("VIEW").to_matchable(),
3263                        Ref::keyword("STAGE").to_matchable(),
3264                        Ref::keyword("FUNCTION").to_matchable(),
3265                        Ref::keyword("PROCEDURE").to_matchable(),
3266                        Ref::keyword("ROUTINE").to_matchable(),
3267                        Ref::keyword("SEQUENCE").to_matchable(),
3268                        Ref::keyword("STREAM").to_matchable(),
3269                        Ref::keyword("TASK").to_matchable(),
3270                    ]);
3271
3272                    let permissions = Sequence::new(vec![
3273                        one_of(vec![
3274                            Sequence::new(vec![
3275                                Ref::keyword("CREATE").to_matchable(),
3276                                one_of(vec![
3277                                    Ref::keyword("SCHEMA").to_matchable(),
3278                                    Sequence::new(vec![
3279                                        Ref::keyword("MASKING").to_matchable(),
3280                                        Ref::keyword("POLICY").to_matchable(),
3281                                    ])
3282                                    .to_matchable(),
3283                                    Ref::keyword("PIPE").to_matchable(),
3284                                    schema_object_types.clone().to_matchable(),
3285                                ])
3286                                .to_matchable(),
3287                            ])
3288                            .to_matchable(),
3289                            Sequence::new(vec![
3290                                Ref::keyword("IMPORTED").to_matchable(),
3291                                Ref::keyword("PRIVILEGES").to_matchable(),
3292                            ])
3293                            .to_matchable(),
3294                            Ref::keyword("APPLY").to_matchable(),
3295                            Ref::keyword("CONNECT").to_matchable(),
3296                            Ref::keyword("CREATE").to_matchable(),
3297                            Ref::keyword("DELETE").to_matchable(),
3298                            Ref::keyword("EXECUTE").to_matchable(),
3299                            Ref::keyword("INSERT").to_matchable(),
3300                            Ref::keyword("MODIFY").to_matchable(),
3301                            Ref::keyword("MONITOR").to_matchable(),
3302                            Ref::keyword("OPERATE").to_matchable(),
3303                            Ref::keyword("OWNERSHIP").to_matchable(),
3304                            Ref::keyword("READ").to_matchable(),
3305                            Ref::keyword("REFERENCE_USAGE").to_matchable(),
3306                            Ref::keyword("REFERENCES").to_matchable(),
3307                            Ref::keyword("SELECT").to_matchable(),
3308                            Ref::keyword("TEMP").to_matchable(),
3309                            Ref::keyword("TEMPORARY").to_matchable(),
3310                            Ref::keyword("TRIGGER").to_matchable(),
3311                            Ref::keyword("TRUNCATE").to_matchable(),
3312                            Ref::keyword("UPDATE").to_matchable(),
3313                            Ref::keyword("USAGE").to_matchable(),
3314                            Ref::keyword("USE_ANY_ROLE").to_matchable(),
3315                            Ref::keyword("WRITE").to_matchable(),
3316                            Sequence::new(vec![
3317                                Ref::keyword("ALL").to_matchable(),
3318                                Ref::keyword("PRIVILEGES").optional().to_matchable(),
3319                            ])
3320                            .to_matchable(),
3321                        ])
3322                        .to_matchable(),
3323                        Ref::new("BracketedColumnReferenceListGrammar")
3324                            .optional()
3325                            .to_matchable(),
3326                    ]);
3327
3328                    let objects = one_of(vec![
3329                        Ref::keyword("ACCOUNT").to_matchable(),
3330                        Sequence::new(vec![
3331                            one_of(vec![
3332                                Sequence::new(vec![
3333                                    Ref::keyword("RESOURCE").to_matchable(),
3334                                    Ref::keyword("MONITOR").to_matchable(),
3335                                ])
3336                                .to_matchable(),
3337                                Ref::keyword("WAREHOUSE").to_matchable(),
3338                                Ref::keyword("DATABASE").to_matchable(),
3339                                Ref::keyword("DOMAIN").to_matchable(),
3340                                Ref::keyword("INTEGRATION").to_matchable(),
3341                                Ref::keyword("LANGUAGE").to_matchable(),
3342                                Ref::keyword("SCHEMA").to_matchable(),
3343                                Ref::keyword("ROLE").to_matchable(),
3344                                Ref::keyword("TABLESPACE").to_matchable(),
3345                                Ref::keyword("TYPE").to_matchable(),
3346                                Sequence::new(vec![
3347                                    Ref::keyword("FOREIGN").to_matchable(),
3348                                    one_of(vec![
3349                                        Ref::keyword("SERVER").to_matchable(),
3350                                        Sequence::new(vec![
3351                                            Ref::keyword("DATA").to_matchable(),
3352                                            Ref::keyword("WRAPPER").to_matchable(),
3353                                        ])
3354                                        .to_matchable(),
3355                                    ])
3356                                    .to_matchable(),
3357                                ])
3358                                .to_matchable(),
3359                                Sequence::new(vec![
3360                                    Ref::keyword("ALL").to_matchable(),
3361                                    Ref::keyword("SCHEMAS").to_matchable(),
3362                                    Ref::keyword("IN").to_matchable(),
3363                                    Ref::keyword("DATABASE").to_matchable(),
3364                                ])
3365                                .to_matchable(),
3366                                Sequence::new(vec![
3367                                    Ref::keyword("FUTURE").to_matchable(),
3368                                    Ref::keyword("SCHEMAS").to_matchable(),
3369                                    Ref::keyword("IN").to_matchable(),
3370                                    Ref::keyword("DATABASE").to_matchable(),
3371                                ])
3372                                .to_matchable(),
3373                                schema_object_types.clone().to_matchable(),
3374                                Sequence::new(vec![
3375                                    Ref::keyword("ALL").to_matchable(),
3376                                    one_of(vec![
3377                                        Ref::keyword("TABLES").to_matchable(),
3378                                        Ref::keyword("VIEWS").to_matchable(),
3379                                        Ref::keyword("STAGES").to_matchable(),
3380                                        Ref::keyword("FUNCTIONS").to_matchable(),
3381                                        Ref::keyword("PROCEDURES").to_matchable(),
3382                                        Ref::keyword("ROUTINES").to_matchable(),
3383                                        Ref::keyword("SEQUENCES").to_matchable(),
3384                                        Ref::keyword("STREAMS").to_matchable(),
3385                                        Ref::keyword("TASKS").to_matchable(),
3386                                    ])
3387                                    .to_matchable(),
3388                                    Ref::keyword("IN").to_matchable(),
3389                                    Ref::keyword("SCHEMA").to_matchable(),
3390                                ])
3391                                .to_matchable(),
3392                                Sequence::new(vec![
3393                                    Ref::keyword("FUTURE").to_matchable(),
3394                                    Ref::keyword("IN").to_matchable(),
3395                                    one_of(vec![
3396                                        Ref::keyword("DATABASE").to_matchable(),
3397                                        Ref::keyword("SCHEMA").to_matchable(),
3398                                    ])
3399                                    .to_matchable(),
3400                                ])
3401                                .to_matchable(),
3402                            ])
3403                            .config(|this| this.optional())
3404                            .to_matchable(),
3405                            Delimited::new(vec![
3406                                Ref::new("ObjectReferenceSegment").to_matchable(),
3407                                Sequence::new(vec![
3408                                    Ref::new("FunctionNameSegment").to_matchable(),
3409                                    Ref::new("FunctionParameterListGrammar")
3410                                        .optional()
3411                                        .to_matchable(),
3412                                ])
3413                                .to_matchable(),
3414                            ])
3415                            .config(|this| {
3416                                this.terminators = vec![
3417                                    Ref::keyword("TO").to_matchable(),
3418                                    Ref::keyword("FROM").to_matchable(),
3419                                ]
3420                            })
3421                            .to_matchable(),
3422                        ])
3423                        .to_matchable(),
3424                        Sequence::new(vec![
3425                            Ref::keyword("LARGE").to_matchable(),
3426                            Ref::keyword("OBJECT").to_matchable(),
3427                            Ref::new("NumericLiteralSegment").to_matchable(),
3428                        ])
3429                        .to_matchable(),
3430                    ]);
3431
3432                    one_of(vec![
3433                        Sequence::new(vec![
3434                            Ref::keyword("GRANT").to_matchable(),
3435                            one_of(vec![
3436                                Sequence::new(vec![
3437                                    Delimited::new(vec![
3438                                        one_of(vec![
3439                                            global_permissions.clone().to_matchable(),
3440                                            permissions.clone().to_matchable(),
3441                                        ])
3442                                        .to_matchable(),
3443                                    ])
3444                                    .config(|this| {
3445                                        this.terminators = vec![Ref::keyword("ON").to_matchable()]
3446                                    })
3447                                    .to_matchable(),
3448                                    Ref::keyword("ON").to_matchable(),
3449                                    objects.clone().to_matchable(),
3450                                ])
3451                                .to_matchable(),
3452                                Sequence::new(vec![
3453                                    Ref::keyword("ROLE").to_matchable(),
3454                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3455                                ])
3456                                .to_matchable(),
3457                                Sequence::new(vec![
3458                                    Ref::keyword("OWNERSHIP").to_matchable(),
3459                                    Ref::keyword("ON").to_matchable(),
3460                                    Ref::keyword("USER").to_matchable(),
3461                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3462                                ])
3463                                .to_matchable(),
3464                                Ref::new("ObjectReferenceSegment").to_matchable(),
3465                            ])
3466                            .to_matchable(),
3467                            Ref::keyword("TO").to_matchable(),
3468                            one_of(vec![
3469                                Ref::keyword("GROUP").to_matchable(),
3470                                Ref::keyword("USER").to_matchable(),
3471                                Ref::keyword("ROLE").to_matchable(),
3472                                Ref::keyword("SHARE").to_matchable(),
3473                            ])
3474                            .config(|this| this.optional())
3475                            .to_matchable(),
3476                            Delimited::new(vec![
3477                                one_of(vec![
3478                                    Ref::new("RoleReferenceSegment").to_matchable(),
3479                                    Ref::new("FunctionSegment").to_matchable(),
3480                                    Ref::keyword("PUBLIC").to_matchable(),
3481                                ])
3482                                .to_matchable(),
3483                            ])
3484                            .to_matchable(),
3485                            Ref::new("AccessStatementSegmentGrantRoleWithOptionGrammar")
3486                                .optional()
3487                                .to_matchable(),
3488                            Sequence::new(vec![
3489                                Ref::keyword("GRANTED").to_matchable(),
3490                                Ref::keyword("BY").to_matchable(),
3491                                one_of(vec![
3492                                    Ref::keyword("CURRENT_USER").to_matchable(),
3493                                    Ref::keyword("SESSION_USER").to_matchable(),
3494                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3495                                ])
3496                                .to_matchable(),
3497                            ])
3498                            .config(|this| this.optional())
3499                            .to_matchable(),
3500                        ])
3501                        .to_matchable(),
3502                        Sequence::new(vec![
3503                            Ref::keyword("REVOKE").to_matchable(),
3504                            Sequence::new(vec![
3505                                Ref::keyword("GRANT").to_matchable(),
3506                                Ref::keyword("OPTION").to_matchable(),
3507                                Ref::keyword("FOR").to_matchable(),
3508                            ])
3509                            .config(|this| this.optional())
3510                            .to_matchable(),
3511                            one_of(vec![
3512                                Sequence::new(vec![
3513                                    Delimited::new(vec![
3514                                        one_of(vec![
3515                                            global_permissions.to_matchable(),
3516                                            permissions.to_matchable(),
3517                                        ])
3518                                        .config(|this| {
3519                                            this.terminators =
3520                                                vec![Ref::keyword("ON").to_matchable()]
3521                                        })
3522                                        .to_matchable(),
3523                                    ])
3524                                    .to_matchable(),
3525                                    Ref::keyword("ON").to_matchable(),
3526                                    objects.to_matchable(),
3527                                ])
3528                                .to_matchable(),
3529                                Sequence::new(vec![
3530                                    Ref::keyword("ROLE").to_matchable(),
3531                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3532                                ])
3533                                .to_matchable(),
3534                                Sequence::new(vec![
3535                                    Ref::keyword("OWNERSHIP").to_matchable(),
3536                                    Ref::keyword("ON").to_matchable(),
3537                                    Ref::keyword("USER").to_matchable(),
3538                                    Ref::new("ObjectReferenceSegment").to_matchable(),
3539                                ])
3540                                .to_matchable(),
3541                                Ref::new("ObjectReferenceSegment").to_matchable(),
3542                            ])
3543                            .to_matchable(),
3544                            Ref::keyword("FROM").to_matchable(),
3545                            one_of(vec![
3546                                Ref::keyword("GROUP").to_matchable(),
3547                                Ref::keyword("USER").to_matchable(),
3548                                Ref::keyword("ROLE").to_matchable(),
3549                                Ref::keyword("SHARE").to_matchable(),
3550                            ])
3551                            .config(|this| this.optional())
3552                            .to_matchable(),
3553                            Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()])
3554                                .to_matchable(),
3555                            Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3556                        ])
3557                        .to_matchable(),
3558                    ])
3559                }
3560                .to_matchable()
3561            })
3562            .to_matchable()
3563            .into(),
3564        ),
3565        (
3566            "InsertStatementSegment".into(),
3567            NodeMatcher::new(SyntaxKind::InsertStatement, |_| {
3568                Sequence::new(vec![
3569                    Ref::keyword("INSERT").to_matchable(),
3570                    Ref::keyword("OVERWRITE").optional().to_matchable(),
3571                    Ref::keyword("INTO").to_matchable(),
3572                    Ref::new("TableReferenceSegment").to_matchable(),
3573                    one_of(vec![
3574                        Ref::new("SelectableGrammar").to_matchable(),
3575                        Sequence::new(vec![
3576                            Ref::new("BracketedColumnReferenceListGrammar").to_matchable(),
3577                            Ref::new("SelectableGrammar").to_matchable(),
3578                        ])
3579                        .to_matchable(),
3580                        Ref::new("DefaultValuesGrammar").to_matchable(),
3581                    ])
3582                    .to_matchable(),
3583                ])
3584                .to_matchable()
3585            })
3586            .to_matchable()
3587            .into(),
3588        ),
3589        (
3590            "TransactionStatementSegment".into(),
3591            NodeMatcher::new(SyntaxKind::TransactionStatement, |_| {
3592                Sequence::new(vec![
3593                    one_of(vec![
3594                        Ref::keyword("START").to_matchable(),
3595                        Ref::keyword("BEGIN").to_matchable(),
3596                        Ref::keyword("COMMIT").to_matchable(),
3597                        Ref::keyword("ROLLBACK").to_matchable(),
3598                        Ref::keyword("END").to_matchable(),
3599                    ])
3600                    .to_matchable(),
3601                    one_of(vec![
3602                        Ref::keyword("TRANSACTION").to_matchable(),
3603                        Ref::keyword("WORK").to_matchable(),
3604                    ])
3605                    .config(|this| this.optional())
3606                    .to_matchable(),
3607                    Sequence::new(vec![
3608                        Ref::keyword("NAME").to_matchable(),
3609                        Ref::new("SingleIdentifierGrammar").to_matchable(),
3610                    ])
3611                    .config(|this| this.optional())
3612                    .to_matchable(),
3613                    Sequence::new(vec![
3614                        Ref::keyword("AND").to_matchable(),
3615                        Ref::keyword("NO").optional().to_matchable(),
3616                        Ref::keyword("CHAIN").to_matchable(),
3617                    ])
3618                    .config(|this| this.optional())
3619                    .to_matchable(),
3620                ])
3621                .to_matchable()
3622            })
3623            .to_matchable()
3624            .into(),
3625        ),
3626        (
3627            "DropTableStatementSegment".into(),
3628            NodeMatcher::new(SyntaxKind::DropTableStatement, |_| {
3629                Sequence::new(vec![
3630                    Ref::keyword("DROP").to_matchable(),
3631                    Ref::new("TemporaryGrammar").optional().to_matchable(),
3632                    Ref::keyword("TABLE").to_matchable(),
3633                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3634                    Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()])
3635                        .to_matchable(),
3636                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3637                ])
3638                .to_matchable()
3639            })
3640            .to_matchable()
3641            .into(),
3642        ),
3643        (
3644            "DropViewStatementSegment".into(),
3645            NodeMatcher::new(SyntaxKind::DropViewStatement, |_| {
3646                Sequence::new(vec![
3647                    Ref::keyword("DROP").to_matchable(),
3648                    Ref::keyword("VIEW").to_matchable(),
3649                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3650                    Ref::new("TableReferenceSegment").to_matchable(),
3651                    Ref::new("DropBehaviorGrammar").optional().to_matchable(),
3652                ])
3653                .to_matchable()
3654            })
3655            .to_matchable()
3656            .into(),
3657        ),
3658        (
3659            "CreateUserStatementSegment".into(),
3660            NodeMatcher::new(SyntaxKind::CreateUserStatement, |_| {
3661                Sequence::new(vec![
3662                    Ref::keyword("CREATE").to_matchable(),
3663                    Ref::keyword("USER").to_matchable(),
3664                    Ref::new("RoleReferenceSegment").to_matchable(),
3665                ])
3666                .to_matchable()
3667            })
3668            .to_matchable()
3669            .into(),
3670        ),
3671        (
3672            "DropUserStatementSegment".into(),
3673            NodeMatcher::new(SyntaxKind::DropUserStatement, |_| {
3674                Sequence::new(vec![
3675                    Ref::keyword("DROP").to_matchable(),
3676                    Ref::keyword("USER").to_matchable(),
3677                    Ref::new("IfExistsGrammar").optional().to_matchable(),
3678                    Ref::new("RoleReferenceSegment").to_matchable(),
3679                ])
3680                .to_matchable()
3681            })
3682            .to_matchable()
3683            .into(),
3684        ),
3685        (
3686            "NotEqualToSegment".into(),
3687            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3688                one_of(vec![
3689                    Sequence::new(vec![
3690                        Ref::new("RawNotSegment").to_matchable(),
3691                        Ref::new("RawEqualsSegment").to_matchable(),
3692                    ])
3693                    .allow_gaps(false)
3694                    .to_matchable(),
3695                    Sequence::new(vec![
3696                        Ref::new("RawLessThanSegment").to_matchable(),
3697                        Ref::new("RawGreaterThanSegment").to_matchable(),
3698                    ])
3699                    .allow_gaps(false)
3700                    .to_matchable(),
3701                ])
3702                .to_matchable()
3703            })
3704            .to_matchable()
3705            .into(),
3706        ),
3707        (
3708            "ConcatSegment".into(),
3709            NodeMatcher::new(SyntaxKind::BinaryOperator, |_| {
3710                Sequence::new(vec![
3711                    Ref::new("PipeSegment").to_matchable(),
3712                    Ref::new("PipeSegment").to_matchable(),
3713                ])
3714                .allow_gaps(false)
3715                .to_matchable()
3716            })
3717            .to_matchable()
3718            .into(),
3719        ),
3720        (
3721            "ArrayExpressionSegment".into(),
3722            NodeMatcher::new(SyntaxKind::ArrayExpression, |_| {
3723                Nothing::new().to_matchable()
3724            })
3725            .to_matchable()
3726            .into(),
3727        ),
3728        (
3729            "LocalAliasSegment".into(),
3730            NodeMatcher::new(SyntaxKind::LocalAlias, |_| Nothing::new().to_matchable())
3731                .to_matchable()
3732                .into(),
3733        ),
3734        (
3735            "MergeStatementSegment".into(),
3736            NodeMatcher::new(SyntaxKind::MergeStatement, |_| {
3737                Sequence::new(vec![
3738                    Ref::new("MergeIntoLiteralGrammar").to_matchable(),
3739                    MetaSegment::indent().to_matchable(),
3740                    one_of(vec![
3741                        Ref::new("TableReferenceSegment").to_matchable(),
3742                        Ref::new("AliasedTableReferenceGrammar").to_matchable(),
3743                    ])
3744                    .to_matchable(),
3745                    MetaSegment::dedent().to_matchable(),
3746                    Ref::keyword("USING").to_matchable(),
3747                    MetaSegment::indent().to_matchable(),
3748                    one_of(vec![
3749                        Ref::new("TableReferenceSegment").to_matchable(),
3750                        Ref::new("AliasedTableReferenceGrammar").to_matchable(),
3751                        Sequence::new(vec![
3752                            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
3753                                .to_matchable(),
3754                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
3755                        ])
3756                        .to_matchable(),
3757                    ])
3758                    .to_matchable(),
3759                    MetaSegment::dedent().to_matchable(),
3760                    Conditional::new(MetaSegment::indent())
3761                        .indented_using_on()
3762                        .to_matchable(),
3763                    Ref::new("JoinOnConditionSegment").to_matchable(),
3764                    Conditional::new(MetaSegment::dedent())
3765                        .indented_using_on()
3766                        .to_matchable(),
3767                    Ref::new("MergeMatchSegment").to_matchable(),
3768                ])
3769                .to_matchable()
3770            })
3771            .to_matchable()
3772            .into(),
3773        ),
3774        (
3775            "IndexColumnDefinitionSegment".into(),
3776            NodeMatcher::new(SyntaxKind::IndexColumnDefinition, |_| {
3777                Sequence::new(vec![
3778                    Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name
3779                    one_of(vec![
3780                        Ref::keyword("ASC").to_matchable(),
3781                        Ref::keyword("DESC").to_matchable(),
3782                    ])
3783                    .config(|this| this.optional())
3784                    .to_matchable(),
3785                ])
3786                .to_matchable()
3787            })
3788            .to_matchable()
3789            .into(),
3790        ),
3791        (
3792            "BitwiseAndSegment".into(),
3793            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3794                Ref::new("AmpersandSegment").to_matchable()
3795            })
3796            .to_matchable()
3797            .into(),
3798        ),
3799        (
3800            "BitwiseOrSegment".into(),
3801            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3802                Ref::new("PipeSegment").to_matchable()
3803            })
3804            .to_matchable()
3805            .into(),
3806        ),
3807        (
3808            "BitwiseLShiftSegment".into(),
3809            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3810                Sequence::new(vec![
3811                    Ref::new("RawLessThanSegment").to_matchable(),
3812                    Ref::new("RawLessThanSegment").to_matchable(),
3813                ])
3814                .allow_gaps(false)
3815                .to_matchable()
3816            })
3817            .to_matchable()
3818            .into(),
3819        ),
3820        (
3821            "BitwiseRShiftSegment".into(),
3822            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3823                Sequence::new(vec![
3824                    Ref::new("RawGreaterThanSegment").to_matchable(),
3825                    Ref::new("RawGreaterThanSegment").to_matchable(),
3826                ])
3827                .allow_gaps(false)
3828                .to_matchable()
3829            })
3830            .to_matchable()
3831            .into(),
3832        ),
3833        (
3834            "LessThanSegment".into(),
3835            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3836                Ref::new("RawLessThanSegment").to_matchable()
3837            })
3838            .to_matchable()
3839            .into(),
3840        ),
3841        (
3842            "GreaterThanOrEqualToSegment".into(),
3843            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3844                Sequence::new(vec![
3845                    Ref::new("RawGreaterThanSegment").to_matchable(),
3846                    Ref::new("RawEqualsSegment").to_matchable(),
3847                ])
3848                .allow_gaps(false)
3849                .to_matchable()
3850            })
3851            .to_matchable()
3852            .into(),
3853        ),
3854        (
3855            "LessThanOrEqualToSegment".into(),
3856            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3857                Sequence::new(vec![
3858                    Ref::new("RawLessThanSegment").to_matchable(),
3859                    Ref::new("RawEqualsSegment").to_matchable(),
3860                ])
3861                .allow_gaps(false)
3862                .to_matchable()
3863            })
3864            .to_matchable()
3865            .into(),
3866        ),
3867        (
3868            "EqualsSegment".into(),
3869            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3870                Ref::new("RawEqualsSegment").to_matchable()
3871            })
3872            .to_matchable()
3873            .into(),
3874        ),
3875        (
3876            "GreaterThanSegment".into(),
3877            NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| {
3878                Ref::new("RawGreaterThanSegment").to_matchable()
3879            })
3880            .to_matchable()
3881            .into(),
3882        ),
3883        (
3884            "QualifiedNumericLiteralSegment".into(),
3885            NodeMatcher::new(SyntaxKind::NumericLiteral, |_| {
3886                Sequence::new(vec![
3887                    Ref::new("SignedSegmentGrammar").to_matchable(),
3888                    Ref::new("NumericLiteralSegment").to_matchable(),
3889                ])
3890                .to_matchable()
3891            })
3892            .to_matchable()
3893            .into(),
3894        ),
3895        (
3896            "AggregateOrderByClause".into(),
3897            NodeMatcher::new(SyntaxKind::AggregateOrderByClause, |_| {
3898                Ref::new("OrderByClauseSegment").to_matchable()
3899            })
3900            .to_matchable()
3901            .into(),
3902        ),
3903        (
3904            "FunctionNameSegment".into(),
3905            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
3906                Sequence::new(vec![
3907                    AnyNumberOf::new(vec![
3908                        Sequence::new(vec![
3909                            Ref::new("SingleIdentifierGrammar").to_matchable(),
3910                            Ref::new("DotSegment").to_matchable(),
3911                        ])
3912                        .to_matchable(),
3913                    ])
3914                    .config(|this| {
3915                        this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]
3916                    })
3917                    .to_matchable(),
3918                    one_of(vec![
3919                        Ref::new("FunctionNameIdentifierSegment").to_matchable(),
3920                        Ref::new("QuotedIdentifierSegment").to_matchable(),
3921                    ])
3922                    .to_matchable(),
3923                ])
3924                .terminators(vec![Ref::new("BracketedSegment").to_matchable()])
3925                .allow_gaps(false)
3926                .to_matchable()
3927            })
3928            .to_matchable()
3929            .into(),
3930        ),
3931        (
3932            "CaseExpressionSegment".into(),
3933            NodeMatcher::new(SyntaxKind::CaseExpression, |_| {
3934                one_of(vec![
3935                    Sequence::new(vec![
3936                        Ref::keyword("CASE").to_matchable(),
3937                        MetaSegment::implicit_indent().to_matchable(),
3938                        AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()])
3939                            .config(|this| {
3940                                this.reset_terminators = true;
3941                                this.terminators = vec![
3942                                    Ref::keyword("ELSE").to_matchable(),
3943                                    Ref::keyword("END").to_matchable(),
3944                                ];
3945                            })
3946                            .to_matchable(),
3947                        Ref::new("ElseClauseSegment").optional().to_matchable(),
3948                        MetaSegment::dedent().to_matchable(),
3949                        Ref::keyword("END").to_matchable(),
3950                    ])
3951                    .to_matchable(),
3952                    Sequence::new(vec![
3953                        Ref::keyword("CASE").to_matchable(),
3954                        Ref::new("ExpressionSegment").to_matchable(),
3955                        MetaSegment::implicit_indent().to_matchable(),
3956                        AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()])
3957                            .config(|this| {
3958                                this.reset_terminators = true;
3959                                this.terminators = vec![
3960                                    Ref::keyword("ELSE").to_matchable(),
3961                                    Ref::keyword("END").to_matchable(),
3962                                ];
3963                            })
3964                            .to_matchable(),
3965                        Ref::new("ElseClauseSegment").optional().to_matchable(),
3966                        MetaSegment::dedent().to_matchable(),
3967                        Ref::keyword("END").to_matchable(),
3968                    ])
3969                    .to_matchable(),
3970                ])
3971                .config(|this| {
3972                    this.terminators = vec![
3973                        Ref::new("ComparisonOperatorGrammar").to_matchable(),
3974                        Ref::new("CommaSegment").to_matchable(),
3975                        Ref::new("BinaryOperatorGrammar").to_matchable(),
3976                    ]
3977                })
3978                .to_matchable()
3979            })
3980            .to_matchable()
3981            .into(),
3982        ),
3983        (
3984            "WhenClauseSegment".into(),
3985            NodeMatcher::new(SyntaxKind::WhenClause, |_| {
3986                Sequence::new(vec![
3987                    Ref::keyword("WHEN").to_matchable(),
3988                    Sequence::new(vec![
3989                        MetaSegment::implicit_indent().to_matchable(),
3990                        Ref::new("ExpressionSegment").to_matchable(),
3991                        MetaSegment::dedent().to_matchable(),
3992                    ])
3993                    .to_matchable(),
3994                    Conditional::new(MetaSegment::indent())
3995                        .indented_then()
3996                        .to_matchable(),
3997                    Ref::keyword("THEN").to_matchable(),
3998                    Conditional::new(MetaSegment::implicit_indent())
3999                        .indented_then_contents()
4000                        .to_matchable(),
4001                    Ref::new("ExpressionSegment").to_matchable(),
4002                    Conditional::new(MetaSegment::dedent())
4003                        .indented_then_contents()
4004                        .to_matchable(),
4005                    Conditional::new(MetaSegment::dedent())
4006                        .indented_then()
4007                        .to_matchable(),
4008                ])
4009                .to_matchable()
4010            })
4011            .to_matchable()
4012            .into(),
4013        ),
4014        (
4015            "ElseClauseSegment".into(),
4016            NodeMatcher::new(SyntaxKind::ElseClause, |_| {
4017                Sequence::new(vec![
4018                    Ref::keyword("ELSE").to_matchable(),
4019                    MetaSegment::implicit_indent().to_matchable(),
4020                    Ref::new("ExpressionSegment").to_matchable(),
4021                    MetaSegment::dedent().to_matchable(),
4022                ])
4023                .to_matchable()
4024            })
4025            .to_matchable()
4026            .into(),
4027        ),
4028        (
4029            "WhereClauseSegment".into(),
4030            NodeMatcher::new(SyntaxKind::WhereClause, |_| {
4031                Sequence::new(vec![
4032                    Ref::keyword("WHERE").to_matchable(),
4033                    MetaSegment::implicit_indent().to_matchable(),
4034                    optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()])
4035                        .to_matchable(),
4036                    MetaSegment::dedent().to_matchable(),
4037                ])
4038                .to_matchable()
4039            })
4040            .to_matchable()
4041            .into(),
4042        ),
4043        (
4044            "SetOperatorSegment".into(),
4045            NodeMatcher::new(SyntaxKind::SetOperator, |_| {
4046                one_of(vec![
4047                    Ref::new("UnionGrammar").to_matchable(),
4048                    Sequence::new(vec![
4049                        one_of(vec![
4050                            Ref::keyword("INTERSECT").to_matchable(),
4051                            Ref::keyword("EXCEPT").to_matchable(),
4052                        ])
4053                        .to_matchable(),
4054                        Ref::keyword("ALL").optional().to_matchable(),
4055                    ])
4056                    .to_matchable(),
4057                    Ref::keyword("MINUS").to_matchable(),
4058                ])
4059                .to_matchable()
4060            })
4061            .to_matchable()
4062            .into(),
4063        ),
4064        (
4065            "ValuesClauseSegment".into(),
4066            NodeMatcher::new(SyntaxKind::ValuesClause, |_| {
4067                Sequence::new(vec![
4068                    one_of(vec![
4069                        Ref::keyword("VALUE").to_matchable(),
4070                        Ref::keyword("VALUES").to_matchable(),
4071                    ])
4072                    .to_matchable(),
4073                    Delimited::new(vec![
4074                        Sequence::new(vec![
4075                            Ref::keyword("ROW").optional().to_matchable(),
4076                            Bracketed::new(vec![
4077                                Delimited::new(vec![
4078                                    Ref::keyword("DEFAULT").to_matchable(),
4079                                    Ref::new("LiteralGrammar").to_matchable(),
4080                                    Ref::new("ExpressionSegment").to_matchable(),
4081                                ])
4082                                .to_matchable(),
4083                            ])
4084                            .config(|this| this.parse_mode(ParseMode::Greedy))
4085                            .to_matchable(),
4086                        ])
4087                        .to_matchable(),
4088                    ])
4089                    .to_matchable(),
4090                ])
4091                .to_matchable()
4092            })
4093            .to_matchable()
4094            .into(),
4095        ),
4096        (
4097            "EmptyStructLiteralSegment".into(),
4098            NodeMatcher::new(SyntaxKind::EmptyStructLiteral, |_| {
4099                Sequence::new(vec![
4100                    Ref::new("StructTypeSegment").to_matchable(),
4101                    Ref::new("EmptyStructLiteralBracketsSegment").to_matchable(),
4102                ])
4103                .to_matchable()
4104            })
4105            .to_matchable()
4106            .into(),
4107        ),
4108        (
4109            "ObjectLiteralSegment".into(),
4110            NodeMatcher::new(SyntaxKind::ObjectLiteral, |_| {
4111                Bracketed::new(vec![
4112                    Delimited::new(vec![Ref::new("ObjectLiteralElementSegment").to_matchable()])
4113                        .config(|this| {
4114                            this.optional();
4115                        })
4116                        .to_matchable(),
4117                ])
4118                .config(|this| {
4119                    this.bracket_type("curly");
4120                })
4121                .to_matchable()
4122            })
4123            .to_matchable()
4124            .into(),
4125        ),
4126        (
4127            "ObjectLiteralElementSegment".into(),
4128            NodeMatcher::new(SyntaxKind::ObjectLiteralElement, |_| {
4129                Sequence::new(vec![
4130                    Ref::new("QuotedLiteralSegment").to_matchable(),
4131                    Ref::new("ColonSegment").to_matchable(),
4132                    Ref::new("BaseExpressionElementGrammar").to_matchable(),
4133                ])
4134                .to_matchable()
4135            })
4136            .to_matchable()
4137            .into(),
4138        ),
4139        (
4140            "TimeZoneGrammar".into(),
4141            NodeMatcher::new(SyntaxKind::TimeZoneGrammar, |_| {
4142                AnyNumberOf::new(vec![
4143                    Sequence::new(vec![
4144                        Ref::keyword("AT").to_matchable(),
4145                        Ref::keyword("TIME").to_matchable(),
4146                        Ref::keyword("ZONE").to_matchable(),
4147                        Ref::new("ExpressionSegment").to_matchable(),
4148                    ])
4149                    .to_matchable(),
4150                ])
4151                .to_matchable()
4152            })
4153            .to_matchable()
4154            .into(),
4155        ),
4156        (
4157            "BracketedArguments".into(),
4158            NodeMatcher::new(SyntaxKind::BracketedArguments, |_| {
4159                Bracketed::new(vec![
4160                    Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()])
4161                        .config(|this| {
4162                            this.optional();
4163                        })
4164                        .to_matchable(),
4165                ])
4166                .to_matchable()
4167            })
4168            .to_matchable()
4169            .into(),
4170        ),
4171        (
4172            "DatatypeSegment".into(),
4173            NodeMatcher::new(SyntaxKind::DataType, |_| {
4174                one_of(vec![
4175                    Ref::new("TimeWithTZGrammar").to_matchable(),
4176                    Sequence::new(vec![
4177                        Ref::keyword("DOUBLE").to_matchable(),
4178                        Ref::keyword("PRECISION").to_matchable(),
4179                    ])
4180                    .to_matchable(),
4181                    Sequence::new(vec![
4182                        one_of(vec![
4183                            Sequence::new(vec![
4184                                one_of(vec![
4185                                    Ref::keyword("CHARACTER").to_matchable(),
4186                                    Ref::keyword("BINARY").to_matchable(),
4187                                ])
4188                                .to_matchable(),
4189                                one_of(vec![
4190                                    Ref::keyword("VARYING").to_matchable(),
4191                                    Sequence::new(vec![
4192                                        Ref::keyword("LARGE").to_matchable(),
4193                                        Ref::keyword("OBJECT").to_matchable(),
4194                                    ])
4195                                    .to_matchable(),
4196                                ])
4197                                .to_matchable(),
4198                            ])
4199                            .to_matchable(),
4200                            Sequence::new(vec![
4201                                Sequence::new(vec![
4202                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
4203                                    Ref::new("DotSegment").to_matchable(),
4204                                ])
4205                                .config(|this| this.optional())
4206                                .to_matchable(),
4207                                Ref::new("DatatypeIdentifierSegment").to_matchable(),
4208                            ])
4209                            .to_matchable(),
4210                        ])
4211                        .to_matchable(),
4212                        Ref::new("BracketedArguments").optional().to_matchable(),
4213                        one_of(vec![
4214                            Ref::keyword("UNSIGNED").to_matchable(),
4215                            Ref::new("CharCharacterSetGrammar").to_matchable(),
4216                        ])
4217                        .config(|config| config.optional())
4218                        .to_matchable(),
4219                    ])
4220                    .to_matchable(),
4221                ])
4222                .to_matchable()
4223            })
4224            .to_matchable()
4225            .into(),
4226        ),
4227        (
4228            "AliasExpressionSegment".into(),
4229            NodeMatcher::new(SyntaxKind::AliasExpression, |_| {
4230                Sequence::new(vec![
4231                    MetaSegment::indent().to_matchable(),
4232                    Ref::keyword("AS").optional().to_matchable(),
4233                    one_of(vec![
4234                        Sequence::new(vec![
4235                            Ref::new("SingleIdentifierGrammar").to_matchable(),
4236                            Bracketed::new(vec![
4237                                Ref::new("SingleIdentifierListSegment").to_matchable(),
4238                            ])
4239                            .config(|this| this.optional())
4240                            .to_matchable(),
4241                        ])
4242                        .to_matchable(),
4243                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
4244                    ])
4245                    .to_matchable(),
4246                    MetaSegment::dedent().to_matchable(),
4247                ])
4248                .to_matchable()
4249            })
4250            .to_matchable()
4251            .into(),
4252        ),
4253        (
4254            "ShorthandCastSegment".into(),
4255            NodeMatcher::new(SyntaxKind::CastExpression, |_| {
4256                Sequence::new(vec![
4257                    one_of(vec![
4258                        Ref::new("Expression_D_Grammar").to_matchable(),
4259                        Ref::new("CaseExpressionSegment").to_matchable(),
4260                    ])
4261                    .to_matchable(),
4262                    AnyNumberOf::new(vec![
4263                        Sequence::new(vec![
4264                            Ref::new("CastOperatorSegment").to_matchable(),
4265                            Ref::new("DatatypeSegment").to_matchable(),
4266                            Ref::new("TimeZoneGrammar").optional().to_matchable(),
4267                        ])
4268                        .to_matchable(),
4269                    ])
4270                    .config(|this| this.min_times(1))
4271                    .to_matchable(),
4272                ])
4273                .to_matchable()
4274            })
4275            .to_matchable()
4276            .into(),
4277        ),
4278        (
4279            "ArrayAccessorSegment".into(),
4280            NodeMatcher::new(SyntaxKind::ArrayAccessor, |_| {
4281                Bracketed::new(vec![
4282                    Delimited::new(vec![
4283                        one_of(vec![
4284                            Ref::new("NumericLiteralSegment").to_matchable(),
4285                            Ref::new("ExpressionSegment").to_matchable(),
4286                        ])
4287                        .to_matchable(),
4288                    ])
4289                    .config(|this| this.delimiter(Ref::new("SliceSegment")))
4290                    .to_matchable(),
4291                ])
4292                .config(|this| {
4293                    this.bracket_type("square");
4294                    this.parse_mode(ParseMode::Greedy);
4295                })
4296                .to_matchable()
4297            })
4298            .to_matchable()
4299            .into(),
4300        ),
4301        (
4302            "ArrayLiteralSegment".into(),
4303            NodeMatcher::new(SyntaxKind::ArrayLiteral, |_| {
4304                Bracketed::new(vec![
4305                    Delimited::new(vec![
4306                        Ref::new("BaseExpressionElementGrammar").to_matchable(),
4307                    ])
4308                    .config(|this| {
4309                        this.delimiter(Ref::new("CommaSegment"));
4310                        this.optional();
4311                    })
4312                    .to_matchable(),
4313                ])
4314                .config(|this| {
4315                    this.bracket_type("square");
4316                    this.parse_mode(ParseMode::Greedy);
4317                })
4318                .to_matchable()
4319            })
4320            .to_matchable()
4321            .into(),
4322        ),
4323        (
4324            "TypedArrayLiteralSegment".into(),
4325            NodeMatcher::new(SyntaxKind::TypedArrayLiteral, |_| {
4326                Sequence::new(vec![
4327                    Ref::new("ArrayTypeSegment").to_matchable(),
4328                    Ref::new("ArrayLiteralSegment").to_matchable(),
4329                ])
4330                .to_matchable()
4331            })
4332            .to_matchable()
4333            .into(),
4334        ),
4335        (
4336            "StructTypeSegment".into(),
4337            NodeMatcher::new(SyntaxKind::StructType, |_| Nothing::new().to_matchable())
4338                .to_matchable()
4339                .into(),
4340        ),
4341        (
4342            "StructLiteralSegment".into(),
4343            NodeMatcher::new(SyntaxKind::StructLiteral, |_| {
4344                Bracketed::new(vec![
4345                    Delimited::new(vec![
4346                        Sequence::new(vec![
4347                            Ref::new("BaseExpressionElementGrammar").to_matchable(),
4348                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
4349                        ])
4350                        .to_matchable(),
4351                    ])
4352                    .to_matchable(),
4353                ])
4354                .to_matchable()
4355            })
4356            .to_matchable()
4357            .into(),
4358        ),
4359        (
4360            "TypedStructLiteralSegment".into(),
4361            NodeMatcher::new(SyntaxKind::TypedStructLiteral, |_| {
4362                Sequence::new(vec![
4363                    Ref::new("StructTypeSegment").to_matchable(),
4364                    Ref::new("StructLiteralSegment").to_matchable(),
4365                ])
4366                .to_matchable()
4367            })
4368            .to_matchable()
4369            .into(),
4370        ),
4371        (
4372            "IntervalExpressionSegment".into(),
4373            NodeMatcher::new(SyntaxKind::IntervalExpression, |_| {
4374                Sequence::new(vec![
4375                    Ref::keyword("INTERVAL").to_matchable(),
4376                    one_of(vec![
4377                        Sequence::new(vec![
4378                            Ref::new("NumericLiteralSegment").to_matchable(),
4379                            one_of(vec![
4380                                Ref::new("QuotedLiteralSegment").to_matchable(),
4381                                Ref::new("DatetimeUnitSegment").to_matchable(),
4382                            ])
4383                            .to_matchable(),
4384                        ])
4385                        .to_matchable(),
4386                        Ref::new("QuotedLiteralSegment").to_matchable(),
4387                    ])
4388                    .to_matchable(),
4389                ])
4390                .to_matchable()
4391            })
4392            .to_matchable()
4393            .into(),
4394        ),
4395        (
4396            "ArrayTypeSegment".into(),
4397            NodeMatcher::new(SyntaxKind::ArrayType, |_| Nothing::new().to_matchable())
4398                .to_matchable()
4399                .into(),
4400        ),
4401        (
4402            "SizedArrayTypeSegment".into(),
4403            NodeMatcher::new(SyntaxKind::SizedArrayType, |_| {
4404                Sequence::new(vec![
4405                    Ref::new("ArrayTypeSegment").to_matchable(),
4406                    Ref::new("ArrayAccessorSegment").to_matchable(),
4407                ])
4408                .to_matchable()
4409            })
4410            .to_matchable()
4411            .into(),
4412        ),
4413        (
4414            "UnorderedSelectStatementSegment".into(),
4415            NodeMatcher::new(SyntaxKind::SelectStatement, |_| {
4416                Sequence::new(vec![
4417                    Ref::new("SelectClauseSegment").to_matchable(),
4418                    MetaSegment::dedent().to_matchable(),
4419                    Ref::new("FromClauseSegment").optional().to_matchable(),
4420                    Ref::new("WhereClauseSegment").optional().to_matchable(),
4421                    Ref::new("GroupByClauseSegment").optional().to_matchable(),
4422                    Ref::new("HavingClauseSegment").optional().to_matchable(),
4423                    Ref::new("OverlapsClauseSegment").optional().to_matchable(),
4424                    Ref::new("NamedWindowSegment").optional().to_matchable(),
4425                ])
4426                .terminators(vec![
4427                    Ref::new("SetOperatorSegment").to_matchable(),
4428                    Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
4429                    Ref::new("WithDataClauseSegment").to_matchable(),
4430                    Ref::new("OrderByClauseSegment").to_matchable(),
4431                    Ref::new("LimitClauseSegment").to_matchable(),
4432                ])
4433                .config(|this| {
4434                    this.parse_mode(ParseMode::GreedyOnceStarted);
4435                })
4436                .to_matchable()
4437            })
4438            .to_matchable()
4439            .into(),
4440        ),
4441        (
4442            "OverlapsClauseSegment".into(),
4443            NodeMatcher::new(SyntaxKind::OverlapsClause, |_| {
4444                Sequence::new(vec![
4445                    Ref::keyword("OVERLAPS").to_matchable(),
4446                    one_of(vec![
4447                        Bracketed::new(vec![
4448                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
4449                            Ref::new("CommaSegment").to_matchable(),
4450                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
4451                        ])
4452                        .to_matchable(),
4453                        Ref::new("ColumnReferenceSegment").to_matchable(),
4454                    ])
4455                    .to_matchable(),
4456                ])
4457                .to_matchable()
4458            })
4459            .to_matchable()
4460            .into(),
4461        ),
4462        ("SelectClauseSegment".into(), {
4463            NodeMatcher::new(SyntaxKind::SelectClause, |_| select_clause_segment())
4464                .to_matchable()
4465                .into()
4466        }),
4467        (
4468            "StatementSegment".into(),
4469            NodeMatcher::new(SyntaxKind::Statement, |_| statement_segment())
4470                .to_matchable()
4471                .into(),
4472        ),
4473        (
4474            "WithNoSchemaBindingClauseSegment".into(),
4475            NodeMatcher::new(SyntaxKind::WithNoSchemaBindingClause, |_| {
4476                Sequence::new(vec![
4477                    Ref::keyword("WITH").to_matchable(),
4478                    Ref::keyword("NO").to_matchable(),
4479                    Ref::keyword("SCHEMA").to_matchable(),
4480                    Ref::keyword("BINDING").to_matchable(),
4481                ])
4482                .to_matchable()
4483            })
4484            .to_matchable()
4485            .into(),
4486        ),
4487        (
4488            "WithDataClauseSegment".into(),
4489            NodeMatcher::new(SyntaxKind::WithDataClause, |_| {
4490                Sequence::new(vec![
4491                    Ref::keyword("WITH").to_matchable(),
4492                    Sequence::new(vec![Ref::keyword("NO").to_matchable()])
4493                        .config(|this| this.optional())
4494                        .to_matchable(),
4495                    Ref::keyword("DATA").to_matchable(),
4496                ])
4497                .to_matchable()
4498            })
4499            .to_matchable()
4500            .into(),
4501        ),
4502        (
4503            "SetExpressionSegment".into(),
4504            NodeMatcher::new(SyntaxKind::SetExpression, |_| {
4505                Sequence::new(vec![
4506                    Ref::new("NonSetSelectableGrammar").to_matchable(),
4507                    AnyNumberOf::new(vec![
4508                        Sequence::new(vec![
4509                            Ref::new("SetOperatorSegment").to_matchable(),
4510                            Ref::new("NonSetSelectableGrammar").to_matchable(),
4511                        ])
4512                        .to_matchable(),
4513                    ])
4514                    .config(|this| this.min_times(1))
4515                    .to_matchable(),
4516                    Ref::new("OrderByClauseSegment").optional().to_matchable(),
4517                    Ref::new("LimitClauseSegment").optional().to_matchable(),
4518                    Ref::new("NamedWindowSegment").optional().to_matchable(),
4519                ])
4520                .to_matchable()
4521            })
4522            .to_matchable()
4523            .into(),
4524        ),
4525        (
4526            "FromClauseSegment".into(),
4527            NodeMatcher::new(SyntaxKind::FromClause, |_| {
4528                Sequence::new(vec![
4529                    Ref::keyword("FROM").to_matchable(),
4530                    Delimited::new(vec![Ref::new("FromExpressionSegment").to_matchable()])
4531                        .to_matchable(),
4532                ])
4533                .to_matchable()
4534            })
4535            .to_matchable()
4536            .into(),
4537        ),
4538        (
4539            "EmptyStructLiteralBracketsSegment".into(),
4540            NodeMatcher::new(SyntaxKind::EmptyStructLiteralBrackets, |_| {
4541                Bracketed::new(vec![]).to_matchable()
4542            })
4543            .to_matchable()
4544            .into(),
4545        ),
4546        (
4547            "WildcardExpressionSegment".into(),
4548            NodeMatcher::new(SyntaxKind::WildcardExpression, |_| {
4549                wildcard_expression_segment()
4550            })
4551            .to_matchable()
4552            .into(),
4553        ),
4554        (
4555            "OrderByClauseSegment".into(),
4556            NodeMatcher::new(SyntaxKind::OrderbyClause, |_| {
4557                Sequence::new(vec![
4558                    Ref::keyword("ORDER").to_matchable(),
4559                    Ref::keyword("BY").to_matchable(),
4560                    MetaSegment::indent().to_matchable(),
4561                    Delimited::new(vec![
4562                        Sequence::new(vec![
4563                            one_of(vec![
4564                                Ref::new("ColumnReferenceSegment").to_matchable(),
4565                                Ref::new("NumericLiteralSegment").to_matchable(),
4566                                Ref::new("ExpressionSegment").to_matchable(),
4567                            ])
4568                            .to_matchable(),
4569                            one_of(vec![
4570                                Ref::keyword("ASC").to_matchable(),
4571                                Ref::keyword("DESC").to_matchable(),
4572                            ])
4573                            .config(|this| this.optional())
4574                            .to_matchable(),
4575                            Sequence::new(vec![
4576                                Ref::keyword("NULLS").to_matchable(),
4577                                one_of(vec![
4578                                    Ref::keyword("FIRST").to_matchable(),
4579                                    Ref::keyword("LAST").to_matchable(),
4580                                ])
4581                                .to_matchable(),
4582                            ])
4583                            .config(|this| this.optional())
4584                            .to_matchable(),
4585                        ])
4586                        .to_matchable(),
4587                    ])
4588                    .config(|this| {
4589                        this.terminators = vec![
4590                            Ref::keyword("LIMIT").to_matchable(),
4591                            Ref::new("FrameClauseUnitGrammar").to_matchable(),
4592                        ]
4593                    })
4594                    .to_matchable(),
4595                    MetaSegment::dedent().to_matchable(),
4596                ])
4597                .to_matchable()
4598            })
4599            .to_matchable()
4600            .into(),
4601        ),
4602        (
4603            "TruncateStatementSegment".into(),
4604            NodeMatcher::new(SyntaxKind::TruncateStatement, |_| {
4605                Sequence::new(vec![
4606                    Ref::keyword("TRUNCATE").to_matchable(),
4607                    Ref::keyword("TABLE").optional().to_matchable(),
4608                    Ref::new("TableReferenceSegment").to_matchable(),
4609                ])
4610                .to_matchable()
4611            })
4612            .to_matchable()
4613            .into(),
4614        ),
4615        (
4616            "FromExpressionSegment".into(),
4617            NodeMatcher::new(SyntaxKind::FromExpression, |_| {
4618                optionally_bracketed(vec![
4619                    Sequence::new(vec![
4620                        MetaSegment::indent().to_matchable(),
4621                        one_of(vec![
4622                            Ref::new("FromExpressionElementSegment").to_matchable(),
4623                            Bracketed::new(vec![Ref::new("FromExpressionSegment").to_matchable()])
4624                                .to_matchable(),
4625                        ])
4626                        .config(|this| {
4627                            this.terminators = vec![
4628                                Sequence::new(vec![
4629                                    Ref::keyword("ORDER").to_matchable(),
4630                                    Ref::keyword("BY").to_matchable(),
4631                                ])
4632                                .to_matchable(),
4633                                Sequence::new(vec![
4634                                    Ref::keyword("GROUP").to_matchable(),
4635                                    Ref::keyword("BY").to_matchable(),
4636                                ])
4637                                .to_matchable(),
4638                            ]
4639                        })
4640                        .to_matchable(),
4641                        MetaSegment::dedent().to_matchable(),
4642                        Conditional::new(MetaSegment::indent())
4643                            .indented_joins()
4644                            .to_matchable(),
4645                        AnyNumberOf::new(vec![
4646                            Sequence::new(vec![
4647                                one_of(vec![
4648                                    Ref::new("JoinClauseSegment").to_matchable(),
4649                                    Ref::new("JoinLikeClauseGrammar").to_matchable(),
4650                                ])
4651                                .config(|this| {
4652                                    this.optional();
4653                                    this.terminators = vec![
4654                                        Sequence::new(vec![
4655                                            Ref::keyword("ORDER").to_matchable(),
4656                                            Ref::keyword("BY").to_matchable(),
4657                                        ])
4658                                        .to_matchable(),
4659                                        Sequence::new(vec![
4660                                            Ref::keyword("GROUP").to_matchable(),
4661                                            Ref::keyword("BY").to_matchable(),
4662                                        ])
4663                                        .to_matchable(),
4664                                    ];
4665                                })
4666                                .to_matchable(),
4667                            ])
4668                            .to_matchable(),
4669                        ])
4670                        .to_matchable(),
4671                        Conditional::new(MetaSegment::dedent())
4672                            .indented_joins()
4673                            .to_matchable(),
4674                    ])
4675                    .to_matchable(),
4676                ])
4677                .to_matchable()
4678            })
4679            .to_matchable()
4680            .into(),
4681        ),
4682        (
4683            "DatePartFunctionNameSegment".into(),
4684            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
4685                Ref::new("DatePartFunctionName").to_matchable()
4686            })
4687            .to_matchable()
4688            .into(),
4689        ),
4690        (
4691            "FromExpressionElementSegment".into(),
4692            NodeMatcher::new(SyntaxKind::FromExpressionElement, |_| {
4693                Sequence::new(vec![
4694                    Ref::new("PreTableFunctionKeywordsGrammar")
4695                        .optional()
4696                        .to_matchable(),
4697                    optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()])
4698                        .to_matchable(),
4699                    Ref::new("AliasExpressionSegment")
4700                        .exclude(one_of(vec![
4701                            Ref::new("FromClauseTerminatorGrammar").to_matchable(),
4702                            Ref::new("SamplingExpressionSegment").to_matchable(),
4703                            Ref::new("JoinLikeClauseGrammar").to_matchable(),
4704                            LookaheadExclude::new("WITH", "(").to_matchable(),
4705                        ]))
4706                        .optional()
4707                        .to_matchable(),
4708                    Sequence::new(vec![
4709                        Ref::keyword("WITH").to_matchable(),
4710                        Ref::keyword("OFFSET").to_matchable(),
4711                        Ref::new("AliasExpressionSegment").to_matchable(),
4712                    ])
4713                    .config(|this| this.optional())
4714                    .to_matchable(),
4715                    Ref::new("SamplingExpressionSegment")
4716                        .optional()
4717                        .to_matchable(),
4718                    Ref::new("PostTableExpressionGrammar")
4719                        .optional()
4720                        .to_matchable(),
4721                ])
4722                .to_matchable()
4723            })
4724            .to_matchable()
4725            .into(),
4726        ),
4727        (
4728            "SelectStatementSegment".into(),
4729            NodeMatcher::new(SyntaxKind::SelectStatement, |_| select_statement())
4730                .to_matchable()
4731                .into(),
4732        ),
4733        (
4734            "CreateSchemaStatementSegment".into(),
4735            NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_| {
4736                Sequence::new(vec![
4737                    Ref::keyword("CREATE").to_matchable(),
4738                    Ref::keyword("SCHEMA").to_matchable(),
4739                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
4740                    Ref::new("SchemaReferenceSegment").to_matchable(),
4741                ])
4742                .to_matchable()
4743            })
4744            .to_matchable()
4745            .into(),
4746        ),
4747        (
4748            "SelectClauseModifierSegment".into(),
4749            NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_| {
4750                one_of(vec![
4751                    Ref::keyword("DISTINCT").to_matchable(),
4752                    Ref::keyword("ALL").to_matchable(),
4753                ])
4754                .to_matchable()
4755            })
4756            .to_matchable()
4757            .into(),
4758        ),
4759        (
4760            "SelectClauseElementSegment".into(),
4761            NodeMatcher::new(SyntaxKind::SelectClauseElement, |_| select_clause_element())
4762                .to_matchable()
4763                .into(),
4764        ),
4765    ]);
4766
4767    // hookpoint
4768    ansi_dialect.add([(
4769        "CharCharacterSetGrammar".into(),
4770        Nothing::new().to_matchable().into(),
4771    )]);
4772
4773    // This is a hook point to allow subclassing for other dialects
4774    ansi_dialect.add([(
4775        "AliasedTableReferenceGrammar".into(),
4776        Sequence::new(vec![
4777            Ref::new("TableReferenceSegment").to_matchable(),
4778            Ref::new("AliasExpressionSegment").to_matchable(),
4779        ])
4780        .to_matchable()
4781        .into(),
4782    )]);
4783
4784    ansi_dialect.add([
4785        (
4786            "FunctionContentsSegment".into(),
4787            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
4788                Sequence::new(vec![
4789                    Bracketed::new(vec![Ref::new("FunctionContentsGrammar").to_matchable()])
4790                        .config(|this| this.optional())
4791                        .to_matchable(),
4792                ])
4793                .to_matchable()
4794            })
4795            .to_matchable()
4796            .into(),
4797        ),
4798        // FunctionContentsExpressionGrammar intended as a hook to override in other dialects.
4799        (
4800            "FunctionContentsExpressionGrammar".into(),
4801            Ref::new("ExpressionSegment").to_matchable().into(),
4802        ),
4803        (
4804            "FunctionContentsGrammar".into(),
4805            AnyNumberOf::new(vec![
4806                Ref::new("ExpressionSegment").to_matchable(),
4807                // A Cast-like function
4808                Sequence::new(vec![
4809                    Ref::new("ExpressionSegment").to_matchable(),
4810                    Ref::keyword("AS").to_matchable(),
4811                    Ref::new("DatatypeSegment").to_matchable(),
4812                ])
4813                .to_matchable(),
4814                // Trim function
4815                Sequence::new(vec![
4816                    Ref::new("TrimParametersGrammar").to_matchable(),
4817                    Ref::new("ExpressionSegment")
4818                        .optional()
4819                        .exclude(Ref::keyword("FROM"))
4820                        .to_matchable(),
4821                    Ref::keyword("FROM").to_matchable(),
4822                    Ref::new("ExpressionSegment").to_matchable(),
4823                ])
4824                .to_matchable(),
4825                // An extract-like or substring-like function
4826                Sequence::new(vec![
4827                    one_of(vec![
4828                        Ref::new("DatetimeUnitSegment").to_matchable(),
4829                        Ref::new("ExpressionSegment").to_matchable(),
4830                    ])
4831                    .to_matchable(),
4832                    Ref::keyword("FROM").to_matchable(),
4833                    Ref::new("ExpressionSegment").to_matchable(),
4834                ])
4835                .to_matchable(),
4836                Sequence::new(vec![
4837                    // Allow an optional distinct keyword here.
4838                    Ref::keyword("DISTINCT").optional().to_matchable(),
4839                    one_of(vec![
4840                        // For COUNT(*) or similar
4841                        Ref::new("StarSegment").to_matchable(),
4842                        Delimited::new(vec![
4843                            Ref::new("FunctionContentsExpressionGrammar").to_matchable(),
4844                        ])
4845                        .to_matchable(),
4846                    ])
4847                    .to_matchable(),
4848                ])
4849                .to_matchable(),
4850                Ref::new("AggregateOrderByClause").to_matchable(), // Used in various functions
4851                Sequence::new(vec![
4852                    Ref::keyword("SEPARATOR").to_matchable(),
4853                    Ref::new("LiteralGrammar").to_matchable(),
4854                ])
4855                .to_matchable(),
4856                // Position-like function
4857                Sequence::new(vec![
4858                    one_of(vec![
4859                        Ref::new("QuotedLiteralSegment").to_matchable(),
4860                        Ref::new("SingleIdentifierGrammar").to_matchable(),
4861                        Ref::new("ColumnReferenceSegment").to_matchable(),
4862                    ])
4863                    .to_matchable(),
4864                    Ref::keyword("IN").to_matchable(),
4865                    one_of(vec![
4866                        Ref::new("QuotedLiteralSegment").to_matchable(),
4867                        Ref::new("SingleIdentifierGrammar").to_matchable(),
4868                        Ref::new("ColumnReferenceSegment").to_matchable(),
4869                    ])
4870                    .to_matchable(),
4871                ])
4872                .to_matchable(),
4873                Ref::new("IgnoreRespectNullsGrammar").to_matchable(),
4874                Ref::new("IndexColumnDefinitionSegment").to_matchable(),
4875                Ref::new("EmptyStructLiteralSegment").to_matchable(),
4876            ])
4877            .to_matchable()
4878            .into(),
4879        ),
4880        (
4881            "PostFunctionGrammar".into(),
4882            one_of(vec![
4883                Ref::new("OverClauseSegment").to_matchable(),
4884                Ref::new("FilterClauseGrammar").to_matchable(),
4885            ])
4886            .to_matchable()
4887            .into(),
4888        ),
4889    ]);
4890
4891    // Assuming `ansi_dialect` is an instance of a struct representing a SQL dialect
4892    // and `add_grammar` is a method to add a new grammar rule to the dialect.
4893    ansi_dialect.add([(
4894        "JoinLikeClauseGrammar".into(),
4895        Nothing::new().to_matchable().into(),
4896    )]);
4897
4898    ansi_dialect.add([
4899        (
4900            "AccessStatementSegmentGrantRoleWithOptionGrammar".into(),
4901            one_of(vec![
4902                Sequence::new(vec![
4903                    Ref::keyword("WITH").to_matchable(),
4904                    Ref::keyword("GRANT").to_matchable(),
4905                    Ref::keyword("OPTION").to_matchable(),
4906                ])
4907                .to_matchable(),
4908                Sequence::new(vec![
4909                    Ref::keyword("WITH").to_matchable(),
4910                    Ref::keyword("ADMIN").to_matchable(),
4911                    Ref::keyword("OPTION").to_matchable(),
4912                ])
4913                .to_matchable(),
4914                Sequence::new(vec![
4915                    Ref::keyword("COPY").to_matchable(),
4916                    Ref::keyword("CURRENT").to_matchable(),
4917                    Ref::keyword("GRANTS").to_matchable(),
4918                ])
4919                .to_matchable(),
4920            ])
4921            .to_matchable()
4922            .into(),
4923        ),
4924        (
4925            // Expression_A_Grammar
4926            // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.html#a_expr
4927            // The upstream grammar is defined recursively, which if implemented naively
4928            // will cause SQLFluff to overflow the stack from recursive function calls.
4929            // To work around this, the a_expr grammar is reworked a bit into sub-grammars
4930            // that effectively provide tail recursion.
4931            "Expression_A_Unary_Operator_Grammar".into(),
4932            one_of(vec![
4933                // This grammar corresponds to the unary operator portion of the initial
4934                // recursive block on the Cockroach Labs a_expr grammar.
4935                Ref::new("SignedSegmentGrammar")
4936                    .exclude(Sequence::new(vec![
4937                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
4938                    ]))
4939                    .to_matchable(),
4940                Ref::new("TildeSegment").to_matchable(),
4941                Ref::new("NotOperatorGrammar").to_matchable(),
4942                // Used in CONNECT BY clauses (EXASOL, Snowflake, Postgres...)
4943                Ref::keyword("PRIOR").to_matchable(),
4944            ])
4945            .to_matchable()
4946            .into(),
4947        ),
4948        (
4949            "Tail_Recurse_Expression_A_Grammar".into(),
4950            Sequence::new(vec![
4951                // This should be used instead of a recursive call to Expression_A_Grammar
4952                // whenever the repeating element in Expression_A_Grammar makes a recursive
4953                // call to itself at the _end_.
4954                AnyNumberOf::new(vec![
4955                    Ref::new("Expression_A_Unary_Operator_Grammar").to_matchable(),
4956                ])
4957                .config(|this| {
4958                    this.terminators = vec![Ref::new("BinaryOperatorGrammar").to_matchable()]
4959                })
4960                .to_matchable(),
4961                Ref::new("Expression_C_Grammar").to_matchable(),
4962            ])
4963            .to_matchable()
4964            .into(),
4965        ),
4966        (
4967            "Expression_A_Grammar".into(),
4968            Sequence::new(vec![
4969                Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
4970                AnyNumberOf::new(vec![
4971                    one_of(vec![
4972                        // Like grammar with NOT and optional ESCAPE
4973                        Sequence::new(vec![
4974                            Sequence::new(vec![
4975                                Ref::keyword("NOT").optional().to_matchable(),
4976                                Ref::new("LikeGrammar").to_matchable(),
4977                            ])
4978                            .to_matchable(),
4979                            Ref::new("Expression_A_Grammar").to_matchable(),
4980                            Sequence::new(vec![
4981                                Ref::keyword("ESCAPE").to_matchable(),
4982                                Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
4983                            ])
4984                            .config(|this| this.optional())
4985                            .to_matchable(),
4986                        ])
4987                        .to_matchable(),
4988                        // Binary operator grammar
4989                        Sequence::new(vec![
4990                            Ref::new("BinaryOperatorGrammar").to_matchable(),
4991                            Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
4992                        ])
4993                        .to_matchable(),
4994                        // IN grammar
4995                        Ref::new("InOperatorGrammar").to_matchable(),
4996                        // IS grammar
4997                        Sequence::new(vec![
4998                            Ref::keyword("IS").to_matchable(),
4999                            Ref::keyword("NOT").optional().to_matchable(),
5000                            Ref::new("IsClauseGrammar").to_matchable(),
5001                        ])
5002                        .to_matchable(),
5003                        // IS NULL and NOT NULL grammars
5004                        Ref::new("IsNullGrammar").to_matchable(),
5005                        Ref::new("NotNullGrammar").to_matchable(),
5006                        // COLLATE grammar
5007                        Ref::new("CollateGrammar").to_matchable(),
5008                        // BETWEEN grammar
5009                        Sequence::new(vec![
5010                            Ref::keyword("NOT").optional().to_matchable(),
5011                            Ref::keyword("BETWEEN").to_matchable(),
5012                            Ref::new("Expression_B_Grammar").to_matchable(),
5013                            Ref::keyword("AND").to_matchable(),
5014                            Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
5015                        ])
5016                        .to_matchable(),
5017                        // Additional sequences and grammar rules can be added here
5018                    ])
5019                    .to_matchable(),
5020                ])
5021                .to_matchable(),
5022            ])
5023            .to_matchable()
5024            .into(),
5025        ),
5026        // Expression_B_Grammar: Does not directly feed into Expression_A_Grammar
5027        // but is used for a BETWEEN statement within Expression_A_Grammar.
5028        // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.htm#b_expr
5029        // We use a similar trick as seen with Expression_A_Grammar to avoid recursion
5030        // by using a tail recursion grammar.  See the comments for a_expr to see how
5031        // that works.
5032        (
5033            "Expression_B_Unary_Operator_Grammar".into(),
5034            one_of(vec![
5035                Ref::new("SignedSegmentGrammar")
5036                    .exclude(Sequence::new(vec![
5037                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
5038                    ]))
5039                    .to_matchable(),
5040                Ref::new("TildeSegment").to_matchable(),
5041            ])
5042            .to_matchable()
5043            .into(),
5044        ),
5045        (
5046            "Tail_Recurse_Expression_B_Grammar".into(),
5047            Sequence::new(vec![
5048                // Only safe to use if the recursive call is at the END of the repeating
5049                // element in the main b_expr portion.
5050                AnyNumberOf::new(vec![
5051                    Ref::new("Expression_B_Unary_Operator_Grammar").to_matchable(),
5052                ])
5053                .to_matchable(),
5054                Ref::new("Expression_C_Grammar").to_matchable(),
5055            ])
5056            .to_matchable()
5057            .into(),
5058        ),
5059        (
5060            "Expression_B_Grammar".into(),
5061            Sequence::new(vec![
5062                // Always start with the tail recursion element
5063                Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(),
5064                AnyNumberOf::new(vec![
5065                    one_of(vec![
5066                        // Arithmetic, string, or comparison binary operators followed by tail
5067                        // recursion
5068                        Sequence::new(vec![
5069                            one_of(vec![
5070                                Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(),
5071                                Ref::new("StringBinaryOperatorGrammar").to_matchable(),
5072                                Ref::new("ComparisonOperatorGrammar").to_matchable(),
5073                            ])
5074                            .to_matchable(),
5075                            Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(),
5076                        ])
5077                        .to_matchable(),
5078                        // Additional sequences and rules from b_expr can be added here
5079                    ])
5080                    .to_matchable(),
5081                ])
5082                .to_matchable(),
5083            ])
5084            .to_matchable()
5085            .into(),
5086        ),
5087        (
5088            "Expression_C_Grammar".into(),
5089            one_of(vec![
5090                // Sequence for "EXISTS" with a bracketed selectable grammar
5091                Sequence::new(vec![
5092                    Ref::keyword("EXISTS").to_matchable(),
5093                    Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
5094                        .to_matchable(),
5095                ])
5096                .to_matchable(),
5097                // Sequence for Expression_D_Grammar or CaseExpressionSegment
5098                // followed by any number of TimeZoneGrammar
5099                Sequence::new(vec![
5100                    one_of(vec![
5101                        Ref::new("Expression_D_Grammar").to_matchable(),
5102                        Ref::new("CaseExpressionSegment").to_matchable(),
5103                    ])
5104                    .to_matchable(),
5105                    AnyNumberOf::new(vec![Ref::new("TimeZoneGrammar").to_matchable()])
5106                        .config(|this| this.optional())
5107                        .to_matchable(),
5108                ])
5109                .to_matchable(),
5110                Ref::new("ShorthandCastSegment").to_matchable(),
5111            ])
5112            .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()])
5113            .to_matchable()
5114            .into(),
5115        ),
5116        (
5117            "Expression_D_Grammar".into(),
5118            Sequence::new(vec![
5119                one_of(vec![
5120                    Ref::new("BareFunctionSegment").to_matchable(),
5121                    Ref::new("FunctionSegment").to_matchable(),
5122                    Bracketed::new(vec![
5123                        one_of(vec![
5124                            Ref::new("ExpressionSegment").to_matchable(),
5125                            Ref::new("SelectableGrammar").to_matchable(),
5126                            Delimited::new(vec![
5127                                Ref::new("ColumnReferenceSegment").to_matchable(),
5128                                Ref::new("FunctionSegment").to_matchable(),
5129                                Ref::new("LiteralGrammar").to_matchable(),
5130                                Ref::new("LocalAliasSegment").to_matchable(),
5131                            ])
5132                            .to_matchable(),
5133                        ])
5134                        .to_matchable(),
5135                    ])
5136                    .config(|this| this.parse_mode(ParseMode::Greedy))
5137                    .to_matchable(),
5138                    Ref::new("SelectStatementSegment").to_matchable(),
5139                    Ref::new("LiteralGrammar").to_matchable(),
5140                    Ref::new("IntervalExpressionSegment").to_matchable(),
5141                    Ref::new("TypedStructLiteralSegment").to_matchable(),
5142                    Ref::new("ArrayExpressionSegment").to_matchable(),
5143                    Ref::new("ColumnReferenceSegment").to_matchable(),
5144                    Sequence::new(vec![
5145                        Ref::new("SingleIdentifierGrammar").to_matchable(),
5146                        Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(),
5147                        Ref::new("StarSegment").to_matchable(),
5148                    ])
5149                    .to_matchable(),
5150                    Sequence::new(vec![
5151                        Ref::new("StructTypeSegment").to_matchable(),
5152                        Bracketed::new(vec![
5153                            Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
5154                                .to_matchable(),
5155                        ])
5156                        .to_matchable(),
5157                    ])
5158                    .to_matchable(),
5159                    Sequence::new(vec![
5160                        Ref::new("DatatypeSegment").to_matchable(),
5161                        one_of(vec![
5162                            Ref::new("QuotedLiteralSegment").to_matchable(),
5163                            Ref::new("NumericLiteralSegment").to_matchable(),
5164                            Ref::new("BooleanLiteralGrammar").to_matchable(),
5165                            Ref::new("NullLiteralSegment").to_matchable(),
5166                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
5167                        ])
5168                        .to_matchable(),
5169                    ])
5170                    .to_matchable(),
5171                    Ref::new("LocalAliasSegment").to_matchable(),
5172                ])
5173                .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()])
5174                .to_matchable(),
5175                Ref::new("AccessorGrammar").optional().to_matchable(),
5176            ])
5177            .allow_gaps(true)
5178            .to_matchable()
5179            .into(),
5180        ),
5181        (
5182            "AccessorGrammar".into(),
5183            AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()])
5184                .to_matchable()
5185                .into(),
5186        ),
5187    ]);
5188
5189    ansi_dialect.add([
5190        (
5191            "SelectableGrammar".into(),
5192            one_of(vec![
5193                optionally_bracketed(vec![
5194                    Ref::new("WithCompoundStatementSegment").to_matchable(),
5195                ])
5196                .to_matchable(),
5197                optionally_bracketed(vec![
5198                    Ref::new("WithCompoundNonSelectStatementSegment").to_matchable(),
5199                ])
5200                .to_matchable(),
5201                Ref::new("NonWithSelectableGrammar").to_matchable(),
5202                Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
5203            ])
5204            .to_matchable()
5205            .into(),
5206        ),
5207        (
5208            "NonWithSelectableGrammar".into(),
5209            one_of(vec![
5210                Ref::new("SetExpressionSegment").to_matchable(),
5211                optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()])
5212                    .to_matchable(),
5213                Ref::new("NonSetSelectableGrammar").to_matchable(),
5214            ])
5215            .to_matchable()
5216            .into(),
5217        ),
5218        (
5219            "NonWithNonSelectableGrammar".into(),
5220            one_of(vec![
5221                Ref::new("UpdateStatementSegment").to_matchable(),
5222                Ref::new("InsertStatementSegment").to_matchable(),
5223                Ref::new("DeleteStatementSegment").to_matchable(),
5224                Ref::new("MergeStatementSegment").to_matchable(),
5225            ])
5226            .to_matchable()
5227            .into(),
5228        ),
5229        (
5230            "NonSetSelectableGrammar".into(),
5231            one_of(vec![
5232                Ref::new("ValuesClauseSegment").to_matchable(),
5233                Ref::new("UnorderedSelectStatementSegment").to_matchable(),
5234                Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()])
5235                    .to_matchable(),
5236                Bracketed::new(vec![
5237                    Ref::new("WithCompoundStatementSegment").to_matchable(),
5238                ])
5239                .to_matchable(),
5240                Bracketed::new(vec![Ref::new("NonSetSelectableGrammar").to_matchable()])
5241                    .to_matchable(),
5242            ])
5243            .to_matchable()
5244            .into(),
5245        ),
5246    ]);
5247
5248    // This is a hook point to allow subclassing for other dialects
5249    ansi_dialect.add([
5250        (
5251            "PostTableExpressionGrammar".into(),
5252            Nothing::new().to_matchable().into(),
5253        ),
5254        (
5255            "BracketedSegment".into(),
5256            BracketedSegmentMatcher::new().to_matchable().into(),
5257        ),
5258        (
5259            "TimeWithTZGrammar".into(),
5260            Sequence::new(vec![
5261                one_of(vec![
5262                    Ref::keyword("TIME").to_matchable(),
5263                    Ref::keyword("TIMESTAMP").to_matchable(),
5264                ])
5265                .to_matchable(),
5266                Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
5267                    .config(|this| this.optional())
5268                    .to_matchable(),
5269                Sequence::new(vec![
5270                    one_of(vec![
5271                        Ref::keyword("WITH").to_matchable(),
5272                        Ref::keyword("WITHOUT").to_matchable(),
5273                    ])
5274                    .to_matchable(),
5275                    Ref::keyword("TIME").to_matchable(),
5276                    Ref::keyword("ZONE").to_matchable(),
5277                ])
5278                .config(|this| this.optional())
5279                .to_matchable(),
5280            ])
5281            .to_matchable()
5282            .into(),
5283        ),
5284    ]);
5285
5286    ansi_dialect
5287}
5288
5289pub fn select_clause_element() -> Matchable {
5290    one_of(vec![
5291        // *, blah.*, blah.blah.*, etc.
5292        Ref::new("WildcardExpressionSegment").to_matchable(),
5293        Sequence::new(vec![
5294            Ref::new("BaseExpressionElementGrammar").to_matchable(),
5295            Ref::new("AliasExpressionSegment").optional().to_matchable(),
5296        ])
5297        .to_matchable(),
5298    ])
5299    .to_matchable()
5300}
5301
5302fn lexer_matchers() -> Vec<Matcher> {
5303    vec![
5304        Matcher::regex("whitespace", r"[^\S\r\n]+", SyntaxKind::Whitespace),
5305        Matcher::regex("inline_comment", r"(--|#)[^\n]*", SyntaxKind::InlineComment),
5306        Matcher::native("block_comment", block_comment, SyntaxKind::BlockComment)
5307            .subdivider(Pattern::legacy(
5308                "newline",
5309                |_| true,
5310                r"\r\n|\n",
5311                SyntaxKind::Newline,
5312            ))
5313            .post_subdivide(Pattern::legacy(
5314                "whitespace",
5315                |_| true,
5316                r"[^\S\r\n]+",
5317                SyntaxKind::Whitespace,
5318            )),
5319        Matcher::regex(
5320            "single_quote",
5321            r"'([^'\\]|\\.|'')*'",
5322            SyntaxKind::SingleQuote,
5323        ),
5324        Matcher::regex(
5325            "double_quote",
5326            r#""([^"\\]|\\.)*""#,
5327            SyntaxKind::DoubleQuote,
5328        ),
5329        Matcher::regex("back_quote", r"`[^`]*`", SyntaxKind::BackQuote),
5330        Matcher::legacy(
5331            "dollar_quote",
5332            |s| s.starts_with("$"),
5333            r"\$(\w*)\$[\s\S]*?\$\1\$",
5334            SyntaxKind::DollarQuote,
5335        ),
5336        Matcher::native(
5337            "numeric_literal",
5338            numeric_literal,
5339            SyntaxKind::NumericLiteral,
5340        ),
5341        Matcher::regex("like_operator", r"!?~~?\*?", SyntaxKind::LikeOperator),
5342        Matcher::regex("newline", r"(\r\n|\n)", SyntaxKind::Newline),
5343        Matcher::string("casting_operator", "::", SyntaxKind::CastingOperator),
5344        Matcher::string("equals", "=", SyntaxKind::RawComparisonOperator),
5345        Matcher::string("greater_than", ">", SyntaxKind::RawComparisonOperator),
5346        Matcher::string("less_than", "<", SyntaxKind::RawComparisonOperator),
5347        Matcher::string("not", "!", SyntaxKind::RawComparisonOperator),
5348        Matcher::string("dot", ".", SyntaxKind::Dot),
5349        Matcher::string("comma", ",", SyntaxKind::Comma),
5350        Matcher::string("plus", "+", SyntaxKind::Plus),
5351        Matcher::string("minus", "-", SyntaxKind::Minus),
5352        Matcher::string("divide", "/", SyntaxKind::Divide),
5353        Matcher::string("percent", "%", SyntaxKind::Percent),
5354        Matcher::string("question", "?", SyntaxKind::Question),
5355        Matcher::string("ampersand", "&", SyntaxKind::Ampersand),
5356        Matcher::string("vertical_bar", "|", SyntaxKind::VerticalBar),
5357        Matcher::string("caret", "^", SyntaxKind::Caret),
5358        Matcher::string("star", "*", SyntaxKind::Star),
5359        Matcher::string("start_bracket", "(", SyntaxKind::StartBracket),
5360        Matcher::string("end_bracket", ")", SyntaxKind::EndBracket),
5361        Matcher::string("start_square_bracket", "[", SyntaxKind::StartSquareBracket),
5362        Matcher::string("end_square_bracket", "]", SyntaxKind::EndSquareBracket),
5363        Matcher::string("start_curly_bracket", "{", SyntaxKind::StartCurlyBracket),
5364        Matcher::string("end_curly_bracket", "}", SyntaxKind::EndCurlyBracket),
5365        Matcher::string("colon", ":", SyntaxKind::Colon),
5366        Matcher::string("semicolon", ";", SyntaxKind::Semicolon),
5367        Matcher::regex("word", "[0-9a-zA-Z_]+", SyntaxKind::Word),
5368    ]
5369}
5370
5371pub fn frame_extent() -> AnyNumberOf {
5372    one_of(vec![
5373        Sequence::new(vec![
5374            Ref::keyword("CURRENT").to_matchable(),
5375            Ref::keyword("ROW").to_matchable(),
5376        ])
5377        .to_matchable(),
5378        Sequence::new(vec![
5379            one_of(vec![
5380                Ref::new("NumericLiteralSegment").to_matchable(),
5381                Sequence::new(vec![
5382                    Ref::keyword("INTERVAL").to_matchable(),
5383                    Ref::new("QuotedLiteralSegment").to_matchable(),
5384                ])
5385                .to_matchable(),
5386                Ref::keyword("UNBOUNDED").to_matchable(),
5387            ])
5388            .to_matchable(),
5389            one_of(vec![
5390                Ref::keyword("PRECEDING").to_matchable(),
5391                Ref::keyword("FOLLOWING").to_matchable(),
5392            ])
5393            .to_matchable(),
5394        ])
5395        .to_matchable(),
5396    ])
5397}
5398
5399pub fn explainable_stmt() -> AnyNumberOf {
5400    one_of(vec![
5401        Ref::new("SelectableGrammar").to_matchable(),
5402        Ref::new("InsertStatementSegment").to_matchable(),
5403        Ref::new("UpdateStatementSegment").to_matchable(),
5404        Ref::new("DeleteStatementSegment").to_matchable(),
5405    ])
5406}
5407
5408pub fn get_unordered_select_statement_segment_grammar() -> Matchable {
5409    Sequence::new(vec![
5410        Ref::new("SelectClauseSegment").to_matchable(),
5411        MetaSegment::dedent().to_matchable(),
5412        Ref::new("FromClauseSegment").optional().to_matchable(),
5413        Ref::new("WhereClauseSegment").optional().to_matchable(),
5414        Ref::new("GroupByClauseSegment").optional().to_matchable(),
5415        Ref::new("HavingClauseSegment").optional().to_matchable(),
5416        Ref::new("OverlapsClauseSegment").optional().to_matchable(),
5417        Ref::new("NamedWindowSegment").optional().to_matchable(),
5418    ])
5419    .terminators(vec![
5420        Ref::new("SetOperatorSegment").to_matchable(),
5421        Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
5422        Ref::new("WithDataClauseSegment").to_matchable(),
5423        Ref::new("OrderByClauseSegment").to_matchable(),
5424        Ref::new("LimitClauseSegment").to_matchable(),
5425    ])
5426    .config(|this| {
5427        this.parse_mode(ParseMode::GreedyOnceStarted);
5428    })
5429    .to_matchable()
5430}
5431
5432pub fn select_statement() -> Matchable {
5433    get_unordered_select_statement_segment_grammar().copy(
5434        Some(vec![
5435            Ref::new("OrderByClauseSegment").optional().to_matchable(),
5436            Ref::new("FetchClauseSegment").optional().to_matchable(),
5437            Ref::new("LimitClauseSegment").optional().to_matchable(),
5438            Ref::new("NamedWindowSegment").optional().to_matchable(),
5439        ]),
5440        None,
5441        None,
5442        None,
5443        vec![
5444            Ref::new("SetOperatorSegment").to_matchable(),
5445            Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
5446            Ref::new("WithDataClauseSegment").to_matchable(),
5447        ],
5448        true,
5449    )
5450}
5451
5452pub fn select_clause_segment() -> Matchable {
5453    Sequence::new(vec![
5454        Ref::keyword("SELECT").to_matchable(),
5455        Ref::new("SelectClauseModifierSegment")
5456            .optional()
5457            .to_matchable(),
5458        MetaSegment::indent().to_matchable(),
5459        Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()])
5460            .config(|this| this.allow_trailing())
5461            .to_matchable(),
5462    ])
5463    .terminators(vec![
5464        Ref::new("SelectClauseTerminatorGrammar").to_matchable(),
5465    ])
5466    .config(|this| {
5467        this.parse_mode(ParseMode::GreedyOnceStarted);
5468    })
5469    .to_matchable()
5470}
5471
5472pub fn statement_segment() -> Matchable {
5473    one_of(vec![
5474        Ref::new("SelectableGrammar").to_matchable(),
5475        Ref::new("MergeStatementSegment").to_matchable(),
5476        Ref::new("InsertStatementSegment").to_matchable(),
5477        Ref::new("TransactionStatementSegment").to_matchable(),
5478        Ref::new("DropTableStatementSegment").to_matchable(),
5479        Ref::new("DropViewStatementSegment").to_matchable(),
5480        Ref::new("CreateUserStatementSegment").to_matchable(),
5481        Ref::new("DropUserStatementSegment").to_matchable(),
5482        Ref::new("TruncateStatementSegment").to_matchable(),
5483        Ref::new("AccessStatementSegment").to_matchable(),
5484        Ref::new("CreateTableStatementSegment").to_matchable(),
5485        Ref::new("CreateRoleStatementSegment").to_matchable(),
5486        Ref::new("DropRoleStatementSegment").to_matchable(),
5487        Ref::new("AlterTableStatementSegment").to_matchable(),
5488        Ref::new("CreateSchemaStatementSegment").to_matchable(),
5489        Ref::new("SetSchemaStatementSegment").to_matchable(),
5490        Ref::new("DropSchemaStatementSegment").to_matchable(),
5491        Ref::new("DropTypeStatementSegment").to_matchable(),
5492        Ref::new("CreateDatabaseStatementSegment").to_matchable(),
5493        Ref::new("DropDatabaseStatementSegment").to_matchable(),
5494        Ref::new("CreateIndexStatementSegment").to_matchable(),
5495        Ref::new("DropIndexStatementSegment").to_matchable(),
5496        Ref::new("CreateViewStatementSegment").to_matchable(),
5497        Ref::new("DeleteStatementSegment").to_matchable(),
5498        Ref::new("UpdateStatementSegment").to_matchable(),
5499        Ref::new("CreateCastStatementSegment").to_matchable(),
5500        Ref::new("DropCastStatementSegment").to_matchable(),
5501        Ref::new("CreateFunctionStatementSegment").to_matchable(),
5502        Ref::new("DropFunctionStatementSegment").to_matchable(),
5503        Ref::new("CreateModelStatementSegment").to_matchable(),
5504        Ref::new("DropModelStatementSegment").to_matchable(),
5505        Ref::new("DescribeStatementSegment").to_matchable(),
5506        Ref::new("UseStatementSegment").to_matchable(),
5507        Ref::new("ExplainStatementSegment").to_matchable(),
5508        Ref::new("CreateSequenceStatementSegment").to_matchable(),
5509        Ref::new("AlterSequenceStatementSegment").to_matchable(),
5510        Ref::new("DropSequenceStatementSegment").to_matchable(),
5511        Ref::new("CreateTriggerStatementSegment").to_matchable(),
5512        Ref::new("DropTriggerStatementSegment").to_matchable(),
5513    ])
5514    .config(|this| this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()])
5515    .to_matchable()
5516}
5517
5518pub fn wildcard_expression_segment() -> Matchable {
5519    Sequence::new(vec![Ref::new("WildcardIdentifierSegment").to_matchable()]).to_matchable()
5520}
5521
5522fn numeric_literal(cursor: &mut Cursor) -> bool {
5523    let first_char = cursor.shift();
5524    match first_char {
5525        '0'..='9' | '.' => {
5526            let has_decimal = first_char == '.';
5527
5528            if has_decimal {
5529                if cursor.peek().is_ascii_digit() {
5530                    cursor.shift_while(|c| c.is_ascii_digit());
5531                } else {
5532                    return false;
5533                }
5534            } else {
5535                cursor.shift_while(|c| c.is_ascii_digit());
5536                if cursor.peek() == '.' {
5537                    cursor.shift();
5538                    cursor.shift_while(|c| c.is_ascii_digit());
5539                }
5540            }
5541
5542            if let 'e' | 'E' = cursor.peek() {
5543                cursor.shift();
5544                if let '+' | '-' = cursor.peek() {
5545                    cursor.shift();
5546                }
5547                let mut exp_digits = false;
5548                while cursor.peek().is_ascii_digit() {
5549                    cursor.shift();
5550                    exp_digits = true;
5551                }
5552                if !exp_digits {
5553                    return false;
5554                }
5555            }
5556
5557            let next_char = cursor.peek();
5558            if next_char == '.' || next_char.is_ascii_alphanumeric() || next_char == '_' {
5559                return false;
5560            }
5561
5562            true
5563        }
5564        _ => false,
5565    }
5566}
5567
5568fn block_comment(cursor: &mut Cursor) -> bool {
5569    if cursor.shift() != '/' {
5570        return false;
5571    }
5572
5573    if cursor.shift() != '*' {
5574        return false;
5575    }
5576
5577    let mut depth = 1usize;
5578
5579    loop {
5580        match cursor.shift() {
5581            '\0' => return false,
5582            '/' if cursor.peek() == '*' => {
5583                cursor.shift();
5584                depth += 1;
5585            }
5586            '*' if cursor.peek() == '/' => {
5587                cursor.shift();
5588                depth -= 1;
5589                if depth == 0 {
5590                    break true;
5591                }
5592            }
5593            _ => {}
5594        }
5595    }
5596}
5597
5598pub(crate) fn select_clause_terminators() -> Vec<Matchable> {
5599    vec![
5600        Ref::keyword("FROM").to_matchable(),
5601        Ref::keyword("WHERE").to_matchable(),
5602        Sequence::new(vec![
5603            Ref::keyword("ORDER").to_matchable(),
5604            Ref::keyword("BY").to_matchable(),
5605        ])
5606        .to_matchable(),
5607        Ref::keyword("LIMIT").to_matchable(),
5608        Ref::keyword("OVERLAPS").to_matchable(),
5609        Ref::new("SetOperatorSegment").to_matchable(),
5610        Ref::keyword("FETCH").to_matchable(),
5611    ]
5612}