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