sqruff_lib_dialects/
mysql.rs1use sqruff_lib_core::dialects::Dialect;
2use sqruff_lib_core::dialects::init::DialectKind;
3use sqruff_lib_core::dialects::syntax::SyntaxKind;
4use sqruff_lib_core::helpers::{Config, ToMatchable};
5use sqruff_lib_core::parser::grammar::Ref;
6use sqruff_lib_core::parser::grammar::anyof::one_of;
7use sqruff_lib_core::parser::lexer::Matcher;
8use sqruff_lib_core::parser::node_matcher::NodeMatcher;
9
10use super::ansi;
11
12pub fn dialect() -> Dialect {
13 raw_dialect().config(|dialect| dialect.expand())
14}
15
16pub fn raw_dialect() -> Dialect {
17 let mut mysql = ansi::raw_dialect();
18 mysql.name = DialectKind::Mysql;
19
20 mysql.patch_lexer_matchers(vec![Matcher::regex(
21 "inline_comment",
22 r"(^--|-- |#)[^\n]*",
23 SyntaxKind::InlineComment,
24 )]);
25
26 mysql.add([
27 (
28 "DivBinaryOperatorSegment".into(),
29 NodeMatcher::new(SyntaxKind::BinaryOperator, |_| {
30 Ref::keyword("DIV").to_matchable()
31 })
32 .to_matchable()
33 .into(),
34 ),
35 (
36 "ArithmeticBinaryOperatorGrammar".into(),
37 one_of(vec![
38 Ref::new("PlusSegment").to_matchable(),
39 Ref::new("MinusSegment").to_matchable(),
40 Ref::new("DivideSegment").to_matchable(),
41 Ref::new("MultiplySegment").to_matchable(),
42 Ref::new("ModuloSegment").to_matchable(),
43 Ref::new("BitwiseAndSegment").to_matchable(),
44 Ref::new("BitwiseOrSegment").to_matchable(),
45 Ref::new("BitwiseXorSegment").to_matchable(),
46 Ref::new("BitwiseLShiftSegment").to_matchable(),
47 Ref::new("BitwiseRShiftSegment").to_matchable(),
48 Ref::new("DivBinaryOperatorSegment").to_matchable(),
49 ])
50 .to_matchable()
51 .into(),
52 ),
53 ]);
54
55 mysql
56}