Skip to content

Commit 56b3402

Browse files
author
Kevin Sittner
authored
Merge pull request #74 from malloydata/grammar-update
Update TextMate to reflect Malloy-in-SQL, data type fixes in VSCode
2 parents d382f8c + e2f5277 commit 56b3402

1 file changed

Lines changed: 82 additions & 39 deletions

File tree

malloy.tmGrammar.json

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
{
22
"scopeName": "source.malloy",
33
"patterns": [
4-
{"include": "#sql-string"},
5-
{"include": "#comments"},
6-
{"include": "#tags"},
7-
{"include": "#strings"},
8-
{"include": "#numbers"},
9-
{"include": "#keywords"},
10-
{"include": "#properties"},
11-
{"include": "#functions"},
12-
{"include": "#dates"},
13-
{"include": "#identifiers-quoted"},
14-
{"include": "#types"},
15-
{"include": "#constants"},
16-
{"include": "#timeframes"},
17-
{"include": "#identifiers-unquoted"}
4+
{"include": "#malloy-language"}
185
],
196
"repository": {
20-
"query-in-sql": {
21-
"begin": "%{",
22-
"name": "source.internal-query-stuff",
23-
"end": "}%?",
7+
"malloy-language": {
248
"patterns": [
259
{"include": "#sql-string"},
2610
{"include": "#comments"},
@@ -30,25 +14,62 @@
3014
{"include": "#keywords"},
3115
{"include": "#properties"},
3216
{"include": "#functions"},
33-
{"include": "#dates"},
17+
{"include": "#datetimes"},
3418
{"include": "#identifiers-quoted"},
3519
{"include": "#types"},
3620
{"include": "#constants"},
3721
{"include": "#timeframes"},
3822
{"include": "#identifiers-unquoted"}
3923
]
4024
},
25+
"malloy-matched": {
26+
"begin": "{",
27+
"end": "}",
28+
"patterns": [
29+
{"include": "#malloy-matched"},
30+
{"include": "#malloy-language"}
31+
]
32+
},
33+
"malloy-in-sql": {
34+
"begin": "%{",
35+
"name": "source.malloy-in-sql",
36+
"end": "}%?",
37+
"patterns": [
38+
{"include": "#malloy-matched"},
39+
{"include": "#malloy-language"}
40+
]
41+
},
4142
"sql-string": {
42-
"begin": "\"\"\"",
43-
"end": "\"\"\"",
44-
"beginCaptures": {
45-
"0": {"name": "punctuation.sql-block.open"}
46-
},
47-
"endCaptures": {
48-
"0": {"name": "punctuation.sql-block.close"}
49-
},
50-
"name": "source.sql",
51-
"patterns": [{"include": "#query-in-sql"}, {"include": "source.sql"}]
43+
"patterns":
44+
[
45+
{
46+
"begin": "\\b(select)(\\s*:\\s*)(\"\"\")",
47+
"end": "\"\"\"",
48+
"beginCaptures": {
49+
"1": {"name": "keyword.control.select"},
50+
"3": {"name": "punctuation.sql-block.open"}
51+
},
52+
"endCaptures": {
53+
"0": {"name": "punctuation.sql-block.close"}
54+
},
55+
"name": "source.sql",
56+
"patterns": [{"include": "#malloy-in-sql"}, {"include": "source.sql"}]
57+
},
58+
{
59+
"begin": "(\\b[A-Za-z_][A-Za-z_0-9]*)(\\s*\\.\\s*)(sql)(\\s*\\(\\s*)(\"\"\")",
60+
"end": "\"\"\"",
61+
"beginCaptures": {
62+
"1": {"name": "variable.other"},
63+
"3": {"name": "keyword.control.sql"},
64+
"5": {"name": "punctuation.sql-block.open"}
65+
},
66+
"endCaptures": {
67+
"0": {"name": "punctuation.sql-block.close"}
68+
},
69+
"name": "source.sql",
70+
"patterns": [{"include": "#malloy-in-sql"}, {"include": "source.sql"}]
71+
}
72+
]
5273
},
5374
"functions": {
5475
"patterns": [
@@ -80,10 +101,14 @@
80101
}
81102
]
82103
},
83-
"dates": {
104+
"datetimes": {
84105
"patterns": [
85106
{
86-
"match": "(?i)@[0-9A-Z-]*(\\s[0-9A-Z-][0-9A-Z-](:[0-9A-Z-][0-9A-Z-])?(:[0-9A-Z-][0-9A-Z-])?)?",
107+
"match": "(?i)@[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}((:[0-9]{2})(([\\.,][0-9]+)(\\[[A-Za-z_/]+\\])?)?)?",
108+
"name": "constant.numeric.timestamp"
109+
},
110+
{
111+
"match": "(?i)@[0-9]{4}(-Q[1-4]|-[0-9]{2}(-[0-9]{2}(-WK)?)?)?",
87112
"name": "constant.numeric.date"
88113
}
89114
]
@@ -99,7 +124,7 @@
99124
"identifiers-unquoted": {
100125
"patterns": [
101126
{
102-
"match": "(?i)\\b[A-z_][A-z_0-9]*\\b",
127+
"match": "(?i)\\b[A-Za-z_][A-Za-z_0-9]*\\b",
103128
"name": "variable.other"
104129
}
105130
]
@@ -181,7 +206,7 @@
181206
"patterns": [{"include": "#tag-values"}]
182207
},
183208
{
184-
"begin": "##!?\\s",
209+
"begin": "##\\s",
185210
"end": "\\n",
186211
"beginCaptures": {
187212
"0": {"name": "support.type.property-name.json"}
@@ -222,7 +247,7 @@
222247
"endCaptures": {
223248
"0": {"name": "punctuation.definition.string.end"}
224249
},
225-
"name": "string.unquoted.single",
250+
"name": "string.quoted.single",
226251
"patterns": [{"include": "#escapes"}]
227252
},
228253
{
@@ -234,28 +259,46 @@
234259
"endCaptures": {
235260
"0": {"name": "punctuation.definition.string.end"}
236261
},
237-
"name": "string.unquoted.double",
262+
"name": "string.quoted.double",
238263
"patterns": [{"include": "#escapes"}]
239264
},
265+
{
266+
"begin": "\"\"\"",
267+
"end": "\"\"\"",
268+
"beginCaptures": {
269+
"0": {"name": "punctuation.definition.string.begin"}
270+
},
271+
"endCaptures": {
272+
"0": {"name": "punctuation.definition.string.end"}
273+
},
274+
"name": "string.quoted.triple"
275+
},
240276
{
241277
"begin": "(?i)[r|/]'",
242278
"end": "'",
243279
"name": "string.regexp",
244-
"patterns": [{"include": "#escapes"}]
280+
"patterns": [{"include": "#regex-escapes"}]
245281
}
246282
],
247283
"repository": {
248284
"escapes": {
249285
"name": "constant.character.escape",
250-
"match": "\\\\(x\\h{2}|[0-2][0-7]{0,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)",
286+
"match": "\\\\(u[A-Fa-f0-9]{4}|.)",
287+
"captures": {
288+
"0": {"name": "constant.character.escape"}
289+
}
290+
},
291+
"regex-escapes": {
292+
"name": "constant.character.escape",
293+
"match": "\\\\.",
251294
"captures": {
252295
"0": {"name": "constant.character.escape"}
253296
}
254297
}
255298
}
256299
},
257300
"numbers": {
258-
"match": "\\b((0|[1-9][0-9]*)(\\.[0-9]*)?| \\.[0-9]+)\\b",
301+
"match": "(?i)(\\b(0|[1-9][0-9]*(E[+-]?[0-9]+|\\.[0-9]*)?)|\\.[0-9]+)",
259302
"name": "constant.numeric"
260303
},
261304
"constants": {
@@ -491,4 +534,4 @@
491534
]
492535
}
493536
}
494-
}
537+
}

0 commit comments

Comments
 (0)