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")
3957                            .optional()
3958                            .reset_terminators()
3959                            .terminators(vec![Ref::keyword("END").to_matchable()])
3960                            .to_matchable(),
3961                        MetaSegment::dedent().to_matchable(),
3962                        Ref::keyword("END").to_matchable(),
3963                    ])
3964                    .to_matchable(),
3965                    Sequence::new(vec![
3966                        Ref::keyword("CASE").to_matchable(),
3967                        Ref::new("ExpressionSegment").to_matchable(),
3968                        MetaSegment::implicit_indent().to_matchable(),
3969                        AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()])
3970                            .config(|this| {
3971                                this.reset_terminators = true;
3972                                this.terminators = vec![
3973                                    Ref::keyword("ELSE").to_matchable(),
3974                                    Ref::keyword("END").to_matchable(),
3975                                ];
3976                            })
3977                            .to_matchable(),
3978                        Ref::new("ElseClauseSegment")
3979                            .optional()
3980                            .reset_terminators()
3981                            .terminators(vec![Ref::keyword("END").to_matchable()])
3982                            .to_matchable(),
3983                        MetaSegment::dedent().to_matchable(),
3984                        Ref::keyword("END").to_matchable(),
3985                    ])
3986                    .to_matchable(),
3987                ])
3988                .config(|this| {
3989                    this.terminators = vec![
3990                        Ref::new("ComparisonOperatorGrammar").to_matchable(),
3991                        Ref::new("CommaSegment").to_matchable(),
3992                        Ref::new("BinaryOperatorGrammar").to_matchable(),
3993                    ]
3994                })
3995                .to_matchable()
3996            })
3997            .to_matchable()
3998            .into(),
3999        ),
4000        (
4001            "WhenClauseSegment".into(),
4002            NodeMatcher::new(SyntaxKind::WhenClause, |_| {
4003                Sequence::new(vec![
4004                    Ref::keyword("WHEN").to_matchable(),
4005                    Sequence::new(vec![
4006                        MetaSegment::implicit_indent().to_matchable(),
4007                        Ref::new("ExpressionSegment").to_matchable(),
4008                        MetaSegment::dedent().to_matchable(),
4009                    ])
4010                    .to_matchable(),
4011                    Conditional::new(MetaSegment::indent())
4012                        .indented_then()
4013                        .to_matchable(),
4014                    Ref::keyword("THEN").to_matchable(),
4015                    Conditional::new(MetaSegment::implicit_indent())
4016                        .indented_then_contents()
4017                        .to_matchable(),
4018                    Ref::new("ExpressionSegment").to_matchable(),
4019                    Conditional::new(MetaSegment::dedent())
4020                        .indented_then_contents()
4021                        .to_matchable(),
4022                    Conditional::new(MetaSegment::dedent())
4023                        .indented_then()
4024                        .to_matchable(),
4025                ])
4026                .to_matchable()
4027            })
4028            .to_matchable()
4029            .into(),
4030        ),
4031        (
4032            "ElseClauseSegment".into(),
4033            NodeMatcher::new(SyntaxKind::ElseClause, |_| {
4034                Sequence::new(vec![
4035                    Ref::keyword("ELSE").to_matchable(),
4036                    MetaSegment::implicit_indent().to_matchable(),
4037                    Ref::new("ExpressionSegment").to_matchable(),
4038                    MetaSegment::dedent().to_matchable(),
4039                ])
4040                .to_matchable()
4041            })
4042            .to_matchable()
4043            .into(),
4044        ),
4045        (
4046            "WhereClauseSegment".into(),
4047            NodeMatcher::new(SyntaxKind::WhereClause, |_| {
4048                Sequence::new(vec![
4049                    Ref::keyword("WHERE").to_matchable(),
4050                    MetaSegment::implicit_indent().to_matchable(),
4051                    optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()])
4052                        .to_matchable(),
4053                    MetaSegment::dedent().to_matchable(),
4054                ])
4055                .to_matchable()
4056            })
4057            .to_matchable()
4058            .into(),
4059        ),
4060        (
4061            "SetOperatorSegment".into(),
4062            NodeMatcher::new(SyntaxKind::SetOperator, |_| {
4063                one_of(vec![
4064                    Ref::new("UnionGrammar").to_matchable(),
4065                    Sequence::new(vec![
4066                        one_of(vec![
4067                            Ref::keyword("INTERSECT").to_matchable(),
4068                            Ref::keyword("EXCEPT").to_matchable(),
4069                        ])
4070                        .to_matchable(),
4071                        Ref::keyword("ALL").optional().to_matchable(),
4072                    ])
4073                    .to_matchable(),
4074                    Ref::keyword("MINUS").to_matchable(),
4075                ])
4076                .to_matchable()
4077            })
4078            .to_matchable()
4079            .into(),
4080        ),
4081        (
4082            "ValuesClauseSegment".into(),
4083            NodeMatcher::new(SyntaxKind::ValuesClause, |_| {
4084                Sequence::new(vec![
4085                    one_of(vec![
4086                        Ref::keyword("VALUE").to_matchable(),
4087                        Ref::keyword("VALUES").to_matchable(),
4088                    ])
4089                    .to_matchable(),
4090                    Delimited::new(vec![
4091                        Sequence::new(vec![
4092                            Ref::keyword("ROW").optional().to_matchable(),
4093                            Bracketed::new(vec![
4094                                Delimited::new(vec![
4095                                    Ref::keyword("DEFAULT").to_matchable(),
4096                                    Ref::new("LiteralGrammar").to_matchable(),
4097                                    Ref::new("ExpressionSegment").to_matchable(),
4098                                ])
4099                                .to_matchable(),
4100                            ])
4101                            .config(|this| this.parse_mode(ParseMode::Greedy))
4102                            .to_matchable(),
4103                        ])
4104                        .to_matchable(),
4105                    ])
4106                    .to_matchable(),
4107                ])
4108                .to_matchable()
4109            })
4110            .to_matchable()
4111            .into(),
4112        ),
4113        (
4114            "EmptyStructLiteralSegment".into(),
4115            NodeMatcher::new(SyntaxKind::EmptyStructLiteral, |_| {
4116                Sequence::new(vec![
4117                    Ref::new("StructTypeSegment").to_matchable(),
4118                    Ref::new("EmptyStructLiteralBracketsSegment").to_matchable(),
4119                ])
4120                .to_matchable()
4121            })
4122            .to_matchable()
4123            .into(),
4124        ),
4125        (
4126            "ObjectLiteralSegment".into(),
4127            NodeMatcher::new(SyntaxKind::ObjectLiteral, |_| {
4128                Bracketed::new(vec![
4129                    Delimited::new(vec![Ref::new("ObjectLiteralElementSegment").to_matchable()])
4130                        .config(|this| {
4131                            this.optional();
4132                        })
4133                        .to_matchable(),
4134                ])
4135                .config(|this| {
4136                    this.bracket_type("curly");
4137                })
4138                .to_matchable()
4139            })
4140            .to_matchable()
4141            .into(),
4142        ),
4143        (
4144            "ObjectLiteralElementSegment".into(),
4145            NodeMatcher::new(SyntaxKind::ObjectLiteralElement, |_| {
4146                Sequence::new(vec![
4147                    Ref::new("QuotedLiteralSegment").to_matchable(),
4148                    Ref::new("ColonSegment").to_matchable(),
4149                    Ref::new("BaseExpressionElementGrammar").to_matchable(),
4150                ])
4151                .to_matchable()
4152            })
4153            .to_matchable()
4154            .into(),
4155        ),
4156        (
4157            "TimeZoneGrammar".into(),
4158            NodeMatcher::new(SyntaxKind::TimeZoneGrammar, |_| {
4159                AnyNumberOf::new(vec![
4160                    Sequence::new(vec![
4161                        Ref::keyword("AT").to_matchable(),
4162                        Ref::keyword("TIME").to_matchable(),
4163                        Ref::keyword("ZONE").to_matchable(),
4164                        Ref::new("ExpressionSegment").to_matchable(),
4165                    ])
4166                    .to_matchable(),
4167                ])
4168                .to_matchable()
4169            })
4170            .to_matchable()
4171            .into(),
4172        ),
4173        (
4174            "BracketedArguments".into(),
4175            NodeMatcher::new(SyntaxKind::BracketedArguments, |_| {
4176                Bracketed::new(vec![
4177                    Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()])
4178                        .config(|this| {
4179                            this.optional();
4180                        })
4181                        .to_matchable(),
4182                ])
4183                .to_matchable()
4184            })
4185            .to_matchable()
4186            .into(),
4187        ),
4188        (
4189            "DatatypeSegment".into(),
4190            NodeMatcher::new(SyntaxKind::DataType, |_| {
4191                one_of(vec![
4192                    Ref::new("TimeWithTZGrammar").to_matchable(),
4193                    Sequence::new(vec![
4194                        Ref::keyword("DOUBLE").to_matchable(),
4195                        Ref::keyword("PRECISION").to_matchable(),
4196                    ])
4197                    .to_matchable(),
4198                    Sequence::new(vec![
4199                        one_of(vec![
4200                            Sequence::new(vec![
4201                                one_of(vec![
4202                                    Ref::keyword("CHARACTER").to_matchable(),
4203                                    Ref::keyword("BINARY").to_matchable(),
4204                                ])
4205                                .to_matchable(),
4206                                one_of(vec![
4207                                    Ref::keyword("VARYING").to_matchable(),
4208                                    Sequence::new(vec![
4209                                        Ref::keyword("LARGE").to_matchable(),
4210                                        Ref::keyword("OBJECT").to_matchable(),
4211                                    ])
4212                                    .to_matchable(),
4213                                ])
4214                                .to_matchable(),
4215                            ])
4216                            .to_matchable(),
4217                            Sequence::new(vec![
4218                                Sequence::new(vec![
4219                                    Ref::new("SingleIdentifierGrammar").to_matchable(),
4220                                    Ref::new("DotSegment").to_matchable(),
4221                                ])
4222                                .config(|this| this.optional())
4223                                .to_matchable(),
4224                                Ref::new("DatatypeIdentifierSegment").to_matchable(),
4225                            ])
4226                            .to_matchable(),
4227                        ])
4228                        .to_matchable(),
4229                        Ref::new("BracketedArguments").optional().to_matchable(),
4230                        one_of(vec![
4231                            Ref::keyword("UNSIGNED").to_matchable(),
4232                            Ref::new("CharCharacterSetGrammar").to_matchable(),
4233                        ])
4234                        .config(|config| config.optional())
4235                        .to_matchable(),
4236                    ])
4237                    .to_matchable(),
4238                ])
4239                .to_matchable()
4240            })
4241            .to_matchable()
4242            .into(),
4243        ),
4244        (
4245            "AsAliasOperatorSegment".into(),
4246            NodeMatcher::new(SyntaxKind::AliasOperator, |_| {
4247                Ref::keyword("AS").to_matchable()
4248            })
4249            .to_matchable()
4250            .into(),
4251        ),
4252        (
4253            "AliasExpressionSegment".into(),
4254            NodeMatcher::new(SyntaxKind::AliasExpression, |_| {
4255                Sequence::new(vec![
4256                    MetaSegment::indent().to_matchable(),
4257                    Ref::new("AsAliasOperatorSegment").optional().to_matchable(),
4258                    one_of(vec![
4259                        Sequence::new(vec![
4260                            Ref::new("SingleIdentifierGrammar").to_matchable(),
4261                            Bracketed::new(vec![
4262                                Ref::new("SingleIdentifierListSegment").to_matchable(),
4263                            ])
4264                            .config(|this| this.optional())
4265                            .to_matchable(),
4266                        ])
4267                        .to_matchable(),
4268                        Ref::new("SingleQuotedIdentifierSegment").to_matchable(),
4269                    ])
4270                    .to_matchable(),
4271                    MetaSegment::dedent().to_matchable(),
4272                ])
4273                .to_matchable()
4274            })
4275            .to_matchable()
4276            .into(),
4277        ),
4278        (
4279            "ShorthandCastSegment".into(),
4280            NodeMatcher::new(SyntaxKind::CastExpression, |_| {
4281                Sequence::new(vec![
4282                    one_of(vec![
4283                        Ref::new("Expression_D_Grammar").to_matchable(),
4284                        Ref::new("CaseExpressionSegment").to_matchable(),
4285                    ])
4286                    .to_matchable(),
4287                    AnyNumberOf::new(vec![
4288                        Sequence::new(vec![
4289                            Ref::new("CastOperatorSegment").to_matchable(),
4290                            Ref::new("DatatypeSegment").to_matchable(),
4291                            Ref::new("TimeZoneGrammar").optional().to_matchable(),
4292                        ])
4293                        .to_matchable(),
4294                    ])
4295                    .config(|this| this.min_times(1))
4296                    .to_matchable(),
4297                ])
4298                .to_matchable()
4299            })
4300            .to_matchable()
4301            .into(),
4302        ),
4303        (
4304            "ArrayAccessorSegment".into(),
4305            NodeMatcher::new(SyntaxKind::ArrayAccessor, |_| {
4306                Bracketed::new(vec![
4307                    Delimited::new(vec![
4308                        one_of(vec![
4309                            Ref::new("NumericLiteralSegment").to_matchable(),
4310                            Ref::new("ExpressionSegment").to_matchable(),
4311                        ])
4312                        .to_matchable(),
4313                    ])
4314                    .config(|this| this.delimiter(Ref::new("SliceSegment")))
4315                    .to_matchable(),
4316                ])
4317                .config(|this| {
4318                    this.bracket_type("square");
4319                    this.parse_mode(ParseMode::Greedy);
4320                })
4321                .to_matchable()
4322            })
4323            .to_matchable()
4324            .into(),
4325        ),
4326        (
4327            "ArrayLiteralSegment".into(),
4328            NodeMatcher::new(SyntaxKind::ArrayLiteral, |_| {
4329                Bracketed::new(vec![
4330                    Delimited::new(vec![
4331                        Ref::new("BaseExpressionElementGrammar").to_matchable(),
4332                    ])
4333                    .config(|this| {
4334                        this.delimiter(Ref::new("CommaSegment"));
4335                        this.optional();
4336                    })
4337                    .to_matchable(),
4338                ])
4339                .config(|this| {
4340                    this.bracket_type("square");
4341                    this.parse_mode(ParseMode::Greedy);
4342                })
4343                .to_matchable()
4344            })
4345            .to_matchable()
4346            .into(),
4347        ),
4348        (
4349            "TypedArrayLiteralSegment".into(),
4350            NodeMatcher::new(SyntaxKind::TypedArrayLiteral, |_| {
4351                Sequence::new(vec![
4352                    Ref::new("ArrayTypeSegment").to_matchable(),
4353                    Ref::new("ArrayLiteralSegment").to_matchable(),
4354                ])
4355                .to_matchable()
4356            })
4357            .to_matchable()
4358            .into(),
4359        ),
4360        (
4361            "StructTypeSegment".into(),
4362            NodeMatcher::new(SyntaxKind::StructType, |_| Nothing::new().to_matchable())
4363                .to_matchable()
4364                .into(),
4365        ),
4366        (
4367            "StructLiteralSegment".into(),
4368            NodeMatcher::new(SyntaxKind::StructLiteral, |_| {
4369                Bracketed::new(vec![
4370                    Delimited::new(vec![
4371                        Sequence::new(vec![
4372                            Ref::new("BaseExpressionElementGrammar").to_matchable(),
4373                            Ref::new("AliasExpressionSegment").optional().to_matchable(),
4374                        ])
4375                        .to_matchable(),
4376                    ])
4377                    .to_matchable(),
4378                ])
4379                .to_matchable()
4380            })
4381            .to_matchable()
4382            .into(),
4383        ),
4384        (
4385            "TypedStructLiteralSegment".into(),
4386            NodeMatcher::new(SyntaxKind::TypedStructLiteral, |_| {
4387                Sequence::new(vec![
4388                    Ref::new("StructTypeSegment").to_matchable(),
4389                    Ref::new("StructLiteralSegment").to_matchable(),
4390                ])
4391                .to_matchable()
4392            })
4393            .to_matchable()
4394            .into(),
4395        ),
4396        (
4397            "IntervalExpressionSegment".into(),
4398            NodeMatcher::new(SyntaxKind::IntervalExpression, |_| {
4399                Sequence::new(vec![
4400                    Ref::keyword("INTERVAL").to_matchable(),
4401                    one_of(vec![
4402                        Sequence::new(vec![
4403                            Ref::new("NumericLiteralSegment").to_matchable(),
4404                            one_of(vec![
4405                                Ref::new("QuotedLiteralSegment").to_matchable(),
4406                                Ref::new("DatetimeUnitSegment").to_matchable(),
4407                            ])
4408                            .to_matchable(),
4409                        ])
4410                        .to_matchable(),
4411                        Ref::new("QuotedLiteralSegment").to_matchable(),
4412                    ])
4413                    .to_matchable(),
4414                ])
4415                .to_matchable()
4416            })
4417            .to_matchable()
4418            .into(),
4419        ),
4420        (
4421            "ArrayTypeSegment".into(),
4422            NodeMatcher::new(SyntaxKind::ArrayType, |_| Nothing::new().to_matchable())
4423                .to_matchable()
4424                .into(),
4425        ),
4426        (
4427            "SizedArrayTypeSegment".into(),
4428            NodeMatcher::new(SyntaxKind::SizedArrayType, |_| {
4429                Sequence::new(vec![
4430                    Ref::new("ArrayTypeSegment").to_matchable(),
4431                    Ref::new("ArrayAccessorSegment").to_matchable(),
4432                ])
4433                .to_matchable()
4434            })
4435            .to_matchable()
4436            .into(),
4437        ),
4438        (
4439            "UnorderedSelectStatementSegment".into(),
4440            NodeMatcher::new(SyntaxKind::SelectStatement, |_| {
4441                Sequence::new(vec![
4442                    Ref::new("SelectClauseSegment").to_matchable(),
4443                    MetaSegment::dedent().to_matchable(),
4444                    Ref::new("FromClauseSegment").optional().to_matchable(),
4445                    Ref::new("WhereClauseSegment").optional().to_matchable(),
4446                    Ref::new("GroupByClauseSegment").optional().to_matchable(),
4447                    Ref::new("HavingClauseSegment").optional().to_matchable(),
4448                    Ref::new("OverlapsClauseSegment").optional().to_matchable(),
4449                    Ref::new("NamedWindowSegment").optional().to_matchable(),
4450                ])
4451                .terminators(vec![
4452                    Ref::new("SetOperatorSegment").to_matchable(),
4453                    Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
4454                    Ref::new("WithDataClauseSegment").to_matchable(),
4455                    Ref::new("OrderByClauseSegment").to_matchable(),
4456                    Ref::new("LimitClauseSegment").to_matchable(),
4457                ])
4458                .config(|this| {
4459                    this.parse_mode(ParseMode::GreedyOnceStarted);
4460                })
4461                .to_matchable()
4462            })
4463            .to_matchable()
4464            .into(),
4465        ),
4466        (
4467            "OverlapsClauseSegment".into(),
4468            NodeMatcher::new(SyntaxKind::OverlapsClause, |_| {
4469                Sequence::new(vec![
4470                    Ref::keyword("OVERLAPS").to_matchable(),
4471                    one_of(vec![
4472                        Bracketed::new(vec![
4473                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
4474                            Ref::new("CommaSegment").to_matchable(),
4475                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
4476                        ])
4477                        .to_matchable(),
4478                        Ref::new("ColumnReferenceSegment").to_matchable(),
4479                    ])
4480                    .to_matchable(),
4481                ])
4482                .to_matchable()
4483            })
4484            .to_matchable()
4485            .into(),
4486        ),
4487        ("SelectClauseSegment".into(), {
4488            NodeMatcher::new(SyntaxKind::SelectClause, |_| select_clause_segment())
4489                .to_matchable()
4490                .into()
4491        }),
4492        (
4493            "StatementSegment".into(),
4494            NodeMatcher::new(SyntaxKind::Statement, |_| statement_segment())
4495                .to_matchable()
4496                .into(),
4497        ),
4498        (
4499            "WithNoSchemaBindingClauseSegment".into(),
4500            NodeMatcher::new(SyntaxKind::WithNoSchemaBindingClause, |_| {
4501                Sequence::new(vec![
4502                    Ref::keyword("WITH").to_matchable(),
4503                    Ref::keyword("NO").to_matchable(),
4504                    Ref::keyword("SCHEMA").to_matchable(),
4505                    Ref::keyword("BINDING").to_matchable(),
4506                ])
4507                .to_matchable()
4508            })
4509            .to_matchable()
4510            .into(),
4511        ),
4512        (
4513            "WithDataClauseSegment".into(),
4514            NodeMatcher::new(SyntaxKind::WithDataClause, |_| {
4515                Sequence::new(vec![
4516                    Ref::keyword("WITH").to_matchable(),
4517                    Sequence::new(vec![Ref::keyword("NO").to_matchable()])
4518                        .config(|this| this.optional())
4519                        .to_matchable(),
4520                    Ref::keyword("DATA").to_matchable(),
4521                ])
4522                .to_matchable()
4523            })
4524            .to_matchable()
4525            .into(),
4526        ),
4527        (
4528            "SetExpressionSegment".into(),
4529            NodeMatcher::new(SyntaxKind::SetExpression, |_| {
4530                Sequence::new(vec![
4531                    Ref::new("NonSetSelectableGrammar").to_matchable(),
4532                    AnyNumberOf::new(vec![
4533                        Sequence::new(vec![
4534                            Ref::new("SetOperatorSegment").to_matchable(),
4535                            Ref::new("NonSetSelectableGrammar").to_matchable(),
4536                        ])
4537                        .to_matchable(),
4538                    ])
4539                    .config(|this| this.min_times(1))
4540                    .to_matchable(),
4541                    Ref::new("OrderByClauseSegment").optional().to_matchable(),
4542                    Ref::new("LimitClauseSegment").optional().to_matchable(),
4543                    Ref::new("NamedWindowSegment").optional().to_matchable(),
4544                ])
4545                .to_matchable()
4546            })
4547            .to_matchable()
4548            .into(),
4549        ),
4550        (
4551            "FromClauseSegment".into(),
4552            NodeMatcher::new(SyntaxKind::FromClause, |_| {
4553                Sequence::new(vec![
4554                    Ref::keyword("FROM").to_matchable(),
4555                    Delimited::new(vec![Ref::new("FromExpressionSegment").to_matchable()])
4556                        .to_matchable(),
4557                ])
4558                .to_matchable()
4559            })
4560            .to_matchable()
4561            .into(),
4562        ),
4563        (
4564            "EmptyStructLiteralBracketsSegment".into(),
4565            NodeMatcher::new(SyntaxKind::EmptyStructLiteralBrackets, |_| {
4566                Bracketed::new(vec![]).to_matchable()
4567            })
4568            .to_matchable()
4569            .into(),
4570        ),
4571        (
4572            "WildcardExpressionSegment".into(),
4573            NodeMatcher::new(SyntaxKind::WildcardExpression, |_| {
4574                wildcard_expression_segment()
4575            })
4576            .to_matchable()
4577            .into(),
4578        ),
4579        (
4580            "OrderByClauseSegment".into(),
4581            NodeMatcher::new(SyntaxKind::OrderbyClause, |_| {
4582                Sequence::new(vec![
4583                    Ref::keyword("ORDER").to_matchable(),
4584                    Ref::keyword("BY").to_matchable(),
4585                    MetaSegment::indent().to_matchable(),
4586                    Delimited::new(vec![
4587                        Sequence::new(vec![
4588                            one_of(vec![
4589                                Ref::new("ColumnReferenceSegment").to_matchable(),
4590                                Ref::new("NumericLiteralSegment").to_matchable(),
4591                                Ref::new("ExpressionSegment").to_matchable(),
4592                            ])
4593                            .to_matchable(),
4594                            one_of(vec![
4595                                Ref::keyword("ASC").to_matchable(),
4596                                Ref::keyword("DESC").to_matchable(),
4597                            ])
4598                            .config(|this| this.optional())
4599                            .to_matchable(),
4600                            Sequence::new(vec![
4601                                Ref::keyword("NULLS").to_matchable(),
4602                                one_of(vec![
4603                                    Ref::keyword("FIRST").to_matchable(),
4604                                    Ref::keyword("LAST").to_matchable(),
4605                                ])
4606                                .to_matchable(),
4607                            ])
4608                            .config(|this| this.optional())
4609                            .to_matchable(),
4610                        ])
4611                        .to_matchable(),
4612                    ])
4613                    .config(|this| {
4614                        this.terminators = vec![
4615                            Ref::keyword("LIMIT").to_matchable(),
4616                            Ref::new("FrameClauseUnitGrammar").to_matchable(),
4617                        ]
4618                    })
4619                    .to_matchable(),
4620                    MetaSegment::dedent().to_matchable(),
4621                ])
4622                .to_matchable()
4623            })
4624            .to_matchable()
4625            .into(),
4626        ),
4627        (
4628            "TruncateStatementSegment".into(),
4629            NodeMatcher::new(SyntaxKind::TruncateStatement, |_| {
4630                Sequence::new(vec![
4631                    Ref::keyword("TRUNCATE").to_matchable(),
4632                    Ref::keyword("TABLE").optional().to_matchable(),
4633                    Ref::new("TableReferenceSegment").to_matchable(),
4634                ])
4635                .to_matchable()
4636            })
4637            .to_matchable()
4638            .into(),
4639        ),
4640        (
4641            "FromExpressionSegment".into(),
4642            NodeMatcher::new(SyntaxKind::FromExpression, |_| {
4643                optionally_bracketed(vec![
4644                    Sequence::new(vec![
4645                        MetaSegment::indent().to_matchable(),
4646                        one_of(vec![
4647                            Ref::new("FromExpressionElementSegment").to_matchable(),
4648                            Bracketed::new(vec![Ref::new("FromExpressionSegment").to_matchable()])
4649                                .to_matchable(),
4650                        ])
4651                        .config(|this| {
4652                            this.terminators = vec![
4653                                Sequence::new(vec![
4654                                    Ref::keyword("ORDER").to_matchable(),
4655                                    Ref::keyword("BY").to_matchable(),
4656                                ])
4657                                .to_matchable(),
4658                                Sequence::new(vec![
4659                                    Ref::keyword("GROUP").to_matchable(),
4660                                    Ref::keyword("BY").to_matchable(),
4661                                ])
4662                                .to_matchable(),
4663                            ]
4664                        })
4665                        .to_matchable(),
4666                        MetaSegment::dedent().to_matchable(),
4667                        Conditional::new(MetaSegment::indent())
4668                            .indented_joins()
4669                            .to_matchable(),
4670                        AnyNumberOf::new(vec![
4671                            Sequence::new(vec![
4672                                one_of(vec![
4673                                    Ref::new("JoinClauseSegment").to_matchable(),
4674                                    Ref::new("JoinLikeClauseGrammar").to_matchable(),
4675                                ])
4676                                .config(|this| {
4677                                    this.optional();
4678                                    this.terminators = vec![
4679                                        Sequence::new(vec![
4680                                            Ref::keyword("ORDER").to_matchable(),
4681                                            Ref::keyword("BY").to_matchable(),
4682                                        ])
4683                                        .to_matchable(),
4684                                        Sequence::new(vec![
4685                                            Ref::keyword("GROUP").to_matchable(),
4686                                            Ref::keyword("BY").to_matchable(),
4687                                        ])
4688                                        .to_matchable(),
4689                                    ];
4690                                })
4691                                .to_matchable(),
4692                            ])
4693                            .to_matchable(),
4694                        ])
4695                        .to_matchable(),
4696                        Conditional::new(MetaSegment::dedent())
4697                            .indented_joins()
4698                            .to_matchable(),
4699                    ])
4700                    .to_matchable(),
4701                ])
4702                .to_matchable()
4703            })
4704            .to_matchable()
4705            .into(),
4706        ),
4707        (
4708            "DatePartFunctionNameSegment".into(),
4709            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
4710                Ref::new("DatePartFunctionName").to_matchable()
4711            })
4712            .to_matchable()
4713            .into(),
4714        ),
4715        (
4716            "FromExpressionElementSegment".into(),
4717            NodeMatcher::new(SyntaxKind::FromExpressionElement, |_| {
4718                Sequence::new(vec![
4719                    Ref::new("PreTableFunctionKeywordsGrammar")
4720                        .optional()
4721                        .to_matchable(),
4722                    optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()])
4723                        .to_matchable(),
4724                    Ref::new("AliasExpressionSegment")
4725                        .exclude(one_of(vec![
4726                            Ref::new("FromClauseTerminatorGrammar").to_matchable(),
4727                            Ref::new("SamplingExpressionSegment").to_matchable(),
4728                            Ref::new("JoinLikeClauseGrammar").to_matchable(),
4729                            LookaheadExclude::new("WITH", "(").to_matchable(),
4730                        ]))
4731                        .optional()
4732                        .to_matchable(),
4733                    Sequence::new(vec![
4734                        Ref::keyword("WITH").to_matchable(),
4735                        Ref::keyword("OFFSET").to_matchable(),
4736                        Ref::new("AliasExpressionSegment").to_matchable(),
4737                    ])
4738                    .config(|this| this.optional())
4739                    .to_matchable(),
4740                    Ref::new("SamplingExpressionSegment")
4741                        .optional()
4742                        .to_matchable(),
4743                    Ref::new("PostTableExpressionGrammar")
4744                        .optional()
4745                        .to_matchable(),
4746                ])
4747                .to_matchable()
4748            })
4749            .to_matchable()
4750            .into(),
4751        ),
4752        (
4753            "SelectStatementSegment".into(),
4754            NodeMatcher::new(SyntaxKind::SelectStatement, |_| select_statement())
4755                .to_matchable()
4756                .into(),
4757        ),
4758        (
4759            "CreateSchemaStatementSegment".into(),
4760            NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_| {
4761                Sequence::new(vec![
4762                    Ref::keyword("CREATE").to_matchable(),
4763                    Ref::keyword("SCHEMA").to_matchable(),
4764                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
4765                    Ref::new("SchemaReferenceSegment").to_matchable(),
4766                ])
4767                .to_matchable()
4768            })
4769            .to_matchable()
4770            .into(),
4771        ),
4772        (
4773            "SelectClauseModifierSegment".into(),
4774            NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_| {
4775                one_of(vec![
4776                    Ref::keyword("DISTINCT").to_matchable(),
4777                    Ref::keyword("ALL").to_matchable(),
4778                ])
4779                .to_matchable()
4780            })
4781            .to_matchable()
4782            .into(),
4783        ),
4784        (
4785            "SelectClauseElementSegment".into(),
4786            NodeMatcher::new(SyntaxKind::SelectClauseElement, |_| select_clause_element())
4787                .to_matchable()
4788                .into(),
4789        ),
4790    ]);
4791
4792    // hookpoint
4793    ansi_dialect.add([(
4794        "CharCharacterSetGrammar".into(),
4795        Nothing::new().to_matchable().into(),
4796    )]);
4797
4798    // This is a hook point to allow subclassing for other dialects
4799    ansi_dialect.add([(
4800        "AliasedTableReferenceGrammar".into(),
4801        Sequence::new(vec![
4802            Ref::new("TableReferenceSegment").to_matchable(),
4803            Ref::new("AliasExpressionSegment").to_matchable(),
4804        ])
4805        .to_matchable()
4806        .into(),
4807    )]);
4808
4809    ansi_dialect.add([
4810        (
4811            "FunctionContentsSegment".into(),
4812            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
4813                Sequence::new(vec![
4814                    Bracketed::new(vec![Ref::new("FunctionContentsGrammar").to_matchable()])
4815                        .config(|this| this.optional())
4816                        .to_matchable(),
4817                ])
4818                .to_matchable()
4819            })
4820            .to_matchable()
4821            .into(),
4822        ),
4823        // FunctionContentsExpressionGrammar intended as a hook to override in other dialects.
4824        (
4825            "FunctionContentsExpressionGrammar".into(),
4826            Ref::new("ExpressionSegment").to_matchable().into(),
4827        ),
4828        (
4829            "FunctionContentsGrammar".into(),
4830            AnyNumberOf::new(vec![
4831                Ref::new("ExpressionSegment").to_matchable(),
4832                // A Cast-like function
4833                Sequence::new(vec![
4834                    Ref::new("ExpressionSegment").to_matchable(),
4835                    Ref::keyword("AS").to_matchable(),
4836                    Ref::new("DatatypeSegment").to_matchable(),
4837                ])
4838                .to_matchable(),
4839                // Trim function
4840                Sequence::new(vec![
4841                    Ref::new("TrimParametersGrammar").to_matchable(),
4842                    Ref::new("ExpressionSegment")
4843                        .optional()
4844                        .exclude(Ref::keyword("FROM"))
4845                        .to_matchable(),
4846                    Ref::keyword("FROM").to_matchable(),
4847                    Ref::new("ExpressionSegment").to_matchable(),
4848                ])
4849                .to_matchable(),
4850                // An extract-like or substring-like function
4851                Sequence::new(vec![
4852                    one_of(vec![
4853                        Ref::new("DatetimeUnitSegment").to_matchable(),
4854                        Ref::new("ExpressionSegment").to_matchable(),
4855                    ])
4856                    .to_matchable(),
4857                    Ref::keyword("FROM").to_matchable(),
4858                    Ref::new("ExpressionSegment").to_matchable(),
4859                ])
4860                .to_matchable(),
4861                Sequence::new(vec![
4862                    // Allow an optional distinct keyword here.
4863                    Ref::keyword("DISTINCT").optional().to_matchable(),
4864                    one_of(vec![
4865                        // For COUNT(*) or similar
4866                        Ref::new("StarSegment").to_matchable(),
4867                        Delimited::new(vec![
4868                            Ref::new("FunctionContentsExpressionGrammar").to_matchable(),
4869                        ])
4870                        .to_matchable(),
4871                    ])
4872                    .to_matchable(),
4873                ])
4874                .to_matchable(),
4875                Ref::new("AggregateOrderByClause").to_matchable(), // Used in various functions
4876                Sequence::new(vec![
4877                    Ref::keyword("SEPARATOR").to_matchable(),
4878                    Ref::new("LiteralGrammar").to_matchable(),
4879                ])
4880                .to_matchable(),
4881                // Position-like function
4882                Sequence::new(vec![
4883                    one_of(vec![
4884                        Ref::new("QuotedLiteralSegment").to_matchable(),
4885                        Ref::new("SingleIdentifierGrammar").to_matchable(),
4886                        Ref::new("ColumnReferenceSegment").to_matchable(),
4887                    ])
4888                    .to_matchable(),
4889                    Ref::keyword("IN").to_matchable(),
4890                    one_of(vec![
4891                        Ref::new("QuotedLiteralSegment").to_matchable(),
4892                        Ref::new("SingleIdentifierGrammar").to_matchable(),
4893                        Ref::new("ColumnReferenceSegment").to_matchable(),
4894                    ])
4895                    .to_matchable(),
4896                ])
4897                .to_matchable(),
4898                Ref::new("IgnoreRespectNullsGrammar").to_matchable(),
4899                Ref::new("IndexColumnDefinitionSegment").to_matchable(),
4900                Ref::new("EmptyStructLiteralSegment").to_matchable(),
4901            ])
4902            .to_matchable()
4903            .into(),
4904        ),
4905        (
4906            "PostFunctionGrammar".into(),
4907            one_of(vec![
4908                Ref::new("OverClauseSegment").to_matchable(),
4909                Ref::new("FilterClauseGrammar").to_matchable(),
4910            ])
4911            .to_matchable()
4912            .into(),
4913        ),
4914    ]);
4915
4916    // Assuming `ansi_dialect` is an instance of a struct representing a SQL dialect
4917    // and `add_grammar` is a method to add a new grammar rule to the dialect.
4918    ansi_dialect.add([(
4919        "JoinLikeClauseGrammar".into(),
4920        Nothing::new().to_matchable().into(),
4921    )]);
4922
4923    ansi_dialect.add([
4924        (
4925            "AccessStatementSegmentGrantRoleWithOptionGrammar".into(),
4926            one_of(vec![
4927                Sequence::new(vec![
4928                    Ref::keyword("WITH").to_matchable(),
4929                    Ref::keyword("GRANT").to_matchable(),
4930                    Ref::keyword("OPTION").to_matchable(),
4931                ])
4932                .to_matchable(),
4933                Sequence::new(vec![
4934                    Ref::keyword("WITH").to_matchable(),
4935                    Ref::keyword("ADMIN").to_matchable(),
4936                    Ref::keyword("OPTION").to_matchable(),
4937                ])
4938                .to_matchable(),
4939                Sequence::new(vec![
4940                    Ref::keyword("COPY").to_matchable(),
4941                    Ref::keyword("CURRENT").to_matchable(),
4942                    Ref::keyword("GRANTS").to_matchable(),
4943                ])
4944                .to_matchable(),
4945            ])
4946            .to_matchable()
4947            .into(),
4948        ),
4949        (
4950            // Expression_A_Grammar
4951            // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.html#a_expr
4952            // The upstream grammar is defined recursively, which if implemented naively
4953            // will cause SQLFluff to overflow the stack from recursive function calls.
4954            // To work around this, the a_expr grammar is reworked a bit into sub-grammars
4955            // that effectively provide tail recursion.
4956            "Expression_A_Unary_Operator_Grammar".into(),
4957            one_of(vec![
4958                // This grammar corresponds to the unary operator portion of the initial
4959                // recursive block on the Cockroach Labs a_expr grammar.
4960                Ref::new("SignedSegmentGrammar")
4961                    .exclude(Sequence::new(vec![
4962                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
4963                    ]))
4964                    .to_matchable(),
4965                Ref::new("TildeSegment").to_matchable(),
4966                Ref::new("NotOperatorGrammar").to_matchable(),
4967                // Used in CONNECT BY clauses (EXASOL, Snowflake, Postgres...)
4968                Ref::keyword("PRIOR").to_matchable(),
4969            ])
4970            .to_matchable()
4971            .into(),
4972        ),
4973        (
4974            "Tail_Recurse_Expression_A_Grammar".into(),
4975            Sequence::new(vec![
4976                // This should be used instead of a recursive call to Expression_A_Grammar
4977                // whenever the repeating element in Expression_A_Grammar makes a recursive
4978                // call to itself at the _end_.
4979                AnyNumberOf::new(vec![
4980                    Ref::new("Expression_A_Unary_Operator_Grammar").to_matchable(),
4981                ])
4982                .config(|this| {
4983                    this.terminators = vec![Ref::new("BinaryOperatorGrammar").to_matchable()]
4984                })
4985                .to_matchable(),
4986                Ref::new("Expression_C_Grammar").to_matchable(),
4987            ])
4988            .to_matchable()
4989            .into(),
4990        ),
4991        (
4992            "Expression_A_Grammar".into(),
4993            Sequence::new(vec![
4994                Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
4995                AnyNumberOf::new(vec![
4996                    one_of(vec![
4997                        // Like grammar with NOT and optional ESCAPE
4998                        Sequence::new(vec![
4999                            Sequence::new(vec![
5000                                Ref::keyword("NOT").optional().to_matchable(),
5001                                Ref::new("LikeGrammar").to_matchable(),
5002                            ])
5003                            .to_matchable(),
5004                            Ref::new("Expression_A_Grammar").to_matchable(),
5005                            Sequence::new(vec![
5006                                Ref::keyword("ESCAPE").to_matchable(),
5007                                Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
5008                            ])
5009                            .config(|this| this.optional())
5010                            .to_matchable(),
5011                        ])
5012                        .to_matchable(),
5013                        // Binary operator grammar
5014                        Sequence::new(vec![
5015                            Ref::new("BinaryOperatorGrammar").to_matchable(),
5016                            Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
5017                        ])
5018                        .to_matchable(),
5019                        // IN grammar
5020                        Ref::new("InOperatorGrammar").to_matchable(),
5021                        // IS grammar
5022                        Sequence::new(vec![
5023                            Ref::keyword("IS").to_matchable(),
5024                            Ref::keyword("NOT").optional().to_matchable(),
5025                            Ref::new("IsClauseGrammar").to_matchable(),
5026                        ])
5027                        .to_matchable(),
5028                        // IS NULL and NOT NULL grammars
5029                        Ref::new("IsNullGrammar").to_matchable(),
5030                        Ref::new("NotNullGrammar").to_matchable(),
5031                        // COLLATE grammar
5032                        Ref::new("CollateGrammar").to_matchable(),
5033                        // BETWEEN grammar
5034                        Sequence::new(vec![
5035                            Ref::keyword("NOT").optional().to_matchable(),
5036                            Ref::keyword("BETWEEN").to_matchable(),
5037                            Ref::new("Expression_B_Grammar").to_matchable(),
5038                            Ref::keyword("AND").to_matchable(),
5039                            Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(),
5040                        ])
5041                        .to_matchable(),
5042                        // Additional sequences and grammar rules can be added here
5043                    ])
5044                    .to_matchable(),
5045                ])
5046                .to_matchable(),
5047            ])
5048            .to_matchable()
5049            .into(),
5050        ),
5051        // Expression_B_Grammar: Does not directly feed into Expression_A_Grammar
5052        // but is used for a BETWEEN statement within Expression_A_Grammar.
5053        // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.htm#b_expr
5054        // We use a similar trick as seen with Expression_A_Grammar to avoid recursion
5055        // by using a tail recursion grammar.  See the comments for a_expr to see how
5056        // that works.
5057        (
5058            "Expression_B_Unary_Operator_Grammar".into(),
5059            one_of(vec![
5060                Ref::new("SignedSegmentGrammar")
5061                    .exclude(Sequence::new(vec![
5062                        Ref::new("QualifiedNumericLiteralSegment").to_matchable(),
5063                    ]))
5064                    .to_matchable(),
5065                Ref::new("TildeSegment").to_matchable(),
5066            ])
5067            .to_matchable()
5068            .into(),
5069        ),
5070        (
5071            "Tail_Recurse_Expression_B_Grammar".into(),
5072            Sequence::new(vec![
5073                // Only safe to use if the recursive call is at the END of the repeating
5074                // element in the main b_expr portion.
5075                AnyNumberOf::new(vec![
5076                    Ref::new("Expression_B_Unary_Operator_Grammar").to_matchable(),
5077                ])
5078                .to_matchable(),
5079                Ref::new("Expression_C_Grammar").to_matchable(),
5080            ])
5081            .to_matchable()
5082            .into(),
5083        ),
5084        (
5085            "Expression_B_Grammar".into(),
5086            Sequence::new(vec![
5087                // Always start with the tail recursion element
5088                Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(),
5089                AnyNumberOf::new(vec![
5090                    one_of(vec![
5091                        // Arithmetic, string, or comparison binary operators followed by tail
5092                        // recursion
5093                        Sequence::new(vec![
5094                            one_of(vec![
5095                                Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(),
5096                                Ref::new("StringBinaryOperatorGrammar").to_matchable(),
5097                                Ref::new("ComparisonOperatorGrammar").to_matchable(),
5098                            ])
5099                            .to_matchable(),
5100                            Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(),
5101                        ])
5102                        .to_matchable(),
5103                        // Additional sequences and rules from b_expr can be added here
5104                    ])
5105                    .to_matchable(),
5106                ])
5107                .to_matchable(),
5108            ])
5109            .to_matchable()
5110            .into(),
5111        ),
5112        (
5113            "Expression_C_Grammar".into(),
5114            one_of(vec![
5115                // Sequence for "EXISTS" with a bracketed selectable grammar
5116                Sequence::new(vec![
5117                    Ref::keyword("EXISTS").to_matchable(),
5118                    Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()])
5119                        .to_matchable(),
5120                ])
5121                .to_matchable(),
5122                // Sequence for Expression_D_Grammar or CaseExpressionSegment
5123                // followed by any number of TimeZoneGrammar
5124                Sequence::new(vec![
5125                    one_of(vec![
5126                        Ref::new("Expression_D_Grammar").to_matchable(),
5127                        Ref::new("CaseExpressionSegment").to_matchable(),
5128                    ])
5129                    .to_matchable(),
5130                    AnyNumberOf::new(vec![Ref::new("TimeZoneGrammar").to_matchable()])
5131                        .config(|this| this.optional())
5132                        .to_matchable(),
5133                ])
5134                .to_matchable(),
5135                Ref::new("ShorthandCastSegment").to_matchable(),
5136            ])
5137            .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()])
5138            .to_matchable()
5139            .into(),
5140        ),
5141        (
5142            "Expression_D_Grammar".into(),
5143            Sequence::new(vec![
5144                one_of(vec![
5145                    Ref::new("BareFunctionSegment").to_matchable(),
5146                    Ref::new("FunctionSegment").to_matchable(),
5147                    Bracketed::new(vec![
5148                        one_of(vec![
5149                            Ref::new("ExpressionSegment").to_matchable(),
5150                            Ref::new("SelectableGrammar").to_matchable(),
5151                            Delimited::new(vec![
5152                                Ref::new("ColumnReferenceSegment").to_matchable(),
5153                                Ref::new("FunctionSegment").to_matchable(),
5154                                Ref::new("LiteralGrammar").to_matchable(),
5155                                Ref::new("LocalAliasSegment").to_matchable(),
5156                            ])
5157                            .to_matchable(),
5158                        ])
5159                        .to_matchable(),
5160                    ])
5161                    .config(|this| this.parse_mode(ParseMode::Greedy))
5162                    .to_matchable(),
5163                    Ref::new("SelectStatementSegment").to_matchable(),
5164                    Ref::new("LiteralGrammar").to_matchable(),
5165                    Ref::new("IntervalExpressionSegment").to_matchable(),
5166                    Ref::new("TypedStructLiteralSegment").to_matchable(),
5167                    Ref::new("ArrayExpressionSegment").to_matchable(),
5168                    Ref::new("ColumnReferenceSegment").to_matchable(),
5169                    Sequence::new(vec![
5170                        Ref::new("SingleIdentifierGrammar").to_matchable(),
5171                        Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(),
5172                        Ref::new("StarSegment").to_matchable(),
5173                    ])
5174                    .to_matchable(),
5175                    Sequence::new(vec![
5176                        Ref::new("StructTypeSegment").to_matchable(),
5177                        Bracketed::new(vec![
5178                            Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
5179                                .to_matchable(),
5180                        ])
5181                        .to_matchable(),
5182                    ])
5183                    .to_matchable(),
5184                    Sequence::new(vec![
5185                        Ref::new("DatatypeSegment").to_matchable(),
5186                        one_of(vec![
5187                            Ref::new("QuotedLiteralSegment").to_matchable(),
5188                            Ref::new("NumericLiteralSegment").to_matchable(),
5189                            Ref::new("BooleanLiteralGrammar").to_matchable(),
5190                            Ref::new("NullLiteralSegment").to_matchable(),
5191                            Ref::new("DateTimeLiteralGrammar").to_matchable(),
5192                        ])
5193                        .to_matchable(),
5194                    ])
5195                    .to_matchable(),
5196                    Ref::new("LocalAliasSegment").to_matchable(),
5197                ])
5198                .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()])
5199                .to_matchable(),
5200                Ref::new("AccessorGrammar").optional().to_matchable(),
5201            ])
5202            .allow_gaps(true)
5203            .to_matchable()
5204            .into(),
5205        ),
5206        (
5207            "AccessorGrammar".into(),
5208            AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()])
5209                .to_matchable()
5210                .into(),
5211        ),
5212    ]);
5213
5214    ansi_dialect.add([
5215        (
5216            "SelectableGrammar".into(),
5217            one_of(vec![
5218                optionally_bracketed(vec![
5219                    Ref::new("WithCompoundStatementSegment").to_matchable(),
5220                ])
5221                .to_matchable(),
5222                Ref::new("NonWithSelectableGrammar").to_matchable(),
5223                Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
5224            ])
5225            .to_matchable()
5226            .into(),
5227        ),
5228        (
5229            "NonWithSelectableGrammar".into(),
5230            one_of(vec![
5231                Ref::new("SetExpressionSegment").to_matchable(),
5232                optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()])
5233                    .to_matchable(),
5234                Ref::new("NonSetSelectableGrammar").to_matchable(),
5235            ])
5236            .to_matchable()
5237            .into(),
5238        ),
5239        // NOTE: In ANSI SQL, CTEs (WITH clause) can only precede SELECT statements,
5240        // not DML statements like INSERT/UPDATE/DELETE. This grammar is kept as a
5241        // hook point for dialects that support CTE+DML (e.g., PostgreSQL, SQL Server,
5242        // SQLite). Those dialects should either:
5243        // 1. Add DML statements to NonWithSelectableGrammar (like PostgreSQL), or
5244        // 2. Add WithCompoundNonSelectStatementSegment to their SelectableGrammar
5245        (
5246            "NonWithNonSelectableGrammar".into(),
5247            Nothing::new().to_matchable().into(),
5248        ),
5249        (
5250            "NonSetSelectableGrammar".into(),
5251            one_of(vec![
5252                Ref::new("ValuesClauseSegment").to_matchable(),
5253                Ref::new("UnorderedSelectStatementSegment").to_matchable(),
5254                Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()])
5255                    .to_matchable(),
5256                Bracketed::new(vec![
5257                    Ref::new("WithCompoundStatementSegment").to_matchable(),
5258                ])
5259                .to_matchable(),
5260                Bracketed::new(vec![Ref::new("NonSetSelectableGrammar").to_matchable()])
5261                    .to_matchable(),
5262            ])
5263            .to_matchable()
5264            .into(),
5265        ),
5266    ]);
5267
5268    // This is a hook point to allow subclassing for other dialects
5269    ansi_dialect.add([
5270        (
5271            "PostTableExpressionGrammar".into(),
5272            Nothing::new().to_matchable().into(),
5273        ),
5274        (
5275            "BracketedSegment".into(),
5276            BracketedSegmentMatcher::new().to_matchable().into(),
5277        ),
5278        (
5279            "TimeWithTZGrammar".into(),
5280            Sequence::new(vec![
5281                one_of(vec![
5282                    Ref::keyword("TIME").to_matchable(),
5283                    Ref::keyword("TIMESTAMP").to_matchable(),
5284                ])
5285                .to_matchable(),
5286                Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()])
5287                    .config(|this| this.optional())
5288                    .to_matchable(),
5289                Sequence::new(vec![
5290                    one_of(vec![
5291                        Ref::keyword("WITH").to_matchable(),
5292                        Ref::keyword("WITHOUT").to_matchable(),
5293                    ])
5294                    .to_matchable(),
5295                    Ref::keyword("TIME").to_matchable(),
5296                    Ref::keyword("ZONE").to_matchable(),
5297                ])
5298                .config(|this| this.optional())
5299                .to_matchable(),
5300            ])
5301            .to_matchable()
5302            .into(),
5303        ),
5304    ]);
5305
5306    ansi_dialect
5307}
5308
5309pub fn select_clause_element() -> Matchable {
5310    one_of(vec![
5311        // *, blah.*, blah.blah.*, etc.
5312        Ref::new("WildcardExpressionSegment").to_matchable(),
5313        Sequence::new(vec![
5314            Ref::new("BaseExpressionElementGrammar").to_matchable(),
5315            Ref::new("AliasExpressionSegment").optional().to_matchable(),
5316        ])
5317        .to_matchable(),
5318    ])
5319    .to_matchable()
5320}
5321
5322fn lexer_matchers() -> Vec<Matcher> {
5323    vec![
5324        Matcher::regex("whitespace", r"[^\S\r\n]+", SyntaxKind::Whitespace),
5325        Matcher::regex("inline_comment", r"(--|#)[^\n]*", SyntaxKind::InlineComment),
5326        Matcher::native("block_comment", block_comment, SyntaxKind::BlockComment)
5327            .subdivider(Pattern::legacy(
5328                "newline",
5329                |_| true,
5330                r"\r\n|\n",
5331                SyntaxKind::Newline,
5332            ))
5333            .post_subdivide(Pattern::legacy(
5334                "whitespace",
5335                |_| true,
5336                r"[^\S\r\n]+",
5337                SyntaxKind::Whitespace,
5338            )),
5339        Matcher::regex(
5340            "single_quote",
5341            r"'([^'\\]|\\.|'')*'",
5342            SyntaxKind::SingleQuote,
5343        ),
5344        Matcher::regex(
5345            "double_quote",
5346            r#""([^"\\]|\\.)*""#,
5347            SyntaxKind::DoubleQuote,
5348        ),
5349        Matcher::regex("back_quote", r"`[^`]*`", SyntaxKind::BackQuote),
5350        Matcher::legacy(
5351            "dollar_quote",
5352            |s| s.starts_with("$"),
5353            r"\$(\w*)\$[\s\S]*?\$\1\$",
5354            SyntaxKind::DollarQuote,
5355        ),
5356        Matcher::native(
5357            "numeric_literal",
5358            numeric_literal,
5359            SyntaxKind::NumericLiteral,
5360        ),
5361        Matcher::regex("like_operator", r"!?~~?\*?", SyntaxKind::LikeOperator),
5362        Matcher::regex("newline", r"(\r\n|\n)", SyntaxKind::Newline),
5363        Matcher::string("casting_operator", "::", SyntaxKind::CastingOperator),
5364        Matcher::string("equals", "=", SyntaxKind::RawComparisonOperator),
5365        Matcher::string("greater_than", ">", SyntaxKind::RawComparisonOperator),
5366        Matcher::string("less_than", "<", SyntaxKind::RawComparisonOperator),
5367        Matcher::string("not", "!", SyntaxKind::RawComparisonOperator),
5368        Matcher::string("dot", ".", SyntaxKind::Dot),
5369        Matcher::string("comma", ",", SyntaxKind::Comma),
5370        Matcher::string("plus", "+", SyntaxKind::Plus),
5371        Matcher::string("minus", "-", SyntaxKind::Minus),
5372        Matcher::string("divide", "/", SyntaxKind::Divide),
5373        Matcher::string("percent", "%", SyntaxKind::Percent),
5374        Matcher::string("question", "?", SyntaxKind::Question),
5375        Matcher::string("ampersand", "&", SyntaxKind::Ampersand),
5376        Matcher::string("vertical_bar", "|", SyntaxKind::VerticalBar),
5377        Matcher::string("caret", "^", SyntaxKind::Caret),
5378        Matcher::string("star", "*", SyntaxKind::Star),
5379        Matcher::string("start_bracket", "(", SyntaxKind::StartBracket),
5380        Matcher::string("end_bracket", ")", SyntaxKind::EndBracket),
5381        Matcher::string("start_square_bracket", "[", SyntaxKind::StartSquareBracket),
5382        Matcher::string("end_square_bracket", "]", SyntaxKind::EndSquareBracket),
5383        Matcher::string("start_curly_bracket", "{", SyntaxKind::StartCurlyBracket),
5384        Matcher::string("end_curly_bracket", "}", SyntaxKind::EndCurlyBracket),
5385        Matcher::string("colon", ":", SyntaxKind::Colon),
5386        Matcher::string("semicolon", ";", SyntaxKind::Semicolon),
5387        Matcher::regex("word", "[0-9a-zA-Z_]+", SyntaxKind::Word),
5388    ]
5389}
5390
5391pub fn frame_extent() -> AnyNumberOf {
5392    one_of(vec![
5393        Sequence::new(vec![
5394            Ref::keyword("CURRENT").to_matchable(),
5395            Ref::keyword("ROW").to_matchable(),
5396        ])
5397        .to_matchable(),
5398        Sequence::new(vec![
5399            one_of(vec![
5400                Ref::new("NumericLiteralSegment").to_matchable(),
5401                Sequence::new(vec![
5402                    Ref::keyword("INTERVAL").to_matchable(),
5403                    Ref::new("QuotedLiteralSegment").to_matchable(),
5404                ])
5405                .to_matchable(),
5406                Ref::keyword("UNBOUNDED").to_matchable(),
5407            ])
5408            .to_matchable(),
5409            one_of(vec![
5410                Ref::keyword("PRECEDING").to_matchable(),
5411                Ref::keyword("FOLLOWING").to_matchable(),
5412            ])
5413            .to_matchable(),
5414        ])
5415        .to_matchable(),
5416    ])
5417}
5418
5419pub fn explainable_stmt() -> AnyNumberOf {
5420    one_of(vec![
5421        Ref::new("SelectableGrammar").to_matchable(),
5422        Ref::new("InsertStatementSegment").to_matchable(),
5423        Ref::new("UpdateStatementSegment").to_matchable(),
5424        Ref::new("DeleteStatementSegment").to_matchable(),
5425    ])
5426}
5427
5428pub fn get_unordered_select_statement_segment_grammar() -> Matchable {
5429    Sequence::new(vec![
5430        Ref::new("SelectClauseSegment").to_matchable(),
5431        MetaSegment::dedent().to_matchable(),
5432        Ref::new("FromClauseSegment").optional().to_matchable(),
5433        Ref::new("WhereClauseSegment").optional().to_matchable(),
5434        Ref::new("GroupByClauseSegment").optional().to_matchable(),
5435        Ref::new("HavingClauseSegment").optional().to_matchable(),
5436        Ref::new("OverlapsClauseSegment").optional().to_matchable(),
5437        Ref::new("NamedWindowSegment").optional().to_matchable(),
5438    ])
5439    .terminators(vec![
5440        Ref::new("SetOperatorSegment").to_matchable(),
5441        Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
5442        Ref::new("WithDataClauseSegment").to_matchable(),
5443        Ref::new("OrderByClauseSegment").to_matchable(),
5444        Ref::new("LimitClauseSegment").to_matchable(),
5445    ])
5446    .config(|this| {
5447        this.parse_mode(ParseMode::GreedyOnceStarted);
5448    })
5449    .to_matchable()
5450}
5451
5452pub fn select_statement() -> Matchable {
5453    get_unordered_select_statement_segment_grammar().copy(
5454        Some(vec![
5455            Ref::new("OrderByClauseSegment").optional().to_matchable(),
5456            Ref::new("FetchClauseSegment").optional().to_matchable(),
5457            Ref::new("LimitClauseSegment").optional().to_matchable(),
5458            Ref::new("NamedWindowSegment").optional().to_matchable(),
5459        ]),
5460        None,
5461        None,
5462        None,
5463        vec![
5464            Ref::new("SetOperatorSegment").to_matchable(),
5465            Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(),
5466            Ref::new("WithDataClauseSegment").to_matchable(),
5467        ],
5468        true,
5469    )
5470}
5471
5472pub fn select_clause_segment() -> Matchable {
5473    Sequence::new(vec![
5474        Ref::keyword("SELECT").to_matchable(),
5475        Ref::new("SelectClauseModifierSegment")
5476            .optional()
5477            .to_matchable(),
5478        MetaSegment::indent().to_matchable(),
5479        Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()])
5480            .config(|this| this.allow_trailing())
5481            .to_matchable(),
5482    ])
5483    .terminators(vec![
5484        Ref::new("SelectClauseTerminatorGrammar").to_matchable(),
5485    ])
5486    .config(|this| {
5487        this.parse_mode(ParseMode::GreedyOnceStarted);
5488    })
5489    .to_matchable()
5490}
5491
5492pub fn statement_segment() -> Matchable {
5493    one_of(vec![
5494        Ref::new("SelectableGrammar").to_matchable(),
5495        Ref::new("MergeStatementSegment").to_matchable(),
5496        Ref::new("InsertStatementSegment").to_matchable(),
5497        Ref::new("TransactionStatementSegment").to_matchable(),
5498        Ref::new("DropTableStatementSegment").to_matchable(),
5499        Ref::new("DropViewStatementSegment").to_matchable(),
5500        Ref::new("CreateUserStatementSegment").to_matchable(),
5501        Ref::new("DropUserStatementSegment").to_matchable(),
5502        Ref::new("TruncateStatementSegment").to_matchable(),
5503        Ref::new("AccessStatementSegment").to_matchable(),
5504        Ref::new("CreateTableStatementSegment").to_matchable(),
5505        Ref::new("CreateRoleStatementSegment").to_matchable(),
5506        Ref::new("DropRoleStatementSegment").to_matchable(),
5507        Ref::new("AlterTableStatementSegment").to_matchable(),
5508        Ref::new("CreateSchemaStatementSegment").to_matchable(),
5509        Ref::new("SetSchemaStatementSegment").to_matchable(),
5510        Ref::new("DropSchemaStatementSegment").to_matchable(),
5511        Ref::new("DropTypeStatementSegment").to_matchable(),
5512        Ref::new("CreateDatabaseStatementSegment").to_matchable(),
5513        Ref::new("DropDatabaseStatementSegment").to_matchable(),
5514        Ref::new("CreateIndexStatementSegment").to_matchable(),
5515        Ref::new("DropIndexStatementSegment").to_matchable(),
5516        Ref::new("CreateViewStatementSegment").to_matchable(),
5517        Ref::new("DeleteStatementSegment").to_matchable(),
5518        Ref::new("UpdateStatementSegment").to_matchable(),
5519        Ref::new("CreateCastStatementSegment").to_matchable(),
5520        Ref::new("DropCastStatementSegment").to_matchable(),
5521        Ref::new("CreateFunctionStatementSegment").to_matchable(),
5522        Ref::new("DropFunctionStatementSegment").to_matchable(),
5523        Ref::new("CreateModelStatementSegment").to_matchable(),
5524        Ref::new("DropModelStatementSegment").to_matchable(),
5525        Ref::new("DescribeStatementSegment").to_matchable(),
5526        Ref::new("UseStatementSegment").to_matchable(),
5527        Ref::new("ExplainStatementSegment").to_matchable(),
5528        Ref::new("CreateSequenceStatementSegment").to_matchable(),
5529        Ref::new("AlterSequenceStatementSegment").to_matchable(),
5530        Ref::new("DropSequenceStatementSegment").to_matchable(),
5531        Ref::new("CreateTriggerStatementSegment").to_matchable(),
5532        Ref::new("DropTriggerStatementSegment").to_matchable(),
5533    ])
5534    .config(|this| this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()])
5535    .to_matchable()
5536}
5537
5538pub fn wildcard_expression_segment() -> Matchable {
5539    Sequence::new(vec![Ref::new("WildcardIdentifierSegment").to_matchable()]).to_matchable()
5540}
5541
5542fn numeric_literal(cursor: &mut Cursor) -> bool {
5543    let first_char = cursor.shift();
5544    match first_char {
5545        '0'..='9' | '.' => {
5546            let has_decimal = first_char == '.';
5547
5548            if has_decimal {
5549                if cursor.peek().is_ascii_digit() {
5550                    cursor.shift_while(|c| c.is_ascii_digit());
5551                } else {
5552                    return false;
5553                }
5554            } else {
5555                cursor.shift_while(|c| c.is_ascii_digit());
5556                if cursor.peek() == '.' {
5557                    cursor.shift();
5558                    cursor.shift_while(|c| c.is_ascii_digit());
5559                }
5560            }
5561
5562            if let 'e' | 'E' = cursor.peek() {
5563                cursor.shift();
5564                if let '+' | '-' = cursor.peek() {
5565                    cursor.shift();
5566                }
5567                let mut exp_digits = false;
5568                while cursor.peek().is_ascii_digit() {
5569                    cursor.shift();
5570                    exp_digits = true;
5571                }
5572                if !exp_digits {
5573                    return false;
5574                }
5575            }
5576
5577            let next_char = cursor.peek();
5578            if next_char == '.' || next_char.is_ascii_alphanumeric() || next_char == '_' {
5579                return false;
5580            }
5581
5582            true
5583        }
5584        _ => false,
5585    }
5586}
5587
5588fn block_comment(cursor: &mut Cursor) -> bool {
5589    if cursor.shift() != '/' {
5590        return false;
5591    }
5592
5593    if cursor.shift() != '*' {
5594        return false;
5595    }
5596
5597    let mut depth = 1usize;
5598
5599    loop {
5600        match cursor.shift() {
5601            '\0' => return false,
5602            '/' if cursor.peek() == '*' => {
5603                cursor.shift();
5604                depth += 1;
5605            }
5606            '*' if cursor.peek() == '/' => {
5607                cursor.shift();
5608                depth -= 1;
5609                if depth == 0 {
5610                    break true;
5611                }
5612            }
5613            _ => {}
5614        }
5615    }
5616}
5617
5618pub(crate) fn select_clause_terminators() -> Vec<Matchable> {
5619    vec![
5620        Ref::keyword("FROM").to_matchable(),
5621        Ref::keyword("WHERE").to_matchable(),
5622        Sequence::new(vec![
5623            Ref::keyword("ORDER").to_matchable(),
5624            Ref::keyword("BY").to_matchable(),
5625        ])
5626        .to_matchable(),
5627        Ref::keyword("LIMIT").to_matchable(),
5628        Ref::keyword("OVERLAPS").to_matchable(),
5629        Ref::new("SetOperatorSegment").to_matchable(),
5630        Ref::keyword("FETCH").to_matchable(),
5631    ]
5632}