diff: Add SQL support

9674cb699c26ca78e8ef8e59d67f384afd3f172e
Alexis Sellier committed ago 1 parent 596a4647
crates/diff/src/bin/rustik-diff/builtins.rs +7 -1
8 8
/// Theme name used for built-in diff highlighting.
9 9
const THEME_NAME: &str = "rustik-catppuccin-mocha";
10 10
/// Built-in syntax theme JSON.
11 11
const THEME: &str = include_str!("../../themes/rustik-catppuccin-mocha.json");
12 12
/// Common syntax grammars loaded by the interactive pager.
13 -
const SYNTAXES: [SyntaxAsset; 15] = [
13 +
const SYNTAXES: [SyntaxAsset; 16] = [
14 14
    SyntaxAsset {
15 15
        source: syntax::syntaxes::C,
16 16
        file_types: &["c", "h"],
17 17
        dependencies: &[],
18 18
    },
79 79
    SyntaxAsset {
80 80
        source: syntax::syntaxes::SHELL,
81 81
        file_types: &["sh", "bash", "zsh"],
82 82
        dependencies: &[],
83 83
    },
84 +
    SyntaxAsset {
85 +
        source: syntax::syntaxes::SQL,
86 +
        file_types: &["sql"],
87 +
        dependencies: &[],
88 +
    },
84 89
    SyntaxAsset {
85 90
        source: syntax::syntaxes::TOML,
86 91
        file_types: &["toml"],
87 92
        dependencies: &[],
88 93
    },
238 243
            "index.html.erb",
239 244
            "script.py",
240 245
            "task.rb",
241 246
            "build.sh",
242 247
            "Cargo.toml",
248 +
            "schema.sql",
243 249
            "config.yml",
244 250
        ] {
245 251
            assert!(
246 252
                SYNTAXES
247 253
                    .iter()
script\n\ +0 -0
crates/highlight/src/lib.rs +1 -1
35 35
pub use raw::{RawCapture, RawGrammar, RawPattern, RawStyle, RawTheme, RawThemeRule};
36 36
pub use registry::{GrammarQuery, Registry};
37 37
pub use theme::{FontStyle, Rgb, Style, StyleSpan, Theme};
38 38
39 39
/// Maximum active include depth followed while matching recursive pattern sets.
40 -
pub const MAX_INCLUDE_DEPTH: usize = 8;
40 +
pub const MAX_INCLUDE_DEPTH: usize = 16;
41 41
42 42
#[cfg(test)]
43 43
#[allow(clippy::unwrap_used)]
44 44
mod tests;
crates/highlight/src/syntaxes.rs +3 -0
38 38
pub const RUST: &str = include_str!("../syntaxes/rust.json");
39 39
40 40
/// Shell grammar source.
41 41
pub const SHELL: &str = include_str!("../syntaxes/shellscript.json");
42 42
43 +
/// SQL grammar source.
44 +
pub const SQL: &str = include_str!("../syntaxes/sql.json");
45 +
43 46
/// TOML grammar source.
44 47
pub const TOML: &str = include_str!("../syntaxes/toml.json");
45 48
46 49
/// TypeScript grammar source.
47 50
pub const TYPESCRIPT: &str = include_str!("../syntaxes/typescript.json");
crates/highlight/syntaxes/sql.json added +200 -0
1 +
{
2 +
  "displayName": "SQL",
3 +
  "fileTypes": [
4 +
    "sql"
5 +
  ],
6 +
  "name": "sql",
7 +
  "patterns": [
8 +
    {
9 +
      "include": "#comments"
10 +
    },
11 +
    {
12 +
      "include": "#strings"
13 +
    },
14 +
    {
15 +
      "include": "#quoted-identifiers"
16 +
    },
17 +
    {
18 +
      "include": "#numbers"
19 +
    },
20 +
    {
21 +
      "include": "#constants"
22 +
    },
23 +
    {
24 +
      "include": "#functions"
25 +
    },
26 +
    {
27 +
      "include": "#data-types"
28 +
    },
29 +
    {
30 +
      "include": "#keywords"
31 +
    },
32 +
    {
33 +
      "include": "#operators"
34 +
    },
35 +
    {
36 +
      "include": "#punctuation"
37 +
    }
38 +
  ],
39 +
  "repository": {
40 +
    "comments": {
41 +
      "patterns": [
42 +
        {
43 +
          "begin": "/\\*",
44 +
          "beginCaptures": {
45 +
            "0": {
46 +
              "name": "punctuation.definition.comment.begin.sql"
47 +
            }
48 +
          },
49 +
          "end": "\\*/",
50 +
          "endCaptures": {
51 +
            "0": {
52 +
              "name": "punctuation.definition.comment.end.sql"
53 +
            }
54 +
          },
55 +
          "name": "comment.block.sql"
56 +
        },
57 +
        {
58 +
          "match": "--.*$",
59 +
          "name": "comment.line.double-dash.sql"
60 +
        }
61 +
      ]
62 +
    },
63 +
    "constants": {
64 +
      "patterns": [
65 +
        {
66 +
          "match": "\\b(?i:(true|false|null|unknown))\\b",
67 +
          "name": "constant.language.sql"
68 +
        },
69 +
        {
70 +
          "match": "\\b(?i:(current_date|current_time|current_timestamp|localtime|localtimestamp|session_user|system_user|user))\\b",
71 +
          "name": "constant.language.sql"
72 +
        }
73 +
      ]
74 +
    },
75 +
    "data-types": {
76 +
      "patterns": [
77 +
        {
78 +
          "match": "\\b(?i:(bigint|binary|bit|blob|boolean|char|character|clob|date|decimal|double|float|int|integer|interval|json|jsonb|numeric|real|serial|smallint|text|time|timestamp|uuid|varbinary|varchar|varying|xml))\\b",
79 +
          "name": "storage.type.sql"
80 +
        }
81 +
      ]
82 +
    },
83 +
    "functions": {
84 +
      "patterns": [
85 +
        {
86 +
          "match": "\\b(?i:(avg|cast|coalesce|count|date_part|date_trunc|extract|lower|max|min|nullif|round|string_agg|sum|upper))\\b(?=\\s*\\()",
87 +
          "name": "support.function.sql"
88 +
        }
89 +
      ]
90 +
    },
91 +
    "keywords": {
92 +
      "patterns": [
93 +
        {
94 +
          "match": "\\b(?i:(add|alter|analyze|asc|begin|by|cascade|column|commit|constraint|create|database|default|delete|desc|distinct|drop|exists|explain|foreign|from|grant|group|having|index|insert|into|join|key|limit|not|offset|on|order|primary|references|returning|rollback|schema|select|set|table|temporary|truncate|union|unique|update|values|view|where|with))\\b",
95 +
          "name": "keyword.other.sql"
96 +
        },
97 +
        {
98 +
          "match": "\\b(?i:(all|and|any|as|between|case|else|end|except|for|full|if|in|inner|intersect|is|left|like|or|outer|over|right|then|when))\\b",
99 +
          "name": "keyword.control.sql"
100 +
        }
101 +
      ]
102 +
    },
103 +
    "numbers": {
104 +
      "patterns": [
105 +
        {
106 +
          "match": "\\b[+-]?(?:\\d+\\.\\d+|\\d+|\\.\\d+)(?:[eE][+-]?\\d+)?\\b",
107 +
          "name": "constant.numeric.sql"
108 +
        }
109 +
      ]
110 +
    },
111 +
    "operators": {
112 +
      "patterns": [
113 +
        {
114 +
          "match": "(<>|!=|<=|>=|:=|[-+*/%<>=])",
115 +
          "name": "keyword.operator.sql"
116 +
        }
117 +
      ]
118 +
    },
119 +
    "punctuation": {
120 +
      "patterns": [
121 +
        {
122 +
          "match": "[(),.;]",
123 +
          "name": "punctuation.separator.sql"
124 +
        }
125 +
      ]
126 +
    },
127 +
    "quoted-identifiers": {
128 +
      "patterns": [
129 +
        {
130 +
          "begin": "\"",
131 +
          "beginCaptures": {
132 +
            "0": {
133 +
              "name": "punctuation.definition.string.begin.sql"
134 +
            }
135 +
          },
136 +
          "end": "\"",
137 +
          "endCaptures": {
138 +
            "0": {
139 +
              "name": "punctuation.definition.string.end.sql"
140 +
            }
141 +
          },
142 +
          "name": "string.quoted.double.sql",
143 +
          "patterns": [
144 +
            {
145 +
              "match": "\"\"",
146 +
              "name": "constant.character.escape.sql"
147 +
            }
148 +
          ]
149 +
        },
150 +
        {
151 +
          "begin": "`",
152 +
          "beginCaptures": {
153 +
            "0": {
154 +
              "name": "punctuation.definition.string.begin.sql"
155 +
            }
156 +
          },
157 +
          "end": "`",
158 +
          "endCaptures": {
159 +
            "0": {
160 +
              "name": "punctuation.definition.string.end.sql"
161 +
            }
162 +
          },
163 +
          "name": "string.quoted.other.sql",
164 +
          "patterns": [
165 +
            {
166 +
              "match": "``",
167 +
              "name": "constant.character.escape.sql"
168 +
            }
169 +
          ]
170 +
        }
171 +
      ]
172 +
    },
173 +
    "strings": {
174 +
      "patterns": [
175 +
        {
176 +
          "begin": "'",
177 +
          "beginCaptures": {
178 +
            "0": {
179 +
              "name": "punctuation.definition.string.begin.sql"
180 +
            }
181 +
          },
182 +
          "end": "'",
183 +
          "endCaptures": {
184 +
            "0": {
185 +
              "name": "punctuation.definition.string.end.sql"
186 +
            }
187 +
          },
188 +
          "name": "string.quoted.single.sql",
189 +
          "patterns": [
190 +
            {
191 +
              "match": "''",
192 +
              "name": "constant.character.escape.sql"
193 +
            }
194 +
          ]
195 +
        }
196 +
      ]
197 +
    }
198 +
  },
199 +
  "scopeName": "source.sql"
200 +
}
crates/highlight/tests/syntaxes.rs +1 -0
18 18
        syntaxes::MARKDOWN,
19 19
        syntaxes::PYTHON,
20 20
        syntaxes::RUBY,
21 21
        syntaxes::RUST,
22 22
        syntaxes::SHELL,
23 +
        syntaxes::SQL,
23 24
        syntaxes::TOML,
24 25
        syntaxes::TYPESCRIPT,
25 26
        syntaxes::YAML,
26 27
    ] {
27 28
        Grammar::from_str(source).unwrap();