Skip to main content

sqruff_lib_dialects/
bigquery.rs

1use itertools::Itertools;
2use sqruff_lib_core::dialects::Dialect;
3use sqruff_lib_core::dialects::init::DialectKind;
4use sqruff_lib_core::dialects::syntax::SyntaxKind;
5use sqruff_lib_core::helpers::{Config, ToMatchable};
6use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed};
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::Matcher;
11use sqruff_lib_core::parser::matchable::MatchableTrait;
12use sqruff_lib_core::parser::node_matcher::NodeMatcher;
13use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser};
14use sqruff_lib_core::parser::segments::generator::SegmentGenerator;
15use sqruff_lib_core::parser::segments::meta::MetaSegment;
16use sqruff_lib_core::parser::types::ParseMode;
17
18use super::ansi::{self, raw_dialect};
19use super::bigquery_keywords::{BIGQUERY_RESERVED_KEYWORDS, BIGQUERY_UNRESERVED_KEYWORDS};
20use sqruff_lib_core::dialects::init::DialectConfig;
21use sqruff_lib_core::value::Value;
22
23sqruff_lib_core::dialect_config!(BigQueryDialectConfig {});
24
25pub fn dialect(config: Option<&Value>) -> Dialect {
26    // Parse and validate dialect configuration, falling back to defaults on failure
27    let _dialect_config: BigQueryDialectConfig = config
28        .map(BigQueryDialectConfig::from_value)
29        .unwrap_or_default();
30    let mut dialect = raw_dialect();
31    dialect.name = DialectKind::Bigquery;
32
33    dialect.insert_lexer_matchers(
34        vec![
35            Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow),
36            Matcher::string("question_mark", "?", SyntaxKind::QuestionMark),
37            Matcher::regex(
38                "at_sign_literal",
39                r"@[a-zA-Z_][\w]*",
40                SyntaxKind::AtSignLiteral,
41            ),
42        ],
43        "equals",
44    );
45
46    dialect.patch_lexer_matchers(vec![
47        Matcher::legacy(
48            "single_quote",
49            |s| s.starts_with(['\'', 'R', 'r', 'B', 'b'].as_ref()),
50            r"([rR]?[bB]?|[bB]?[rR]?)?('''((?<!\\)(\\{2})*\\'|'{,2}(?!')|[^'])*(?<!\\)(\\{2})*'''|'((?<!\\)(\\{2})*\\'|[^'])*(?<!\\)(\\{2})*')",
51            SyntaxKind::SingleQuote
52        ),
53        Matcher::legacy(
54            "double_quote",
55            |s| s.starts_with(['"', 'R', 'r', 'B', 'b']),
56            r#"([rR]?[bB]?|[bB]?[rR]?)?(\"\"\"((?<!\\)(\\{2})*\\\"|\"{,2}(?!\")|[^\"])*(?<!\\)(\\{2})*\"\"\"|"((?<!\\)(\\{2})*\\"|[^"])*(?<!\\)(\\{2})*")"#,
57            SyntaxKind::DoubleQuote
58        ),
59    ]);
60
61    // BigQuery supports CTEs with DML statements (INSERT, UPDATE, DELETE, MERGE)
62    // We add these to NonWithSelectableGrammar so WithCompoundStatementSegment can use them
63    dialect.add([(
64        "NonWithSelectableGrammar".into(),
65        one_of(vec![
66            Ref::new("SetExpressionSegment").to_matchable(),
67            optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()])
68                .to_matchable(),
69            Ref::new("NonSetSelectableGrammar").to_matchable(),
70            Ref::new("UpdateStatementSegment").to_matchable(),
71            Ref::new("InsertStatementSegment").to_matchable(),
72            Ref::new("DeleteStatementSegment").to_matchable(),
73            Ref::new("MergeStatementSegment").to_matchable(),
74        ])
75        .to_matchable()
76        .into(),
77    )]);
78
79    dialect.add([
80        (
81            "DoubleQuotedLiteralSegment".into(),
82            TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral)
83                .to_matchable()
84                .into(),
85        ),
86        (
87            "SingleQuotedLiteralSegment".into(),
88            TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral)
89                .to_matchable()
90                .into(),
91        ),
92        (
93            "DoubleQuotedUDFBody".into(),
94            TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::UdfBody)
95                .to_matchable()
96                .into(),
97        ),
98        (
99            "SingleQuotedUDFBody".into(),
100            TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::UdfBody)
101                .to_matchable()
102                .into(),
103        ),
104        (
105            "StartAngleBracketSegment".into(),
106            StringParser::new("<", SyntaxKind::StartAngleBracket)
107                .to_matchable()
108                .into(),
109        ),
110        (
111            "EndAngleBracketSegment".into(),
112            StringParser::new(">", SyntaxKind::EndAngleBracket)
113                .to_matchable()
114                .into(),
115        ),
116        (
117            "RightArrowSegment".into(),
118            StringParser::new("=>", SyntaxKind::RightArrow)
119                .to_matchable()
120                .into(),
121        ),
122        (
123            "DashSegment".into(),
124            StringParser::new("-", SyntaxKind::Dash)
125                .to_matchable()
126                .into(),
127        ),
128        (
129            "SingleIdentifierFullGrammar".into(),
130            one_of(vec![
131                Ref::new("NakedIdentifierSegment").to_matchable(),
132                Ref::new("QuotedIdentifierSegment").to_matchable(),
133                Ref::new("NakedIdentifierFullSegment").to_matchable(),
134            ])
135            .to_matchable()
136            .into(),
137        ),
138        (
139            "QuestionMarkSegment".into(),
140            StringParser::new("?", SyntaxKind::QuestionMark)
141                .to_matchable()
142                .into(),
143        ),
144        (
145            "AtSignLiteralSegment".into(),
146            TypedParser::new(SyntaxKind::AtSignLiteral, SyntaxKind::AtSignLiteral)
147                .to_matchable()
148                .into(),
149        ),
150        (
151            "DefaultDeclareOptionsGrammar".into(),
152            Sequence::new(vec![
153                Ref::keyword("DEFAULT").to_matchable(),
154                one_of(vec![
155                    Ref::new("LiteralGrammar").to_matchable(),
156                    Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()])
157                        .to_matchable(),
158                    Ref::new("BareFunctionSegment").to_matchable(),
159                    Ref::new("FunctionSegment").to_matchable(),
160                    Ref::new("ArrayLiteralSegment").to_matchable(),
161                    Ref::new("TupleSegment").to_matchable(),
162                    Ref::new("BaseExpressionElementGrammar").to_matchable(),
163                ])
164                .config(|this| {
165                    this.terminators = vec![Ref::new("SemicolonSegment").to_matchable()];
166                })
167                .to_matchable(),
168            ])
169            .to_matchable()
170            .into(),
171        ),
172        (
173            "ExtendedDatetimeUnitSegment".into(),
174            SegmentGenerator::new(|dialect| {
175                MultiStringParser::new(
176                    dialect
177                        .sets("extended_datetime_units")
178                        .into_iter()
179                        .map_into()
180                        .collect_vec(),
181                    SyntaxKind::DatePart,
182                )
183                .to_matchable()
184            })
185            .into(),
186        ),
187        (
188            "NakedIdentifierFullSegment".into(),
189            RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::NakedIdentifierAll)
190                .to_matchable()
191                .into(),
192        ),
193        (
194            "NakedIdentifierPart".into(),
195            RegexParser::new("[A-Z0-9_]+", SyntaxKind::NakedIdentifier)
196                .to_matchable()
197                .into(),
198        ),
199        (
200            "ProcedureNameIdentifierSegment".into(),
201            one_of(vec![
202                RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::ProcedureNameIdentifier)
203                    .anti_template("STRUCT")
204                    .to_matchable(),
205                RegexParser::new("`[^`]*`", SyntaxKind::ProcedureNameIdentifier).to_matchable(),
206            ])
207            .to_matchable()
208            .into(),
209        ),
210        (
211            "ProcedureParameterGrammar".into(),
212            one_of(vec![
213                Sequence::new(vec![
214                    one_of(vec![
215                        Ref::keyword("IN").to_matchable(),
216                        Ref::keyword("OUT").to_matchable(),
217                        Ref::keyword("INOUT").to_matchable(),
218                    ])
219                    .config(|this| this.optional())
220                    .to_matchable(),
221                    Ref::new("ParameterNameSegment").optional().to_matchable(),
222                    one_of(vec![
223                        Sequence::new(vec![
224                            Ref::keyword("ANY").to_matchable(),
225                            Ref::keyword("TYPE").to_matchable(),
226                        ])
227                        .to_matchable(),
228                        Ref::new("DatatypeSegment").to_matchable(),
229                    ])
230                    .to_matchable(),
231                ])
232                .to_matchable(),
233                one_of(vec![
234                    Sequence::new(vec![
235                        Ref::keyword("ANY").to_matchable(),
236                        Ref::keyword("TYPE").to_matchable(),
237                    ])
238                    .to_matchable(),
239                    Ref::new("DatatypeSegment").to_matchable(),
240                ])
241                .to_matchable(),
242            ])
243            .to_matchable()
244            .into(),
245        ),
246    ]);
247
248    dialect.add([
249        (
250            "NakedIdentifierSegment".into(),
251            SegmentGenerator::new(|dialect| {
252                // Generate the anti template from the set of reserved keywords
253                let reserved_keywords = dialect.sets("reserved_keywords");
254                let pattern = reserved_keywords.iter().join("|");
255                let anti_template = format!("^({pattern})$");
256
257                RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::NakedIdentifier)
258                    .anti_template(&anti_template)
259                    .to_matchable()
260            })
261            .into(),
262        ),
263        (
264            "FunctionContentsExpressionGrammar".into(),
265            one_of(vec![
266                Ref::new("DatetimeUnitSegment").to_matchable(),
267                Ref::new("DatePartWeekSegment").to_matchable(),
268                Sequence::new(vec![
269                    Ref::new("ExpressionSegment").to_matchable(),
270                    Sequence::new(vec![
271                        one_of(vec![
272                            Ref::keyword("IGNORE").to_matchable(),
273                            Ref::keyword("RESPECT").to_matchable(),
274                        ])
275                        .to_matchable(),
276                        Ref::keyword("NULLS").to_matchable(),
277                    ])
278                    .config(|this| this.optional())
279                    .to_matchable(),
280                ])
281                .to_matchable(),
282                Sequence::new(vec![
283                    Ref::new("ExpressionSegment").to_matchable(),
284                    Ref::keyword("HAVING").to_matchable(),
285                    one_of(vec![
286                        Ref::keyword("MIN").to_matchable(),
287                        Ref::keyword("MAX").to_matchable(),
288                    ])
289                    .to_matchable(),
290                    Ref::new("ExpressionSegment").to_matchable(),
291                ])
292                .to_matchable(),
293                Ref::new("NamedArgumentSegment").to_matchable(),
294            ])
295            .to_matchable()
296            .into(),
297        ),
298        (
299            "TrimParametersGrammar".into(),
300            Nothing::new().to_matchable().into(),
301        ),
302        (
303            "ParameterNameSegment".into(),
304            one_of(vec![
305                RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::Parameter).to_matchable(),
306                RegexParser::new("`[^`]*`", SyntaxKind::Parameter).to_matchable(),
307            ])
308            .to_matchable()
309            .into(),
310        ),
311        (
312            "DateTimeLiteralGrammar".into(),
313            Sequence::new(vec![
314                one_of(vec![
315                    Ref::keyword("DATE").to_matchable(),
316                    Ref::keyword("DATETIME").to_matchable(),
317                    Ref::keyword("TIME").to_matchable(),
318                    Ref::keyword("TIMESTAMP").to_matchable(),
319                ])
320                .to_matchable(),
321                TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral)
322                    .to_matchable(),
323            ])
324            .to_matchable()
325            .into(),
326        ),
327        (
328            "JoinLikeClauseGrammar".into(),
329            Sequence::new(vec![
330                AnyNumberOf::new(vec![
331                    Ref::new("FromPivotExpressionSegment").to_matchable(),
332                    Ref::new("FromUnpivotExpressionSegment").to_matchable(),
333                ])
334                .config(|this| this.min_times = 1)
335                .to_matchable(),
336                Ref::new("AliasExpressionSegment").optional().to_matchable(),
337            ])
338            .to_matchable()
339            .into(),
340        ),
341        (
342            "NaturalJoinKeywordsGrammar".into(),
343            Nothing::new().to_matchable().into(),
344        ),
345        (
346            "AccessorGrammar".into(),
347            AnyNumberOf::new(vec![
348                Ref::new("ArrayAccessorSegment").to_matchable(),
349                Ref::new("SemiStructuredAccessorSegment").to_matchable(),
350            ])
351            .to_matchable()
352            .into(),
353        ),
354        (
355            "MergeIntoLiteralGrammar".into(),
356            Sequence::new(vec![
357                Ref::keyword("MERGE").to_matchable(),
358                Ref::keyword("INTO").optional().to_matchable(),
359            ])
360            .to_matchable()
361            .into(),
362        ),
363        (
364            "PrimaryKeyGrammar".into(),
365            Nothing::new().to_matchable().into(),
366        ),
367        (
368            "ForeignKeyGrammar".into(),
369            Nothing::new().to_matchable().into(),
370        ),
371    ]);
372
373    // Set Keywords
374    dialect.sets_mut("unreserved_keywords").clear();
375    dialect.update_keywords_set_from_multiline_string(
376        "unreserved_keywords",
377        BIGQUERY_UNRESERVED_KEYWORDS,
378    );
379
380    dialect.sets_mut("reserved_keywords").clear();
381    dialect
382        .update_keywords_set_from_multiline_string("reserved_keywords", BIGQUERY_RESERVED_KEYWORDS);
383
384    // Add additional datetime units
385    // https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#extract
386    dialect.sets_mut("datetime_units").extend([
387        "MICROSECOND",
388        "MILLISECOND",
389        "SECOND",
390        "MINUTE",
391        "HOUR",
392        "DAY",
393        "DAYOFWEEK",
394        "DAYOFYEAR",
395        "WEEK",
396        "ISOWEEK",
397        "MONTH",
398        "QUARTER",
399        "YEAR",
400        "ISOYEAR",
401    ]);
402
403    // Add additional datetime units only recognised in some functions (e.g.
404    // extract)
405    dialect
406        .sets_mut("extended_datetime_units")
407        .extend(["DATE", "DATETIME", "TIME"]);
408
409    dialect.sets_mut("date_part_function_name").clear();
410    dialect.sets_mut("date_part_function_name").extend([
411        "DATE_DIFF",
412        "DATE_TRUNC",
413        "DATETIME_DIFF",
414        "DATETIME_TRUNC",
415        "EXTRACT",
416        "LAST_DAY",
417        "TIME_DIFF",
418        "TIME_TRUNC",
419        "TIMESTAMP_DIFF",
420        "TIMESTAMP_TRUNC",
421    ]);
422
423    // Set value table functions
424    dialect.sets_mut("value_table_functions").extend(["UNNEST"]);
425
426    // Set angle bracket pairs
427    dialect.bracket_sets_mut("angle_bracket_pairs").extend([(
428        "angle",
429        "StartAngleBracketSegment",
430        "EndAngleBracketSegment",
431        false,
432    )]);
433
434    dialect.add([
435        (
436            "ProcedureParameterListSegment".into(),
437            NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_| {
438                Bracketed::new(vec![
439                    Delimited::new(vec![Ref::new("ProcedureParameterGrammar").to_matchable()])
440                        .config(|this| this.optional())
441                        .to_matchable(),
442                ])
443                .to_matchable()
444            })
445            .to_matchable()
446            .into(),
447        ),
448        (
449            "ProcedureStatements".into(),
450            NodeMatcher::new(SyntaxKind::ProcedureStatements, |_| {
451                AnyNumberOf::new(vec![
452                    Sequence::new(vec![
453                        Ref::new("StatementSegment").to_matchable(),
454                        Ref::new("DelimiterGrammar").to_matchable(),
455                    ])
456                    .to_matchable(),
457                ])
458                .config(|this| {
459                    this.terminators = vec![Ref::keyword("END").to_matchable()];
460                    this.parse_mode = ParseMode::Greedy;
461                })
462                .to_matchable()
463            })
464            .to_matchable()
465            .into(),
466        ),
467        (
468            "CreateProcedureStatementSegment".into(),
469            NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| {
470                Sequence::new(vec![
471                    Ref::keyword("CREATE").to_matchable(),
472                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
473                    Ref::keyword("PROCEDURE").to_matchable(),
474                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
475                    Ref::new("ProcedureNameSegment").to_matchable(),
476                    Ref::new("ProcedureParameterListSegment").to_matchable(),
477                    Sequence::new(vec![
478                        Ref::keyword("OPTIONS").to_matchable(),
479                        Ref::keyword("STRICT_MODE").to_matchable(),
480                        StringParser::new("strict_mode", SyntaxKind::ProcedureOption)
481                            .to_matchable(),
482                        Ref::new("EqualsSegment").to_matchable(),
483                        Ref::new("BooleanLiteralGrammar").optional().to_matchable(),
484                    ])
485                    .config(|this| this.optional())
486                    .to_matchable(),
487                    Ref::keyword("BEGIN").to_matchable(),
488                    MetaSegment::indent().to_matchable(),
489                    Ref::new("ProcedureStatements").to_matchable(),
490                    MetaSegment::dedent().to_matchable(),
491                    Ref::keyword("END").to_matchable(),
492                ])
493                .to_matchable()
494            })
495            .to_matchable()
496            .into(),
497        ),
498        (
499            "CallStatementSegment".into(),
500            NodeMatcher::new(SyntaxKind::CallStatement, |_| {
501                Sequence::new(vec![
502                    Ref::keyword("CALL").to_matchable(),
503                    Ref::new("ProcedureNameSegment").to_matchable(),
504                    Bracketed::new(vec![
505                        Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
506                            .config(|this| this.optional())
507                            .to_matchable(),
508                    ])
509                    .to_matchable(),
510                ])
511                .to_matchable()
512            })
513            .to_matchable()
514            .into(),
515        ),
516        (
517            "ReturnStatementSegment".into(),
518            NodeMatcher::new(SyntaxKind::ReturnStatement, |_| {
519                Sequence::new(vec![Ref::keyword("RETURN").to_matchable()]).to_matchable()
520            })
521            .to_matchable()
522            .into(),
523        ),
524        (
525            "BreakStatementSegment".into(),
526            NodeMatcher::new(SyntaxKind::BreakStatement, |_| {
527                Sequence::new(vec![Ref::keyword("BREAK").to_matchable()]).to_matchable()
528            })
529            .to_matchable()
530            .into(),
531        ),
532        (
533            "LeaveStatementSegment".into(),
534            NodeMatcher::new(SyntaxKind::LeaveStatement, |_| {
535                Sequence::new(vec![Ref::keyword("LEAVE").to_matchable()]).to_matchable()
536            })
537            .to_matchable()
538            .into(),
539        ),
540        (
541            "ContinueStatementSegment".into(),
542            NodeMatcher::new(SyntaxKind::ContinueStatement, |_| {
543                one_of(vec![
544                    Ref::keyword("CONTINUE").to_matchable(),
545                    Ref::keyword("ITERATE").to_matchable(),
546                ])
547                .to_matchable()
548            })
549            .to_matchable()
550            .into(),
551        ),
552        (
553            "RaiseStatementSegment".into(),
554            NodeMatcher::new(SyntaxKind::RaiseStatement, |_| {
555                Sequence::new(vec![
556                    Ref::keyword("RAISE").to_matchable(),
557                    Sequence::new(vec![
558                        Ref::keyword("USING").to_matchable(),
559                        Ref::keyword("MESSAGE").to_matchable(),
560                        Ref::new("EqualsSegment").to_matchable(),
561                        Ref::new("ExpressionSegment").optional().to_matchable(),
562                    ])
563                    .config(|this| this.optional())
564                    .to_matchable(),
565                ])
566                .to_matchable()
567            })
568            .to_matchable()
569            .into(),
570        ),
571    ]);
572
573    dialect.replace_grammar(
574        "ArrayTypeSegment",
575        Sequence::new(vec![
576            Ref::keyword("ARRAY").to_matchable(),
577            Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()])
578                .config(|this| {
579                    this.bracket_type = "angle";
580                    this.bracket_pairs_set = "angle_bracket_pairs";
581                })
582                .to_matchable(),
583        ])
584        .to_matchable(),
585    );
586
587    dialect.add([
588        (
589            "QualifyClauseSegment".into(),
590            NodeMatcher::new(SyntaxKind::QualifyClause, |_| {
591                Sequence::new(vec![
592                    Ref::keyword("QUALIFY").to_matchable(),
593                    MetaSegment::indent().to_matchable(),
594                    optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()])
595                        .to_matchable(),
596                    MetaSegment::dedent().to_matchable(),
597                ])
598                .to_matchable()
599            })
600            .to_matchable()
601            .into(),
602        ),
603        (
604            "SetOperatorSegment".into(),
605            NodeMatcher::new(SyntaxKind::SetOperator, |_| {
606                one_of(vec![
607                    Sequence::new(vec![
608                        Ref::keyword("UNION").to_matchable(),
609                        one_of(vec![
610                            Ref::keyword("DISTINCT").to_matchable(),
611                            Ref::keyword("ALL").to_matchable(),
612                        ])
613                        .to_matchable(),
614                    ])
615                    .to_matchable(),
616                    Sequence::new(vec![
617                        Ref::keyword("INTERSECT").to_matchable(),
618                        Ref::keyword("DISTINCT").to_matchable(),
619                    ])
620                    .to_matchable(),
621                    Sequence::new(vec![
622                        Ref::keyword("EXCEPT").to_matchable(),
623                        Ref::keyword("DISTINCT").to_matchable(),
624                    ])
625                    .to_matchable(),
626                ])
627                .to_matchable()
628            })
629            .to_matchable()
630            .into(),
631        ),
632    ]);
633
634    dialect.replace_grammar("SetExpressionSegment", {
635        Sequence::new(vec![
636            one_of(vec![
637                Ref::new("NonSetSelectableGrammar").to_matchable(),
638                Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()])
639                    .to_matchable(),
640            ])
641            .to_matchable(),
642            AnyNumberOf::new(vec![
643                Sequence::new(vec![
644                    Ref::new("SetOperatorSegment").to_matchable(),
645                    one_of(vec![
646                        Ref::new("NonSetSelectableGrammar").to_matchable(),
647                        Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()])
648                            .to_matchable(),
649                    ])
650                    .to_matchable(),
651                ])
652                .to_matchable(),
653            ])
654            .config(|this| this.min_times = 1)
655            .to_matchable(),
656            Ref::new("OrderByClauseSegment").optional().to_matchable(),
657            Ref::new("LimitClauseSegment").optional().to_matchable(),
658            Ref::new("NamedWindowSegment").optional().to_matchable(),
659        ])
660        .to_matchable()
661    });
662
663    dialect.replace_grammar("SelectStatementSegment", {
664        ansi::select_statement().copy(
665            Some(vec![
666                Ref::new("QualifyClauseSegment").optional().to_matchable(),
667            ]),
668            None,
669            Some(Ref::new("OrderByClauseSegment").optional().to_matchable()),
670            None,
671            Vec::new(),
672            false,
673        )
674    });
675
676    dialect.replace_grammar(
677        "UnorderedSelectStatementSegment",
678        ansi::get_unordered_select_statement_segment_grammar().copy(
679            Some(vec![
680                Ref::new("QualifyClauseSegment").optional().to_matchable(),
681            ]),
682            None,
683            Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()),
684            None,
685            Vec::new(),
686            false,
687        ),
688    );
689
690    dialect.add([(
691        "MultiStatementSegment".into(),
692        NodeMatcher::new(SyntaxKind::MultiStatementSegment, |_| {
693            one_of(vec![
694                Ref::new("ForInStatementSegment").to_matchable(),
695                Ref::new("RepeatStatementSegment").to_matchable(),
696                Ref::new("WhileStatementSegment").to_matchable(),
697                Ref::new("LoopStatementSegment").to_matchable(),
698                Ref::new("IfStatementSegment").to_matchable(),
699                Ref::new("CreateProcedureStatementSegment").to_matchable(),
700            ])
701            .to_matchable()
702        })
703        .to_matchable()
704        .into(),
705    )]);
706
707    dialect.replace_grammar(
708        "FileSegment",
709        Sequence::new(vec![
710            Sequence::new(vec![
711                one_of(vec![
712                    Ref::new("MultiStatementSegment").to_matchable(),
713                    Ref::new("StatementSegment").to_matchable(),
714                ])
715                .to_matchable(),
716            ])
717            .to_matchable(),
718            AnyNumberOf::new(vec![
719                Ref::new("DelimiterGrammar").to_matchable(),
720                one_of(vec![
721                    Ref::new("MultiStatementSegment").to_matchable(),
722                    Ref::new("StatementSegment").to_matchable(),
723                ])
724                .to_matchable(),
725            ])
726            .to_matchable(),
727            Ref::new("DelimiterGrammar").optional().to_matchable(),
728        ])
729        .to_matchable(),
730    );
731
732    dialect.replace_grammar(
733        "StatementSegment",
734        ansi::statement_segment().copy(
735            Some(vec![
736                Ref::new("DeclareStatementSegment").to_matchable(),
737                Ref::new("SetStatementSegment").to_matchable(),
738                Ref::new("ExportStatementSegment").to_matchable(),
739                Ref::new("CreateExternalTableStatementSegment").to_matchable(),
740                Ref::new("AssertStatementSegment").to_matchable(),
741                Ref::new("CallStatementSegment").to_matchable(),
742                Ref::new("ReturnStatementSegment").to_matchable(),
743                Ref::new("BreakStatementSegment").to_matchable(),
744                Ref::new("LeaveStatementSegment").to_matchable(),
745                Ref::new("ContinueStatementSegment").to_matchable(),
746                Ref::new("RaiseStatementSegment").to_matchable(),
747                Ref::new("AlterViewStatementSegment").to_matchable(),
748                Ref::new("CreateMaterializedViewStatementSegment").to_matchable(),
749                Ref::new("AlterMaterializedViewStatementSegment").to_matchable(),
750                Ref::new("DropMaterializedViewStatementSegment").to_matchable(),
751            ]),
752            None,
753            None,
754            None,
755            Vec::new(),
756            false,
757        ),
758    );
759
760    dialect.add([(
761        "AssertStatementSegment".into(),
762        NodeMatcher::new(SyntaxKind::AssertStatement, |_| {
763            Sequence::new(vec![
764                Ref::keyword("ASSERT").to_matchable(),
765                Ref::new("ExpressionSegment").to_matchable(),
766                Sequence::new(vec![
767                    Ref::keyword("AS").to_matchable(),
768                    Ref::new("QuotedLiteralSegment").to_matchable(),
769                ])
770                .config(|this| this.optional())
771                .to_matchable(),
772            ])
773            .to_matchable()
774        })
775        .to_matchable()
776        .into(),
777    )]);
778
779    dialect.add([(
780        "ForInStatementsSegment".into(),
781        NodeMatcher::new(SyntaxKind::ForInStatements, |_| {
782            AnyNumberOf::new(vec![
783                Sequence::new(vec![
784                    one_of(vec![
785                        Ref::new("StatementSegment").to_matchable(),
786                        Ref::new("MultiStatementSegment").to_matchable(),
787                    ])
788                    .to_matchable(),
789                    Ref::new("DelimiterGrammar").to_matchable(),
790                ])
791                .to_matchable(),
792            ])
793            .config(|this| {
794                this.terminators = vec![
795                    Sequence::new(vec![
796                        Ref::keyword("END").to_matchable(),
797                        Ref::keyword("FOR").to_matchable(),
798                    ])
799                    .to_matchable(),
800                ];
801                this.parse_mode = ParseMode::Greedy;
802            })
803            .to_matchable()
804        })
805        .to_matchable()
806        .into(),
807    )]);
808
809    dialect.add([(
810        "ForInStatementSegment".into(),
811        NodeMatcher::new(SyntaxKind::ForInStatement, |_| {
812            Sequence::new(vec![
813                Ref::keyword("FOR").to_matchable(),
814                Ref::new("SingleIdentifierGrammar").to_matchable(),
815                Ref::keyword("IN").to_matchable(),
816                MetaSegment::indent().to_matchable(),
817                Ref::new("SelectableGrammar").to_matchable(),
818                MetaSegment::dedent().to_matchable(),
819                Ref::keyword("DO").to_matchable(),
820                MetaSegment::indent().to_matchable(),
821                Ref::new("ForInStatementsSegment").to_matchable(),
822                MetaSegment::dedent().to_matchable(),
823                Ref::keyword("END").to_matchable(),
824                Ref::keyword("FOR").to_matchable(),
825            ])
826            .to_matchable()
827        })
828        .to_matchable()
829        .into(),
830    )]);
831
832    dialect.add([
833        (
834            "RepeatStatementsSegment".into(),
835            NodeMatcher::new(SyntaxKind::RepeatStatements, |_| {
836                AnyNumberOf::new(vec![
837                    Sequence::new(vec![
838                        one_of(vec![
839                            Ref::new("StatementSegment").to_matchable(),
840                            Ref::new("MultiStatementSegment").to_matchable(),
841                        ])
842                        .to_matchable(),
843                        Ref::new("DelimiterGrammar").to_matchable(),
844                    ])
845                    .to_matchable(),
846                ])
847                .config(|this| {
848                    this.terminators = vec![Ref::keyword("UNTIL").to_matchable()];
849                    this.parse_mode = ParseMode::Greedy;
850                })
851                .to_matchable()
852            })
853            .to_matchable()
854            .into(),
855        ),
856        (
857            "RepeatStatementSegment".into(),
858            NodeMatcher::new(SyntaxKind::RepeatStatement, |_| {
859                Sequence::new(vec![
860                    Ref::keyword("REPEAT").to_matchable(),
861                    MetaSegment::indent().to_matchable(),
862                    Ref::new("RepeatStatementsSegment").to_matchable(),
863                    Ref::keyword("UNTIL").to_matchable(),
864                    Ref::new("ExpressionSegment").to_matchable(),
865                    MetaSegment::dedent().to_matchable(),
866                    Ref::keyword("END").to_matchable(),
867                    Ref::keyword("REPEAT").to_matchable(),
868                ])
869                .to_matchable()
870            })
871            .to_matchable()
872            .into(),
873        ),
874        (
875            "IfStatementsSegment".into(),
876            NodeMatcher::new(SyntaxKind::IfStatements, |_| {
877                AnyNumberOf::new(vec![
878                    Sequence::new(vec![
879                        one_of(vec![
880                            Ref::new("StatementSegment").to_matchable(),
881                            Ref::new("MultiStatementSegment").to_matchable(),
882                        ])
883                        .to_matchable(),
884                        Ref::new("DelimiterGrammar").to_matchable(),
885                    ])
886                    .to_matchable(),
887                ])
888                .config(|this| {
889                    this.terminators = vec![
890                        Ref::keyword("ELSE").to_matchable(),
891                        Ref::keyword("ELSEIF").to_matchable(),
892                        Sequence::new(vec![
893                            Ref::keyword("END").to_matchable(),
894                            Ref::keyword("IF").to_matchable(),
895                        ])
896                        .to_matchable(),
897                    ];
898                    this.parse_mode = ParseMode::Greedy;
899                })
900                .to_matchable()
901            })
902            .to_matchable()
903            .into(),
904        ),
905        (
906            "IfStatementSegment".into(),
907            NodeMatcher::new(SyntaxKind::IfStatement, |_| {
908                Sequence::new(vec![
909                    Ref::keyword("IF").to_matchable(),
910                    Ref::new("ExpressionSegment").to_matchable(),
911                    Ref::keyword("THEN").to_matchable(),
912                    MetaSegment::indent().to_matchable(),
913                    Ref::new("IfStatementsSegment").to_matchable(),
914                    MetaSegment::dedent().to_matchable(),
915                    AnyNumberOf::new(vec![
916                        Sequence::new(vec![
917                            Ref::keyword("ELSEIF").to_matchable(),
918                            Ref::new("ExpressionSegment").to_matchable(),
919                            Ref::keyword("THEN").to_matchable(),
920                            MetaSegment::indent().to_matchable(),
921                            Ref::new("IfStatementsSegment").to_matchable(),
922                            MetaSegment::dedent().to_matchable(),
923                        ])
924                        .to_matchable(),
925                    ])
926                    .to_matchable(),
927                    Sequence::new(vec![
928                        Ref::keyword("ELSE").to_matchable(),
929                        MetaSegment::indent().to_matchable(),
930                        Ref::new("IfStatementsSegment").to_matchable(),
931                        MetaSegment::dedent().to_matchable(),
932                    ])
933                    .config(|this| this.optional())
934                    .to_matchable(),
935                    Ref::keyword("END").to_matchable(),
936                    Ref::keyword("IF").to_matchable(),
937                ])
938                .to_matchable()
939            })
940            .to_matchable()
941            .into(),
942        ),
943        (
944            "LoopStatementsSegment".into(),
945            NodeMatcher::new(SyntaxKind::LoopStatements, |_| {
946                AnyNumberOf::new(vec![
947                    Sequence::new(vec![
948                        one_of(vec![
949                            Ref::new("StatementSegment").to_matchable(),
950                            Ref::new("MultiStatementSegment").to_matchable(),
951                        ])
952                        .to_matchable(),
953                        Ref::new("DelimiterGrammar").to_matchable(),
954                    ])
955                    .to_matchable(),
956                ])
957                .config(|this| {
958                    this.terminators = vec![
959                        Sequence::new(vec![
960                            Ref::keyword("END").to_matchable(),
961                            Ref::keyword("LOOP").to_matchable(),
962                        ])
963                        .to_matchable(),
964                    ];
965                    this.parse_mode = ParseMode::Greedy;
966                })
967                .to_matchable()
968            })
969            .to_matchable()
970            .into(),
971        ),
972        (
973            "LoopStatementSegment".into(),
974            NodeMatcher::new(SyntaxKind::LoopStatement, |_| {
975                Sequence::new(vec![
976                    Ref::keyword("LOOP").to_matchable(),
977                    MetaSegment::indent().to_matchable(),
978                    Ref::new("LoopStatementsSegment").to_matchable(),
979                    MetaSegment::dedent().to_matchable(),
980                    Ref::keyword("END").to_matchable(),
981                    Ref::keyword("LOOP").to_matchable(),
982                ])
983                .to_matchable()
984            })
985            .to_matchable()
986            .into(),
987        ),
988        (
989            "WhileStatementsSegment".into(),
990            NodeMatcher::new(SyntaxKind::WhileStatements, |_| {
991                AnyNumberOf::new(vec![
992                    Sequence::new(vec![
993                        Ref::new("StatementSegment").to_matchable(),
994                        Ref::new("DelimiterGrammar").to_matchable(),
995                    ])
996                    .to_matchable(),
997                ])
998                .config(|this| {
999                    this.terminators = vec![
1000                        Sequence::new(vec![
1001                            Ref::keyword("END").to_matchable(),
1002                            Ref::keyword("WHILE").to_matchable(),
1003                        ])
1004                        .to_matchable(),
1005                    ];
1006                    this.parse_mode = ParseMode::Greedy;
1007                })
1008                .to_matchable()
1009            })
1010            .to_matchable()
1011            .into(),
1012        ),
1013        (
1014            "WhileStatementSegment".into(),
1015            NodeMatcher::new(SyntaxKind::WhileStatement, |_| {
1016                Sequence::new(vec![
1017                    Ref::keyword("WHILE").to_matchable(),
1018                    Ref::new("ExpressionSegment").to_matchable(),
1019                    Ref::keyword("DO").to_matchable(),
1020                    MetaSegment::indent().to_matchable(),
1021                    Ref::new("WhileStatementsSegment").to_matchable(),
1022                    MetaSegment::dedent().to_matchable(),
1023                    Ref::keyword("END").to_matchable(),
1024                    Ref::keyword("WHILE").to_matchable(),
1025                ])
1026                .to_matchable()
1027            })
1028            .to_matchable()
1029            .into(),
1030        ),
1031    ]);
1032
1033    dialect.replace_grammar(
1034        "SelectClauseModifierSegment",
1035        Sequence::new(vec![
1036            one_of(vec![
1037                Ref::keyword("DISTINCT").to_matchable(),
1038                Ref::keyword("ALL").to_matchable(),
1039            ])
1040            .config(|this| this.optional())
1041            .to_matchable(),
1042            Sequence::new(vec![
1043                Ref::keyword("AS").to_matchable(),
1044                one_of(vec![
1045                    Ref::keyword("STRUCT").to_matchable(),
1046                    Ref::keyword("VALUE").to_matchable(),
1047                ])
1048                .to_matchable(),
1049            ])
1050            .config(|this| this.optional())
1051            .to_matchable(),
1052        ])
1053        .to_matchable(),
1054    );
1055
1056    dialect.replace_grammar(
1057        "IntervalExpressionSegment",
1058        Sequence::new(vec![
1059            Ref::keyword("INTERVAL").to_matchable(),
1060            Ref::new("ExpressionSegment").to_matchable(),
1061            one_of(vec![
1062                Ref::new("QuotedLiteralSegment").to_matchable(),
1063                Ref::new("DatetimeUnitSegment").to_matchable(),
1064                Sequence::new(vec![
1065                    Ref::new("DatetimeUnitSegment").to_matchable(),
1066                    Ref::keyword("TO").to_matchable(),
1067                    Ref::new("DatetimeUnitSegment").to_matchable(),
1068                ])
1069                .to_matchable(),
1070            ])
1071            .to_matchable(),
1072        ])
1073        .to_matchable(),
1074    );
1075
1076    dialect.add([
1077        (
1078            "DateTimeFunctionContentsSegment".into(),
1079            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
1080                Bracketed::new(vec![
1081                    Delimited::new(vec![
1082                        Ref::new("DatetimeUnitSegment").to_matchable(),
1083                        Ref::new("DatePartWeekSegment").to_matchable(),
1084                        Ref::new("FunctionContentsGrammar").to_matchable(),
1085                    ])
1086                    .to_matchable(),
1087                ])
1088                .to_matchable()
1089            })
1090            .to_matchable()
1091            .into(),
1092        ),
1093        (
1094            "ExtractFunctionContentsSegment".into(),
1095            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
1096                Bracketed::new(vec![
1097                    one_of(vec![
1098                        Ref::new("DatetimeUnitSegment").to_matchable(),
1099                        Ref::new("DatePartWeekSegment").to_matchable(),
1100                        Ref::new("ExtendedDatetimeUnitSegment").to_matchable(),
1101                    ])
1102                    .to_matchable(),
1103                    Ref::keyword("FROM").to_matchable(),
1104                    Ref::new("ExpressionSegment").to_matchable(),
1105                ])
1106                .to_matchable()
1107            })
1108            .to_matchable()
1109            .into(),
1110        ),
1111        (
1112            "NormalizeFunctionContentsSegment".into(),
1113            NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
1114                Bracketed::new(vec![
1115                    Ref::new("ExpressionSegment").to_matchable(),
1116                    Sequence::new(vec![
1117                        Ref::new("CommaSegment").to_matchable(),
1118                        one_of(vec![
1119                            Ref::keyword("NFC").to_matchable(),
1120                            Ref::keyword("NFKC").to_matchable(),
1121                            Ref::keyword("NFD").to_matchable(),
1122                            Ref::keyword("NFKD").to_matchable(),
1123                        ])
1124                        .to_matchable(),
1125                    ])
1126                    .config(|this| this.optional())
1127                    .to_matchable(),
1128                ])
1129                .to_matchable()
1130            })
1131            .to_matchable()
1132            .into(),
1133        ),
1134        (
1135            "ExtractFunctionNameSegment".into(),
1136            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
1137                StringParser::new("EXTRACT", SyntaxKind::FunctionNameIdentifier).to_matchable()
1138            })
1139            .to_matchable()
1140            .into(),
1141        ),
1142        (
1143            "ArrayFunctionNameSegment".into(),
1144            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
1145                StringParser::new("ARRAY", SyntaxKind::FunctionNameIdentifier).to_matchable()
1146            })
1147            .to_matchable()
1148            .into(),
1149        ),
1150        (
1151            "DatePartWeekSegment".into(),
1152            NodeMatcher::new(SyntaxKind::DatePartWeek, |_| {
1153                Sequence::new(vec![
1154                    Ref::keyword("WEEK").to_matchable(),
1155                    Bracketed::new(vec![
1156                        one_of(vec![
1157                            Ref::keyword("SUNDAY").to_matchable(),
1158                            Ref::keyword("MONDAY").to_matchable(),
1159                            Ref::keyword("TUESDAY").to_matchable(),
1160                            Ref::keyword("WEDNESDAY").to_matchable(),
1161                            Ref::keyword("THURSDAY").to_matchable(),
1162                            Ref::keyword("FRIDAY").to_matchable(),
1163                            Ref::keyword("SATURDAY").to_matchable(),
1164                        ])
1165                        .to_matchable(),
1166                    ])
1167                    .to_matchable(),
1168                ])
1169                .to_matchable()
1170            })
1171            .to_matchable()
1172            .into(),
1173        ),
1174        (
1175            "NormalizeFunctionNameSegment".into(),
1176            NodeMatcher::new(SyntaxKind::FunctionName, |_| {
1177                one_of(vec![
1178                    StringParser::new("NORMALIZE", SyntaxKind::FunctionNameIdentifier)
1179                        .to_matchable(),
1180                    StringParser::new("NORMALIZE_AND_CASEFOLD", SyntaxKind::FunctionNameIdentifier)
1181                        .to_matchable(),
1182                ])
1183                .to_matchable()
1184            })
1185            .to_matchable()
1186            .into(),
1187        ),
1188    ]);
1189
1190    dialect.replace_grammar(
1191        "FunctionNameSegment",
1192        Sequence::new(vec![
1193            // AnyNumberOf to handle project names, schemas, or the SAFE keyword
1194            AnyNumberOf::new(vec![
1195                Sequence::new(vec![
1196                    one_of(vec![
1197                        Ref::keyword("SAFE").to_matchable(),
1198                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1199                    ])
1200                    .to_matchable(),
1201                    Ref::new("DotSegment").to_matchable(),
1202                ])
1203                .terminators(vec![Ref::new("BracketedSegment").to_matchable()])
1204                .to_matchable(),
1205            ])
1206            .to_matchable(),
1207            // Base function name
1208            one_of(vec![
1209                Ref::new("FunctionNameIdentifierSegment").to_matchable(),
1210                Ref::new("QuotedIdentifierSegment").to_matchable(),
1211            ])
1212            .config(|this| this.terminators = vec![Ref::new("BracketedSegment").to_matchable()])
1213            .to_matchable(),
1214        ])
1215        .allow_gaps(true)
1216        .to_matchable(),
1217    );
1218
1219    dialect.replace_grammar(
1220        "FunctionSegment",
1221        Sequence::new(vec![
1222            one_of(vec![
1223                Sequence::new(vec![
1224                    // BigQuery EXTRACT allows optional TimeZone
1225                    Ref::new("ExtractFunctionNameSegment").to_matchable(),
1226                    Ref::new("ExtractFunctionContentsSegment").to_matchable(),
1227                ])
1228                .to_matchable(),
1229                Sequence::new(vec![
1230                    // BigQuery NORMALIZE allows optional normalization_mode
1231                    Ref::new("NormalizeFunctionNameSegment").to_matchable(),
1232                    Ref::new("NormalizeFunctionContentsSegment").to_matchable(),
1233                ])
1234                .to_matchable(),
1235                Sequence::new(vec![
1236                    // Treat functions which take date parts separately
1237                    Ref::new("DatePartFunctionNameSegment")
1238                        .exclude(Ref::new("ExtractFunctionNameSegment"))
1239                        .to_matchable(),
1240                    Ref::new("DateTimeFunctionContentsSegment").to_matchable(),
1241                ])
1242                .to_matchable(),
1243                Sequence::new(vec![
1244                    Sequence::new(vec![
1245                        Ref::new("FunctionNameSegment")
1246                            .exclude(one_of(vec![
1247                                Ref::new("DatePartFunctionNameSegment").to_matchable(),
1248                                Ref::new("NormalizeFunctionNameSegment").to_matchable(),
1249                                Ref::new("ValuesClauseSegment").to_matchable(),
1250                            ]))
1251                            .to_matchable(),
1252                        Ref::new("FunctionContentsSegment").to_matchable(),
1253                    ])
1254                    .to_matchable(),
1255                    Ref::new("ArrayAccessorSegment").optional().to_matchable(),
1256                    Ref::new("SemiStructuredAccessorSegment")
1257                        .optional()
1258                        .to_matchable(),
1259                    Ref::new("PostFunctionGrammar").optional().to_matchable(),
1260                ])
1261                .to_matchable(),
1262            ])
1263            .to_matchable(),
1264        ])
1265        .config(|this| this.allow_gaps = false)
1266        .to_matchable(),
1267    );
1268
1269    dialect.replace_grammar(
1270        "FunctionDefinitionGrammar",
1271        Sequence::new(vec![
1272            AnyNumberOf::new(vec![
1273                Sequence::new(vec![
1274                    one_of(vec![
1275                        Ref::keyword("DETERMINISTIC").to_matchable(),
1276                        Sequence::new(vec![
1277                            Ref::keyword("NOT").to_matchable(),
1278                            Ref::keyword("DETERMINISTIC").to_matchable(),
1279                        ])
1280                        .to_matchable(),
1281                    ])
1282                    .to_matchable(),
1283                ])
1284                .config(|this| this.optional())
1285                .to_matchable(),
1286                Sequence::new(vec![
1287                    Ref::keyword("LANGUAGE").to_matchable(),
1288                    Ref::new("NakedIdentifierSegment").to_matchable(),
1289                    Sequence::new(vec![
1290                        Ref::keyword("OPTIONS").to_matchable(),
1291                        Bracketed::new(vec![
1292                            Delimited::new(vec![
1293                                Sequence::new(vec![
1294                                    Ref::new("ParameterNameSegment").to_matchable(),
1295                                    Ref::new("EqualsSegment").to_matchable(),
1296                                    Anything::new().to_matchable(),
1297                                ])
1298                                .to_matchable(),
1299                                Ref::new("CommaSegment").to_matchable(),
1300                            ])
1301                            .to_matchable(),
1302                        ])
1303                        .to_matchable(),
1304                    ])
1305                    .config(|this| this.optional())
1306                    .to_matchable(),
1307                ])
1308                .to_matchable(),
1309                Sequence::new(vec![
1310                    Ref::keyword("AS").to_matchable(),
1311                    one_of(vec![
1312                        Ref::new("DoubleQuotedUDFBody").to_matchable(),
1313                        Ref::new("SingleQuotedUDFBody").to_matchable(),
1314                        Bracketed::new(vec![
1315                            one_of(vec![
1316                                Ref::new("ExpressionSegment").to_matchable(),
1317                                Ref::new("SelectStatementSegment").to_matchable(),
1318                            ])
1319                            .to_matchable(),
1320                        ])
1321                        .to_matchable(),
1322                    ])
1323                    .to_matchable(),
1324                ])
1325                .to_matchable(),
1326            ])
1327            .to_matchable(),
1328        ])
1329        .to_matchable(),
1330    );
1331
1332    dialect.replace_grammar(
1333        "WildcardExpressionSegment",
1334        ansi::wildcard_expression_segment().copy(
1335            Some(vec![
1336                Ref::new("ExceptClauseSegment").optional().to_matchable(),
1337                Ref::new("ReplaceClauseSegment").optional().to_matchable(),
1338            ]),
1339            None,
1340            None,
1341            None,
1342            Vec::new(),
1343            false,
1344        ),
1345    );
1346
1347    dialect.add([
1348        (
1349            "ExceptClauseSegment".into(),
1350            NodeMatcher::new(SyntaxKind::SelectExceptClause, |_| {
1351                Sequence::new(vec![
1352                    Ref::keyword("EXCEPT").to_matchable(),
1353                    Bracketed::new(vec![
1354                        Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()])
1355                            .to_matchable(),
1356                    ])
1357                    .to_matchable(),
1358                ])
1359                .to_matchable()
1360            })
1361            .to_matchable()
1362            .into(),
1363        ),
1364        (
1365            "ReplaceClauseSegment".into(),
1366            NodeMatcher::new(SyntaxKind::SelectReplaceClause, |_| {
1367                Sequence::new(vec![
1368                    Ref::keyword("REPLACE").to_matchable(),
1369                    Bracketed::new(vec![
1370                        Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()])
1371                            .to_matchable(),
1372                    ])
1373                    .to_matchable(),
1374                ])
1375                .to_matchable()
1376            })
1377            .to_matchable()
1378            .into(),
1379        ),
1380    ]);
1381
1382    dialect.replace_grammar("DatatypeSegment", {
1383        one_of(vec![
1384            Sequence::new(vec![
1385                Ref::new("DatatypeIdentifierSegment").to_matchable(),
1386                Ref::new("BracketedArguments").optional().to_matchable(),
1387            ])
1388            .to_matchable(),
1389            Sequence::new(vec![
1390                Ref::keyword("ANY").to_matchable(),
1391                Ref::keyword("TYPE").to_matchable(),
1392            ])
1393            .to_matchable(),
1394            Ref::new("ArrayTypeSegment").to_matchable(),
1395            Ref::new("StructTypeSegment").to_matchable(),
1396        ])
1397        .to_matchable()
1398    });
1399
1400    dialect.replace_grammar(
1401        "StructTypeSegment",
1402        Sequence::new(vec![
1403            Ref::keyword("STRUCT").to_matchable(),
1404            Ref::new("StructTypeSchemaSegment")
1405                .optional()
1406                .to_matchable(),
1407        ])
1408        .to_matchable(),
1409    );
1410
1411    dialect.add([(
1412        "StructTypeSchemaSegment".into(),
1413        NodeMatcher::new(SyntaxKind::StructTypeSchema, |_| {
1414            Bracketed::new(vec![
1415                Delimited::new(vec![
1416                    Sequence::new(vec![
1417                        one_of(vec![
1418                            Ref::new("DatatypeSegment").to_matchable(),
1419                            Sequence::new(vec![
1420                                Ref::new("ParameterNameSegment").to_matchable(),
1421                                Ref::new("DatatypeSegment").to_matchable(),
1422                            ])
1423                            .to_matchable(),
1424                        ])
1425                        .to_matchable(),
1426                        AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
1427                            .to_matchable(),
1428                        Ref::new("OptionsSegment").optional().to_matchable(),
1429                    ])
1430                    .to_matchable(),
1431                ])
1432                .to_matchable(),
1433            ])
1434            .config(|this| {
1435                this.bracket_type = "angle";
1436                this.bracket_pairs_set = "angle_bracket_pairs";
1437            })
1438            .to_matchable()
1439        })
1440        .to_matchable()
1441        .into(),
1442    )]);
1443
1444    dialect.add([(
1445        "ArrayFunctionContentsSegment".into(),
1446        NodeMatcher::new(SyntaxKind::FunctionContents, |_| {
1447            Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable()
1448        })
1449        .to_matchable()
1450        .into(),
1451    )]);
1452
1453    dialect.replace_grammar(
1454        "ArrayExpressionSegment",
1455        Sequence::new(vec![
1456            Ref::new("ArrayFunctionNameSegment").to_matchable(),
1457            Ref::new("ArrayFunctionContentsSegment").to_matchable(),
1458        ])
1459        .to_matchable(),
1460    );
1461
1462    dialect.add([
1463        (
1464            "TupleSegment".into(),
1465            NodeMatcher::new(SyntaxKind::Tuple, |_| {
1466                Bracketed::new(vec![
1467                    Delimited::new(vec![
1468                        Ref::new("BaseExpressionElementGrammar").to_matchable(),
1469                    ])
1470                    .to_matchable(),
1471                ])
1472                .to_matchable()
1473            })
1474            .to_matchable()
1475            .into(),
1476        ),
1477        (
1478            "NamedArgumentSegment".into(),
1479            NodeMatcher::new(SyntaxKind::NamedArgument, |_| {
1480                Sequence::new(vec![
1481                    Ref::new("NakedIdentifierSegment").to_matchable(),
1482                    Ref::new("RightArrowSegment").to_matchable(),
1483                    Ref::new("ExpressionSegment").to_matchable(),
1484                ])
1485                .to_matchable()
1486            })
1487            .to_matchable()
1488            .into(),
1489        ),
1490    ]);
1491
1492    dialect.add([(
1493        "SemiStructuredAccessorSegment".into(),
1494        NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| {
1495            Sequence::new(vec![
1496                AnyNumberOf::new(vec![
1497                    Sequence::new(vec![
1498                        Ref::new("DotSegment").to_matchable(),
1499                        one_of(vec![
1500                            Ref::new("SingleIdentifierGrammar").to_matchable(),
1501                            Ref::new("StarSegment").to_matchable(),
1502                        ])
1503                        .to_matchable(),
1504                    ])
1505                    .config(|this| this.allow_gaps = true)
1506                    .to_matchable(),
1507                    Ref::new("ArrayAccessorSegment").optional().to_matchable(),
1508                ])
1509                .config(|this| {
1510                    this.allow_gaps = true;
1511                    this.min_times = 1;
1512                })
1513                .to_matchable(),
1514            ])
1515            .config(|this| this.allow_gaps = true)
1516            .to_matchable()
1517        })
1518        .to_matchable()
1519        .into(),
1520    )]);
1521
1522    dialect.replace_grammar(
1523        "ColumnReferenceSegment",
1524        Sequence::new(vec![
1525            Ref::new("SingleIdentifierGrammar").to_matchable(),
1526            Sequence::new(vec![
1527                Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(),
1528                Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()])
1529                    .config(|this| {
1530                        this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
1531                        this.terminators = vec![
1532                            Ref::keyword("ON").to_matchable(),
1533                            Ref::keyword("AS").to_matchable(),
1534                            Ref::keyword("USING").to_matchable(),
1535                            Ref::new("CommaSegment").to_matchable(),
1536                            Ref::new("CastOperatorSegment").to_matchable(),
1537                            Ref::new("StartSquareBracketSegment").to_matchable(),
1538                            Ref::new("StartBracketSegment").to_matchable(),
1539                            Ref::new("BinaryOperatorGrammar").to_matchable(),
1540                            Ref::new("ColonSegment").to_matchable(),
1541                            Ref::new("DelimiterGrammar").to_matchable(),
1542                            Ref::new("BracketedSegment").to_matchable(),
1543                        ];
1544                        this.allow_gaps = false;
1545                    })
1546                    .to_matchable(),
1547            ])
1548            .allow_gaps(false)
1549            .config(|this| this.optional())
1550            .to_matchable(),
1551        ])
1552        .allow_gaps(false)
1553        .to_matchable(),
1554    );
1555
1556    dialect.replace_grammar("TableReferenceSegment", {
1557        Delimited::new(vec![
1558            Sequence::new(vec![
1559                Ref::new("SingleIdentifierGrammar").to_matchable(),
1560                AnyNumberOf::new(vec![
1561                    Sequence::new(vec![
1562                        Ref::new("DashSegment").to_matchable(),
1563                        Ref::new("NakedIdentifierPart").to_matchable(),
1564                    ])
1565                    .config(|this| this.allow_gaps = false)
1566                    .to_matchable(),
1567                ])
1568                .config(|this| this.optional())
1569                .to_matchable(),
1570            ])
1571            .config(|this| this.allow_gaps = false)
1572            .to_matchable(),
1573        ])
1574        .config(|this| {
1575            this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"));
1576            this.terminators = vec![
1577                Ref::keyword("ON").to_matchable(),
1578                Ref::keyword("AS").to_matchable(),
1579                Ref::keyword("USING").to_matchable(),
1580                Ref::new("CommaSegment").to_matchable(),
1581                Ref::new("CastOperatorSegment").to_matchable(),
1582                Ref::new("StartSquareBracketSegment").to_matchable(),
1583                Ref::new("StartBracketSegment").to_matchable(),
1584                Ref::new("ColonSegment").to_matchable(),
1585                Ref::new("DelimiterGrammar").to_matchable(),
1586                Ref::new("JoinLikeClauseGrammar").to_matchable(),
1587                Ref::new("BracketedSegment").to_matchable(),
1588            ];
1589            this.allow_gaps = false;
1590        })
1591        .to_matchable()
1592    });
1593
1594    dialect.add([
1595        (
1596            "DeclareStatementSegment".into(),
1597            NodeMatcher::new(SyntaxKind::DeclareSegment, |_| {
1598                Sequence::new(vec![
1599                    Ref::keyword("DECLARE").to_matchable(),
1600                    Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()])
1601                        .to_matchable(),
1602                    one_of(vec![
1603                        Ref::new("DefaultDeclareOptionsGrammar").to_matchable(),
1604                        Sequence::new(vec![
1605                            Ref::new("DatatypeSegment").to_matchable(),
1606                            Ref::new("DefaultDeclareOptionsGrammar")
1607                                .optional()
1608                                .to_matchable(),
1609                        ])
1610                        .to_matchable(),
1611                    ])
1612                    .to_matchable(),
1613                ])
1614                .to_matchable()
1615            })
1616            .to_matchable()
1617            .into(),
1618        ),
1619        (
1620            "SetStatementSegment".into(),
1621            NodeMatcher::new(SyntaxKind::SetSegment, |_| {
1622                Sequence::new(vec![
1623                    Ref::keyword("SET").to_matchable(),
1624                    one_of(vec![
1625                        Ref::new("NakedIdentifierSegment").to_matchable(),
1626                        Bracketed::new(vec![
1627                            Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()])
1628                                .to_matchable(),
1629                        ])
1630                        .to_matchable(),
1631                    ])
1632                    .to_matchable(),
1633                    Ref::new("EqualsSegment").to_matchable(),
1634                    Delimited::new(vec![
1635                        one_of(vec![
1636                            Ref::new("LiteralGrammar").to_matchable(),
1637                            Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()])
1638                                .to_matchable(),
1639                            Ref::new("BareFunctionSegment").to_matchable(),
1640                            Ref::new("FunctionSegment").to_matchable(),
1641                            Bracketed::new(vec![
1642                                Delimited::new(vec![
1643                                    one_of(vec![
1644                                        Ref::new("LiteralGrammar").to_matchable(),
1645                                        Bracketed::new(vec![
1646                                            Ref::new("SelectStatementSegment").to_matchable(),
1647                                        ])
1648                                        .to_matchable(),
1649                                        Ref::new("BareFunctionSegment").to_matchable(),
1650                                        Ref::new("FunctionSegment").to_matchable(),
1651                                    ])
1652                                    .to_matchable(),
1653                                ])
1654                                .to_matchable(),
1655                            ])
1656                            .to_matchable(),
1657                            Ref::new("ArrayLiteralSegment").to_matchable(),
1658                            Ref::new("ExpressionSegment").to_matchable(),
1659                        ])
1660                        .to_matchable(),
1661                    ])
1662                    .to_matchable(),
1663                ])
1664                .to_matchable()
1665            })
1666            .to_matchable()
1667            .into(),
1668        ),
1669        (
1670            "PartitionBySegment".into(),
1671            NodeMatcher::new(SyntaxKind::PartitionBySegment, |_| {
1672                Sequence::new(vec![
1673                    Ref::keyword("PARTITION").to_matchable(),
1674                    Ref::keyword("BY").to_matchable(),
1675                    Ref::new("ExpressionSegment").to_matchable(),
1676                ])
1677                .to_matchable()
1678            })
1679            .to_matchable()
1680            .into(),
1681        ),
1682        (
1683            "ClusterBySegment".into(),
1684            NodeMatcher::new(SyntaxKind::ClusterBySegment, |_| {
1685                Sequence::new(vec![
1686                    Ref::keyword("CLUSTER").to_matchable(),
1687                    Ref::keyword("BY").to_matchable(),
1688                    Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()])
1689                        .to_matchable(),
1690                ])
1691                .to_matchable()
1692            })
1693            .to_matchable()
1694            .into(),
1695        ),
1696        (
1697            "OptionsSegment".into(),
1698            NodeMatcher::new(SyntaxKind::OptionsSegment, |_| {
1699                Sequence::new(vec![
1700                    Ref::keyword("OPTIONS").to_matchable(),
1701                    Bracketed::new(vec![
1702                        Delimited::new(vec![
1703                            Sequence::new(vec![
1704                                Ref::new("ParameterNameSegment").to_matchable(),
1705                                Ref::new("EqualsSegment").to_matchable(),
1706                                Ref::new("BaseExpressionElementGrammar").to_matchable(),
1707                            ])
1708                            .to_matchable(),
1709                        ])
1710                        .to_matchable(),
1711                    ])
1712                    .to_matchable(),
1713                ])
1714                .to_matchable()
1715            })
1716            .to_matchable()
1717            .into(),
1718        ),
1719    ]);
1720
1721    dialect.replace_grammar(
1722        "ColumnDefinitionSegment",
1723        Sequence::new(vec![
1724            Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name
1725            Ref::new("DatatypeSegment").to_matchable(),         // Column type
1726            AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()])
1727                .to_matchable(),
1728            Ref::new("OptionsSegment").optional().to_matchable(),
1729        ])
1730        .to_matchable(),
1731    );
1732
1733    dialect.replace_grammar(
1734        "CreateTableStatementSegment",
1735        Sequence::new(vec![
1736            Ref::keyword("CREATE").to_matchable(),
1737            Ref::new("OrReplaceGrammar").optional().to_matchable(),
1738            Ref::new("TemporaryTransientGrammar")
1739                .optional()
1740                .to_matchable(),
1741            Ref::keyword("TABLE").to_matchable(),
1742            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1743            Ref::new("TableReferenceSegment").to_matchable(),
1744            Sequence::new(vec![
1745                one_of(vec![
1746                    Ref::keyword("COPY").to_matchable(),
1747                    Ref::keyword("LIKE").to_matchable(),
1748                    Ref::keyword("CLONE").to_matchable(),
1749                ])
1750                .to_matchable(),
1751                Ref::new("TableReferenceSegment").to_matchable(),
1752            ])
1753            .config(|this| this.optional())
1754            .to_matchable(),
1755            Sequence::new(vec![
1756                Bracketed::new(vec![
1757                    Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()])
1758                        .config(|this| this.allow_trailing())
1759                        .to_matchable(),
1760                ])
1761                .to_matchable(),
1762            ])
1763            .config(|this| this.optional())
1764            .to_matchable(),
1765            Ref::new("PartitionBySegment").optional().to_matchable(),
1766            Ref::new("ClusterBySegment").optional().to_matchable(),
1767            Ref::new("OptionsSegment").optional().to_matchable(),
1768            Sequence::new(vec![
1769                Ref::keyword("AS").to_matchable(),
1770                optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
1771                    .to_matchable(),
1772            ])
1773            .config(|this| this.optional())
1774            .to_matchable(),
1775        ])
1776        .to_matchable(),
1777    );
1778
1779    dialect.replace_grammar(
1780        "AlterTableStatementSegment",
1781        Sequence::new(vec![
1782            Ref::keyword("ALTER").to_matchable(),
1783            Ref::keyword("TABLE").to_matchable(),
1784            Ref::new("IfExistsGrammar").optional().to_matchable(),
1785            Ref::new("TableReferenceSegment").to_matchable(),
1786            one_of(vec![
1787                // SET OPTIONS
1788                Sequence::new(vec![
1789                    Ref::keyword("SET").to_matchable(),
1790                    Ref::new("OptionsSegment").to_matchable(),
1791                ])
1792                .to_matchable(),
1793                // ADD COLUMN
1794                Delimited::new(vec![
1795                    Sequence::new(vec![
1796                        Ref::keyword("ADD").to_matchable(),
1797                        Ref::keyword("COLUMN").to_matchable(),
1798                        Ref::new("IfNotExistsGrammar").optional().to_matchable(),
1799                        Ref::new("ColumnDefinitionSegment").to_matchable(),
1800                    ])
1801                    .to_matchable(),
1802                ])
1803                .config(|this| this.allow_trailing = true)
1804                .to_matchable(),
1805                // RENAME TO
1806                Sequence::new(vec![
1807                    Ref::keyword("RENAME").to_matchable(),
1808                    Ref::keyword("TO").to_matchable(),
1809                    Ref::new("TableReferenceSegment").to_matchable(),
1810                ])
1811                .to_matchable(),
1812                // RENAME COLUMN
1813                Delimited::new(vec![
1814                    Sequence::new(vec![
1815                        Ref::keyword("RENAME").to_matchable(),
1816                        Ref::keyword("COLUMN").to_matchable(),
1817                        Ref::new("IfExistsGrammar").optional().to_matchable(),
1818                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1819                        Ref::keyword("TO").to_matchable(),
1820                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1821                    ])
1822                    .to_matchable(),
1823                ])
1824                .config(|this| this.allow_trailing = true)
1825                .to_matchable(),
1826                // DROP COLUMN
1827                Delimited::new(vec![
1828                    Sequence::new(vec![
1829                        Ref::keyword("DROP").to_matchable(),
1830                        Ref::keyword("COLUMN").to_matchable(),
1831                        Ref::new("IfExistsGrammar").optional().to_matchable(),
1832                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1833                    ])
1834                    .to_matchable(),
1835                ])
1836                .to_matchable(),
1837                // ALTER COLUMN SET OPTIONS
1838                Delimited::new(vec![
1839                    Sequence::new(vec![
1840                        Ref::keyword("ALTER").to_matchable(),
1841                        Ref::keyword("COLUMN").to_matchable(),
1842                        Ref::new("IfExistsGrammar").optional().to_matchable(),
1843                        Ref::new("SingleIdentifierGrammar").to_matchable(),
1844                        one_of(vec![
1845                            Sequence::new(vec![
1846                                Ref::keyword("SET").to_matchable(),
1847                                one_of(vec![
1848                                    Ref::new("OptionsSegment").to_matchable(),
1849                                    Sequence::new(vec![
1850                                        Ref::keyword("DATA").to_matchable(),
1851                                        Ref::keyword("TYPE").to_matchable(),
1852                                        Ref::new("DatatypeSegment").to_matchable(),
1853                                    ])
1854                                    .to_matchable(),
1855                                    Sequence::new(vec![
1856                                        Ref::keyword("DEFAULT").to_matchable(),
1857                                        one_of(vec![
1858                                            Ref::new("LiteralGrammar").to_matchable(),
1859                                            Ref::new("FunctionSegment").to_matchable(),
1860                                        ])
1861                                        .to_matchable(),
1862                                    ])
1863                                    .to_matchable(),
1864                                ])
1865                                .to_matchable(),
1866                            ])
1867                            .to_matchable(),
1868                            Sequence::new(vec![
1869                                Ref::keyword("DROP").to_matchable(),
1870                                one_of(vec![
1871                                    Ref::keyword("DEFAULT").to_matchable(),
1872                                    Sequence::new(vec![
1873                                        Ref::keyword("NOT").to_matchable(),
1874                                        Ref::keyword("NULL").to_matchable(),
1875                                    ])
1876                                    .to_matchable(),
1877                                ])
1878                                .to_matchable(),
1879                            ])
1880                            .to_matchable(),
1881                        ])
1882                        .to_matchable(),
1883                    ])
1884                    .to_matchable(),
1885                ])
1886                .to_matchable(),
1887            ])
1888            .to_matchable(),
1889        ])
1890        .to_matchable(),
1891    );
1892
1893    dialect.add([(
1894        "CreateExternalTableStatementSegment".into(),
1895        NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| {
1896            Sequence::new(vec![
1897                Ref::keyword("CREATE").to_matchable(),
1898                Sequence::new(vec![
1899                    Ref::keyword("OR").optional().to_matchable(),
1900                    Ref::keyword("REPLACE").optional().to_matchable(),
1901                ])
1902                .config(|this| this.optional())
1903                .to_matchable(),
1904                Ref::keyword("EXTERNAL").to_matchable(),
1905                Ref::keyword("TABLE").to_matchable(),
1906                Sequence::new(vec![
1907                    Ref::keyword("IF").optional().to_matchable(),
1908                    Ref::keyword("NOT").optional().to_matchable(),
1909                    Ref::keyword("EXISTS").optional().to_matchable(),
1910                ])
1911                .config(|this| this.optional())
1912                .to_matchable(),
1913                Ref::new("TableReferenceSegment").to_matchable(),
1914                Bracketed::new(vec![
1915                    Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()])
1916                        .config(|this| this.allow_trailing = true)
1917                        .to_matchable(),
1918                ])
1919                .config(|this| this.optional())
1920                .to_matchable(),
1921                AnyNumberOf::new(vec![
1922                    Sequence::new(vec![
1923                        Ref::keyword("WITH").to_matchable(),
1924                        Ref::keyword("CONNECTION").to_matchable(),
1925                        Ref::new("TableReferenceSegment").to_matchable(),
1926                    ])
1927                    .config(|this| this.optional())
1928                    .to_matchable(),
1929                    Sequence::new(vec![
1930                        Ref::keyword("WITH").to_matchable(),
1931                        Ref::keyword("PARTITION").to_matchable(),
1932                        Ref::keyword("COLUMNS").to_matchable(),
1933                        Bracketed::new(vec![
1934                            Delimited::new(vec![
1935                                Ref::new("ColumnDefinitionSegment").to_matchable(),
1936                            ])
1937                            .config(|this| this.allow_trailing = true)
1938                            .to_matchable(),
1939                        ])
1940                        .config(|this| this.optional())
1941                        .to_matchable(),
1942                    ])
1943                    .config(|this| this.optional())
1944                    .to_matchable(),
1945                    Ref::new("OptionsSegment").optional().to_matchable(),
1946                ])
1947                .to_matchable(),
1948            ])
1949            .to_matchable()
1950        })
1951        .to_matchable()
1952        .into(),
1953    )]);
1954
1955    dialect.add([(
1956        "CreateExternalTableStatementSegment".into(),
1957        NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| {
1958            Sequence::new(vec![
1959                Ref::keyword("CREATE").to_matchable(),
1960                Sequence::new(vec![
1961                    Ref::keyword("OR").optional().to_matchable(),
1962                    Ref::keyword("REPLACE").optional().to_matchable(),
1963                ])
1964                .config(|this| this.optional())
1965                .to_matchable(),
1966                Ref::keyword("EXTERNAL").to_matchable(),
1967                Ref::keyword("TABLE").to_matchable(),
1968                Sequence::new(vec![
1969                    Ref::keyword("IF").optional().to_matchable(),
1970                    Ref::keyword("NOT").optional().to_matchable(),
1971                    Ref::keyword("EXISTS").optional().to_matchable(),
1972                ])
1973                .config(|this| this.optional())
1974                .to_matchable(),
1975                Ref::new("TableReferenceSegment").to_matchable(),
1976                Bracketed::new(vec![
1977                    Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()])
1978                        .config(|this| this.allow_trailing = true)
1979                        .to_matchable(),
1980                ])
1981                .config(|this| this.optional())
1982                .to_matchable(),
1983                AnyNumberOf::new(vec![
1984                    Sequence::new(vec![
1985                        Ref::keyword("WITH").to_matchable(),
1986                        Ref::keyword("CONNECTION").to_matchable(),
1987                        Ref::new("TableReferenceSegment").to_matchable(),
1988                    ])
1989                    .config(|this| this.optional())
1990                    .to_matchable(),
1991                    Sequence::new(vec![
1992                        Ref::keyword("WITH").to_matchable(),
1993                        Ref::keyword("PARTITION").to_matchable(),
1994                        Ref::keyword("COLUMNS").to_matchable(),
1995                        Bracketed::new(vec![
1996                            Delimited::new(vec![
1997                                Ref::new("ColumnDefinitionSegment").to_matchable(),
1998                            ])
1999                            .config(|this| this.allow_trailing = true)
2000                            .to_matchable(),
2001                        ])
2002                        .config(|this| this.optional())
2003                        .to_matchable(),
2004                    ])
2005                    .config(|this| this.optional())
2006                    .to_matchable(),
2007                    Ref::new("OptionsSegment").optional().to_matchable(),
2008                ])
2009                .to_matchable(),
2010            ])
2011            .to_matchable()
2012        })
2013        .to_matchable()
2014        .into(),
2015    )]);
2016
2017    dialect.replace_grammar(
2018        "CreateViewStatementSegment",
2019        Sequence::new(vec![
2020            Ref::keyword("CREATE").to_matchable(),
2021            Ref::new("OrReplaceGrammar").optional().to_matchable(),
2022            Ref::keyword("VIEW").to_matchable(),
2023            Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2024            Ref::new("TableReferenceSegment").to_matchable(),
2025            Ref::new("BracketedColumnReferenceListGrammar")
2026                .optional()
2027                .to_matchable(),
2028            Ref::new("OptionsSegment").optional().to_matchable(),
2029            Ref::keyword("AS").to_matchable(),
2030            optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(),
2031        ])
2032        .to_matchable(),
2033    );
2034
2035    dialect.add([
2036        (
2037            "AlterViewStatementSegment".into(),
2038            NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| {
2039                Sequence::new(vec![
2040                    Ref::keyword("ALTER").to_matchable(),
2041                    Ref::keyword("VIEW").to_matchable(),
2042                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2043                    Ref::new("TableReferenceSegment").to_matchable(),
2044                    Ref::keyword("SET").to_matchable(),
2045                    Ref::new("OptionsSegment").to_matchable(),
2046                ])
2047                .to_matchable()
2048            })
2049            .to_matchable()
2050            .into(),
2051        ),
2052        (
2053            "CreateMaterializedViewStatementSegment".into(),
2054            NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| {
2055                Sequence::new(vec![
2056                    Ref::keyword("CREATE").to_matchable(),
2057                    Ref::new("OrReplaceGrammar").optional().to_matchable(),
2058                    Ref::keyword("MATERIALIZED").to_matchable(),
2059                    Ref::keyword("VIEW").to_matchable(),
2060                    Ref::new("IfNotExistsGrammar").optional().to_matchable(),
2061                    Ref::new("TableReferenceSegment").to_matchable(),
2062                    Ref::new("PartitionBySegment").optional().to_matchable(),
2063                    Ref::new("ClusterBySegment").optional().to_matchable(),
2064                    Ref::new("OptionsSegment").optional().to_matchable(),
2065                    Ref::keyword("AS").to_matchable(),
2066                    optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()])
2067                        .to_matchable(),
2068                ])
2069                .to_matchable()
2070            })
2071            .to_matchable()
2072            .into(),
2073        ),
2074        (
2075            "AlterMaterializedViewStatementSegment".into(),
2076            NodeMatcher::new(SyntaxKind::AlterMaterializedViewSetOptionsStatement, |_| {
2077                Sequence::new(vec![
2078                    Ref::keyword("ALTER").to_matchable(),
2079                    Ref::keyword("MATERIALIZED").to_matchable(),
2080                    Ref::keyword("VIEW").to_matchable(),
2081                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2082                    Ref::new("TableReferenceSegment").to_matchable(),
2083                    Ref::keyword("SET").to_matchable(),
2084                    Ref::new("OptionsSegment").to_matchable(),
2085                ])
2086                .to_matchable()
2087            })
2088            .to_matchable()
2089            .into(),
2090        ),
2091        (
2092            "DropMaterializedViewStatementSegment".into(),
2093            NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| {
2094                Sequence::new(vec![
2095                    Ref::keyword("DROP").to_matchable(),
2096                    Ref::keyword("MATERIALIZED").to_matchable(),
2097                    Ref::keyword("VIEW").to_matchable(),
2098                    Ref::new("IfExistsGrammar").optional().to_matchable(),
2099                    Ref::new("TableReferenceSegment").to_matchable(),
2100                ])
2101                .to_matchable()
2102            })
2103            .to_matchable()
2104            .into(),
2105        ),
2106        (
2107            "ParameterizedSegment".into(),
2108            NodeMatcher::new(SyntaxKind::ParameterizedExpression, |_| {
2109                one_of(vec![
2110                    Ref::new("AtSignLiteralSegment").to_matchable(),
2111                    Ref::new("QuestionMarkSegment").to_matchable(),
2112                ])
2113                .to_matchable()
2114            })
2115            .to_matchable()
2116            .into(),
2117        ),
2118        (
2119            "PivotForClauseSegment".into(),
2120            NodeMatcher::new(SyntaxKind::PivotForClause, |_| {
2121                Sequence::new(vec![
2122                    Ref::new("BaseExpressionElementGrammar").to_matchable(),
2123                ])
2124                .config(|this| {
2125                    this.terminators = vec![Ref::keyword("IN").to_matchable()];
2126                    this.parse_mode(ParseMode::Greedy);
2127                })
2128                .to_matchable()
2129            })
2130            .to_matchable()
2131            .into(),
2132        ),
2133        (
2134            "FromPivotExpressionSegment".into(),
2135            NodeMatcher::new(SyntaxKind::FromPivotExpression, |_| {
2136                Sequence::new(vec![
2137                    Ref::keyword("PIVOT").to_matchable(),
2138                    Bracketed::new(vec![
2139                        Delimited::new(vec![
2140                            Sequence::new(vec![
2141                                Ref::new("FunctionSegment").to_matchable(),
2142                                Ref::new("AliasExpressionSegment").optional().to_matchable(),
2143                            ])
2144                            .to_matchable(),
2145                        ])
2146                        .to_matchable(),
2147                        Ref::keyword("FOR").to_matchable(),
2148                        Ref::new("PivotForClauseSegment").to_matchable(),
2149                        Ref::keyword("IN").to_matchable(),
2150                        Bracketed::new(vec![
2151                            Delimited::new(vec![
2152                                Sequence::new(vec![
2153                                    Ref::new("LiteralGrammar").to_matchable(),
2154                                    Ref::new("AliasExpressionSegment").optional().to_matchable(),
2155                                ])
2156                                .to_matchable(),
2157                            ])
2158                            .to_matchable(),
2159                        ])
2160                        .to_matchable(),
2161                    ])
2162                    .to_matchable(),
2163                ])
2164                .to_matchable()
2165            })
2166            .to_matchable()
2167            .into(),
2168        ),
2169        (
2170            "UnpivotAliasExpressionSegment".into(),
2171            NodeMatcher::new(SyntaxKind::AliasExpression, |_| {
2172                Sequence::new(vec![
2173                    MetaSegment::indent().to_matchable(),
2174                    Ref::keyword("AS").optional().to_matchable(),
2175                    one_of(vec![
2176                        Ref::new("QuotedLiteralSegment").to_matchable(),
2177                        Ref::new("NumericLiteralSegment").to_matchable(),
2178                    ])
2179                    .to_matchable(),
2180                    MetaSegment::dedent().to_matchable(),
2181                ])
2182                .to_matchable()
2183            })
2184            .to_matchable()
2185            .into(),
2186        ),
2187    ]);
2188
2189    dialect.add([(
2190        "FromUnpivotExpressionSegment".into(),
2191        NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_| {
2192            Sequence::new(vec![
2193                Ref::keyword("UNPIVOT").to_matchable(),
2194                Sequence::new(vec![
2195                    one_of(vec![
2196                        Ref::keyword("INCLUDE").to_matchable(),
2197                        Ref::keyword("EXCLUDE").to_matchable(),
2198                    ])
2199                    .to_matchable(),
2200                    Ref::keyword("NULLS").to_matchable(),
2201                ])
2202                .config(|this| this.optional())
2203                .to_matchable(),
2204                one_of(vec![
2205                    // single column unpivot
2206                    Bracketed::new(vec![
2207                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2208                        Ref::keyword("FOR").to_matchable(),
2209                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2210                        Ref::keyword("IN").to_matchable(),
2211                        Bracketed::new(vec![
2212                            Delimited::new(vec![
2213                                Sequence::new(vec![
2214                                    Delimited::new(vec![
2215                                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2216                                    ])
2217                                    .to_matchable(),
2218                                    Ref::new("UnpivotAliasExpressionSegment")
2219                                        .optional()
2220                                        .to_matchable(),
2221                                ])
2222                                .to_matchable(),
2223                            ])
2224                            .to_matchable(),
2225                        ])
2226                        .to_matchable(),
2227                    ])
2228                    .to_matchable(),
2229                    // multi column unpivot
2230                    Bracketed::new(vec![
2231                        Bracketed::new(vec![
2232                            Delimited::new(vec![
2233                                Ref::new("SingleIdentifierGrammar").to_matchable(),
2234                            ])
2235                            .config(|this| this.min_delimiters = 1)
2236                            .to_matchable(),
2237                        ])
2238                        .to_matchable(),
2239                        Ref::keyword("FOR").to_matchable(),
2240                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2241                        Ref::keyword("IN").to_matchable(),
2242                        Bracketed::new(vec![
2243                            Delimited::new(vec![
2244                                Sequence::new(vec![
2245                                    Bracketed::new(vec![
2246                                        Delimited::new(vec![
2247                                            Ref::new("SingleIdentifierGrammar").to_matchable(),
2248                                        ])
2249                                        .config(|this| this.min_delimiters = 1)
2250                                        .to_matchable(),
2251                                    ])
2252                                    .to_matchable(),
2253                                    Ref::new("UnpivotAliasExpressionSegment")
2254                                        .optional()
2255                                        .to_matchable(),
2256                                ])
2257                                .to_matchable(),
2258                            ])
2259                            .to_matchable(),
2260                        ])
2261                        .to_matchable(),
2262                    ])
2263                    .to_matchable(),
2264                ])
2265                .to_matchable(),
2266            ])
2267            .to_matchable()
2268        })
2269        .to_matchable()
2270        .into(),
2271    )]);
2272
2273    dialect.add([
2274        (
2275            "InsertStatementSegment".into(),
2276            NodeMatcher::new(SyntaxKind::InsertStatement, |_| {
2277                Sequence::new(vec![
2278                    Ref::keyword("INSERT").to_matchable(),
2279                    Ref::keyword("INTO").optional().to_matchable(),
2280                    Ref::new("TableReferenceSegment").to_matchable(),
2281                    Ref::new("BracketedColumnReferenceListGrammar")
2282                        .optional()
2283                        .to_matchable(),
2284                    Ref::new("SelectableGrammar").to_matchable(),
2285                ])
2286                .to_matchable()
2287            })
2288            .to_matchable()
2289            .into(),
2290        ),
2291        (
2292            "SamplingExpressionSegment".into(),
2293            NodeMatcher::new(SyntaxKind::SampleExpression, |_| {
2294                Sequence::new(vec![
2295                    Ref::keyword("TABLESAMPLE").to_matchable(),
2296                    Ref::keyword("SYSTEM").to_matchable(),
2297                    Bracketed::new(vec![
2298                        Ref::new("NumericLiteralSegment").to_matchable(),
2299                        Ref::keyword("PERCENT").to_matchable(),
2300                    ])
2301                    .to_matchable(),
2302                ])
2303                .to_matchable()
2304            })
2305            .to_matchable()
2306            .into(),
2307        ),
2308        (
2309            "MergeMatchSegment".into(),
2310            NodeMatcher::new(SyntaxKind::MergeMatch, |_| {
2311                AnyNumberOf::new(vec![
2312                    Ref::new("MergeMatchedClauseSegment").to_matchable(),
2313                    Ref::new("MergeNotMatchedByTargetClauseSegment").to_matchable(),
2314                    Ref::new("MergeNotMatchedBySourceClauseSegment").to_matchable(),
2315                ])
2316                .config(|this| this.min_times = 1)
2317                .to_matchable()
2318            })
2319            .to_matchable()
2320            .into(),
2321        ),
2322        (
2323            "MergeNotMatchedByTargetClauseSegment".into(),
2324            NodeMatcher::new(SyntaxKind::NotMatchedByTargetClause, |_| {
2325                Sequence::new(vec![
2326                    Ref::keyword("WHEN").to_matchable(),
2327                    Ref::keyword("NOT").to_matchable(),
2328                    Ref::keyword("MATCHED").to_matchable(),
2329                    Sequence::new(vec![
2330                        Ref::keyword("BY").to_matchable(),
2331                        Ref::keyword("TARGET").to_matchable(),
2332                    ])
2333                    .config(|this| this.optional())
2334                    .to_matchable(),
2335                    Sequence::new(vec![
2336                        Ref::keyword("AND").to_matchable(),
2337                        Ref::new("ExpressionSegment").to_matchable(),
2338                    ])
2339                    .config(|this| this.optional())
2340                    .to_matchable(),
2341                    Ref::keyword("THEN").to_matchable(),
2342                    MetaSegment::indent().to_matchable(),
2343                    Ref::new("MergeInsertClauseSegment").to_matchable(),
2344                    MetaSegment::dedent().to_matchable(),
2345                ])
2346                .to_matchable()
2347            })
2348            .to_matchable()
2349            .into(),
2350        ),
2351        (
2352            "MergeNotMatchedBySourceClauseSegment".into(),
2353            NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_| {
2354                Sequence::new(vec![
2355                    Ref::keyword("WHEN").to_matchable(),
2356                    Ref::keyword("NOT").to_matchable(),
2357                    Ref::keyword("MATCHED").to_matchable(),
2358                    Ref::keyword("BY").to_matchable(),
2359                    Ref::keyword("SOURCE").to_matchable(),
2360                    Sequence::new(vec![
2361                        Ref::keyword("AND").to_matchable(),
2362                        Ref::new("ExpressionSegment").to_matchable(),
2363                    ])
2364                    .config(|this| this.optional())
2365                    .to_matchable(),
2366                    Ref::keyword("THEN").to_matchable(),
2367                    MetaSegment::indent().to_matchable(),
2368                    one_of(vec![
2369                        Ref::new("MergeUpdateClauseSegment").to_matchable(),
2370                        Ref::new("MergeDeleteClauseSegment").to_matchable(),
2371                    ])
2372                    .to_matchable(),
2373                    MetaSegment::dedent().to_matchable(),
2374                ])
2375                .to_matchable()
2376            })
2377            .to_matchable()
2378            .into(),
2379        ),
2380        (
2381            "MergeInsertClauseSegment".into(),
2382            NodeMatcher::new(SyntaxKind::MergeInsertClause, |_| {
2383                one_of(vec![
2384                    Sequence::new(vec![
2385                        Ref::keyword("INSERT").to_matchable(),
2386                        MetaSegment::indent().to_matchable(),
2387                        Ref::new("BracketedColumnReferenceListGrammar")
2388                            .optional()
2389                            .to_matchable(),
2390                        MetaSegment::dedent().to_matchable(),
2391                        Ref::new("ValuesClauseSegment").optional().to_matchable(),
2392                    ])
2393                    .to_matchable(),
2394                    Sequence::new(vec![
2395                        Ref::keyword("INSERT").to_matchable(),
2396                        Ref::keyword("ROW").to_matchable(),
2397                    ])
2398                    .to_matchable(),
2399                ])
2400                .to_matchable()
2401            })
2402            .to_matchable()
2403            .into(),
2404        ),
2405    ]);
2406
2407    dialect.add([
2408        (
2409            "DeleteStatementSegment".into(),
2410            NodeMatcher::new(SyntaxKind::DeleteStatement, |_| {
2411                Sequence::new(vec![
2412                    Ref::keyword("DELETE").to_matchable(),
2413                    Ref::keyword("FROM").optional().to_matchable(),
2414                    Ref::new("TableReferenceSegment").to_matchable(),
2415                    Ref::new("AliasExpressionSegment").optional().to_matchable(),
2416                    Ref::new("WhereClauseSegment").optional().to_matchable(),
2417                ])
2418                .to_matchable()
2419            })
2420            .to_matchable()
2421            .into(),
2422        ),
2423        (
2424            "ExportStatementSegment".into(),
2425            NodeMatcher::new(SyntaxKind::ExportStatement, |_| {
2426                Sequence::new(vec![
2427                    Ref::keyword("EXPORT").to_matchable(),
2428                    Ref::keyword("DATA").to_matchable(),
2429                    Sequence::new(vec![
2430                        Ref::keyword("WITH").to_matchable(),
2431                        Ref::keyword("CONNECTION").to_matchable(),
2432                        Ref::new("ObjectReferenceSegment").to_matchable(),
2433                    ])
2434                    .config(|this| this.optional())
2435                    .to_matchable(),
2436                    Ref::keyword("OPTIONS").to_matchable(),
2437                    Bracketed::new(vec![
2438                        Delimited::new(vec![
2439                            Sequence::new(vec![
2440                                one_of(vec![
2441                                    StringParser::new("compression", SyntaxKind::ExportOption)
2442                                        .to_matchable(),
2443                                    StringParser::new("field_delimiter", SyntaxKind::ExportOption)
2444                                        .to_matchable(),
2445                                    StringParser::new("format", SyntaxKind::ExportOption)
2446                                        .to_matchable(),
2447                                    StringParser::new("uri", SyntaxKind::ExportOption)
2448                                        .to_matchable(),
2449                                ])
2450                                .to_matchable(),
2451                                Ref::new("EqualsSegment").to_matchable(),
2452                                Ref::new("QuotedLiteralSegment").to_matchable(),
2453                            ])
2454                            .to_matchable(),
2455                            Sequence::new(vec![
2456                                one_of(vec![
2457                                    StringParser::new("header", SyntaxKind::ExportOption)
2458                                        .to_matchable(),
2459                                    StringParser::new("overwrite", SyntaxKind::ExportOption)
2460                                        .to_matchable(),
2461                                    StringParser::new(
2462                                        "use_avro_logical_types",
2463                                        SyntaxKind::ExportOption,
2464                                    )
2465                                    .to_matchable(),
2466                                ])
2467                                .to_matchable(),
2468                                Ref::new("EqualsSegment").to_matchable(),
2469                                one_of(vec![
2470                                    Ref::keyword("TRUE").to_matchable(),
2471                                    Ref::keyword("FALSE").to_matchable(),
2472                                ])
2473                                .to_matchable(),
2474                            ])
2475                            .to_matchable(),
2476                        ])
2477                        .to_matchable(),
2478                    ])
2479                    .to_matchable(),
2480                    Ref::keyword("AS").to_matchable(),
2481                    Ref::new("SelectableGrammar").to_matchable(),
2482                ])
2483                .to_matchable()
2484            })
2485            .to_matchable()
2486            .into(),
2487        ),
2488        (
2489            "ProcedureNameSegment".into(),
2490            NodeMatcher::new(SyntaxKind::ProcedureName, |_| {
2491                Sequence::new(vec![
2492                    AnyNumberOf::new(vec![
2493                        Sequence::new(vec![
2494                            Ref::new("SingleIdentifierGrammar").to_matchable(),
2495                            Ref::new("DotSegment").to_matchable(),
2496                        ])
2497                        .to_matchable(),
2498                    ])
2499                    .to_matchable(),
2500                    one_of(vec![
2501                        Ref::new("ProcedureNameIdentifierSegment").to_matchable(),
2502                        Ref::new("QuotedIdentifierSegment").to_matchable(),
2503                    ])
2504                    .to_matchable(),
2505                ])
2506                .config(|this| this.allow_gaps = false)
2507                .to_matchable()
2508            })
2509            .to_matchable()
2510            .into(),
2511        ),
2512    ]);
2513
2514    dialect.add([
2515        (
2516            "QuotedIdentifierSegment".into(),
2517            TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier)
2518                .to_matchable()
2519                .into(),
2520        ),
2521        (
2522            "NumericLiteralSegment".into(),
2523            one_of(vec![
2524                TypedParser::new(SyntaxKind::NumericLiteral, SyntaxKind::NumericLiteral)
2525                    .to_matchable(),
2526                Ref::new("ParameterizedSegment").to_matchable(),
2527            ])
2528            .to_matchable()
2529            .into(),
2530        ),
2531        (
2532            "QuotedLiteralSegment".into(),
2533            one_of(vec![
2534                Ref::new("SingleQuotedLiteralSegment").to_matchable(),
2535                Ref::new("DoubleQuotedLiteralSegment").to_matchable(),
2536            ])
2537            .to_matchable()
2538            .into(),
2539        ),
2540        (
2541            "LiteralGrammar".into(),
2542            dialect
2543                .grammar("LiteralGrammar")
2544                .copy(
2545                    Some(vec![Ref::new("ParameterizedSegment").to_matchable()]),
2546                    None,
2547                    None,
2548                    None,
2549                    Vec::new(),
2550                    false,
2551                )
2552                .into(),
2553        ),
2554        (
2555            "PostTableExpressionGrammar".into(),
2556            Sequence::new(vec![
2557                Sequence::new(vec![
2558                    Ref::keyword("FOR").to_matchable(),
2559                    one_of(vec![
2560                        Ref::keyword("SYSTEM_TIME").to_matchable(),
2561                        Sequence::new(vec![
2562                            Ref::keyword("SYSTEM").to_matchable(),
2563                            Ref::keyword("TIME").to_matchable(),
2564                        ])
2565                        .to_matchable(),
2566                    ])
2567                    .to_matchable(),
2568                    Ref::keyword("AS").to_matchable(),
2569                    Ref::keyword("OF").to_matchable(),
2570                    Ref::new("ExpressionSegment").to_matchable(),
2571                ])
2572                .config(|this| this.optional())
2573                .to_matchable(),
2574                Sequence::new(vec![
2575                    Ref::keyword("WITH").to_matchable(),
2576                    Ref::keyword("OFFSET").to_matchable(),
2577                    Sequence::new(vec![
2578                        Ref::keyword("AS").to_matchable(),
2579                        Ref::new("SingleIdentifierGrammar").to_matchable(),
2580                    ])
2581                    .config(|this| this.optional())
2582                    .to_matchable(),
2583                ])
2584                .config(|this| this.optional())
2585                .to_matchable(),
2586            ])
2587            .to_matchable()
2588            .into(),
2589        ),
2590        (
2591            "FunctionNameIdentifierSegment".into(),
2592            one_of(vec![
2593                RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::FunctionNameIdentifier)
2594                    .anti_template("^(STRUCT|ARRAY)$")
2595                    .to_matchable(),
2596                RegexParser::new("`[^`]*`", SyntaxKind::FunctionNameIdentifier).to_matchable(),
2597            ])
2598            .to_matchable()
2599            .into(),
2600        ),
2601    ]);
2602
2603    dialect.expand();
2604    dialect
2605}