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