Skip to main content

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