-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtickscript.sublime-syntax
More file actions
282 lines (252 loc) · 8.61 KB
/
tickscript.sublime-syntax
File metadata and controls
282 lines (252 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
%YAML 1.2
---
name: TICKscript
file_extensions: [tick]
scope: source.tick
variables:
char_escape: \\x\h{2}|\\u\h{4}|\\U\h{8}|\\[0-7]{3}|\\.
# These are the only words that can't be used as identifiers.
keyword: \b(?:AND|OR|lambda|var|dbrp|TRUE|FALSE)\b
ident: \b(?!{{keyword}})[[:alpha:]_][[:alnum:]_]*\b
# https://docs.influxdata.com/kapacitor/v1.5/tick/syntax/#variables-and-literals
predeclared_type: \b(?:string|duration|int|float|lambda)\b
chain_operator: \||\.|@
contexts:
# EBNF grammar specification -> https://docs.influxdata.com/kapacitor/v1.5/reference/spec/
main:
- include: match-statement
match-statement:
- include: match-comment
- include: match-keyword-dbrp
- include: match-declaration
- include: match-expression
match-keyword-dbrp:
- match: '\bdbrp\b'
scope: keyword.control.tick
push:
- include: match-reference
- match: '\.'
scope: keyword.operator.tick
- include: pop-on-terminator
match-declaration:
- match: '\bvar\b'
scope: storage.type.keyword.var.tick
push:
- match: '{{ident}}'
scope: variable.declaration.tick
set: pop-var-type-or-assignment
# pop if matched nothing -> probable syntax error
- include: pop-before-nonblank
pop-var-type-or-assignment:
# added explicit regex matching to avoid ambiguities due to double division
# expressions like 'var a = c / foo(b) / e'
- match: '=(?=\s*\/)'
scope: keyword.operator.assignment.tick
push:
- include: match-regexp
- include: pop-on-terminator
- match: '='
scope: keyword.operator.assignment.tick
push:
- include: match-keyword-lambda
- include: match-brackets
- include: match-expression
- include: pop-on-terminator
- match: '{{predeclared_type}}'
scope: storage.type.tick support.type.builtin.tick
pop: true
- include: pop-before-nonblank
match-expression:
- match: '\b(stream|batch)\b'
scope: variable.language.tick
- include: match-chain
- include: match-function
- include: match-lambdaexpr # Added: needed to match "var a = b + c" (without parens)
# - include: match-primary # Removed: already contained in "lambdaexpr"
match-primary:
- match: '\('
scope: punctuation.section.parens.begin.tick
push:
- include: match-lambdaexpr
- match: '\)'
scope: punctuation.section.parens.end.tick
pop: true
- include: match-string
- include: match-reference
- include: match-number
# - include: match-regexp # Removed: moved regex matching only where possible to avoid ambiguities
- include: match-star
- include: match-function # Replaces LFunc because here it is the same and far more flexible
- match: '{{ident}}'
scope: variable.other.tick
match-function:
- match: '({{ident}})\s*(\()'
captures:
1: variable.function.tick
2: punctuation.section.parens.begin.tick
push:
- include: match-parameter
- match: ','
scope: punctuation.separator.tick
- match: '\)'
scope: punctuation.section.parens.end.tick
pop: true
match-chain:
- match: '{{chain_operator}}'
scope: keyword.operator.chain.tick
push:
- include: match-function
- match: '{{ident}}'
scope: variable.function.tick
pop: true
- include: pop-on-terminator
match-parameter:
- include: match-keyword-lambda
- include: match-expression
# - include: match-primary # Removed: Expression already matches Primary
match-keyword-lambda:
- match: '\b(lambda)(\:)'
captures:
1: keyword.control.tick
2: punctuation.separator.tick
push:
- include: match-lambdaexpr
- match: ''
pop: true
# Essentially a Primay with optional operators
match-lambdaexpr:
- include: match-primary
- include: match-operators
pop-before-nonblank:
- match: (?=\S)
pop: true
pop-on-terminator:
- match: $
pop: true
match-comment:
- match: '//'
scope: punctuation.definition.comment.tick
push:
- meta_scope: comment.line.tick
- match: '$\n?'
pop: true
match-regexp:
- match: '/'
scope: punctuation.definition.regexp.begin.tick
push:
- meta_scope: string.regexp.tick
- match: '\\/'
scope: string.regexp.tick
- match: '/'
scope: punctuation.definition.regexp.end.tick
pop: true
match-brackets:
- match: \[
scope: punctuation.section.brackets.begin.tick
push:
- include: match-lambdaexpr
- match: ','
scope: punctuation.separator.tick
- match: \]
scope: punctuation.section.brackets.end.tick
pop: true
match-operators: [
# regex operators may be followed by regex or Expression
{match: \=\~ ,
scope: keyword.operator.regex.tick,
push: [{include: match-regexp}, {include: pop-before-nonblank}]
},
{match: \!\~ ,
scope: keyword.operator.regex.tick,
push: [{include: match-regexp}, {include: pop-before-nonblank}]
},
{match: \+ , scope: keyword.operator.math.tick},
{match: \- , scope: keyword.operator.math.tick},
{match: \* , scope: keyword.operator.math.tick},
{match: / , scope: keyword.operator.math.tick},
{match: == , scope: keyword.operator.logical.tick},
{match: \!= , scope: keyword.operator.logical.tick},
{match: <= , scope: keyword.operator.logical.tick},
{match: \>= , scope: keyword.operator.logical.tick},
{match: < , scope: keyword.operator.logical.tick},
{match: \> , scope: keyword.operator.logical.tick},
{match: \! , scope: keyword.operator.logical.tick},
{match: \bAND\b , scope: keyword.operator.logical.tick},
{match: \bOR\b , scope: keyword.operator.logical.tick}
]
match-star:
- match: \*
scope: keyword.operator.tick
match-number:
- match: '\b\d+(?:\.\d+)?(?:[uµmshdw]|ms)\b'
scope: constant.numeric.tick
- match: '\b\d+(?:\.\d+)?\b'
scope: constant.numeric.tick
- match: '\b(?:TRUE|FALSE)\b'
scope: constant.boolean.tick
match-string:
- match: "'"
scope: punctuation.definition.string.begin.tick
push:
- meta_scope: string.quoted.single.tick
- include: match-go-template
- match: '{{char_escape}}'
scope: constant.character.escape.tick
- match: "'"
scope: punctuation.definition.string.end.tick
pop: true
- match: "'''"
scope: punctuation.definition.string.begin.tick
push:
- meta_scope: string.quoted.triple.tick
- include: match-go-template
- match: "'''"
scope: punctuation.definition.string.end.tick
pop: true
# Used to reference fields
match-reference:
- match: '"'
scope: punctuation.definition.string.begin.tick
push:
- include: match-go-template
- meta_scope: string.quoted.double.tick
- match: '{{char_escape}}'
scope: constant.character.escape.tick
- match: '"'
scope: punctuation.definition.string.end.tick
pop: true
# Thanks to Go sublime syntax
match-go-template:
- match: '{{(?=.*}})'
scope: punctuation.section.interpolation.begin.tick
push:
- meta_scope: meta.interpolation.tick
- clear_scopes: 1
- match: "}}"
scope: punctuation.section.interpolation.end.tick
pop: true
- match: "\\s-"
scope: keyword.operator.template.right.trim.tick
- match: "-\\s"
scope: keyword.operator.template.left.trim.tick
- match: ":=|="
scope: keyword.operator.assignment.tick
- match: \|
scope: keyword.operator.template.pipe.tick
- match: '(\.)([\w]+)'
captures:
1: punctuation.accessor.dot.tick
2: variable.other.member.tick
- match: '(\$)[\w]+'
scope: variable.other.template.tick
captures:
1: punctuation.definition.variable.tick
- match: '[.$]'
scope: variable.other.template.tick
- match: \b(if|else|range|template|with|end|nil|define|block)\b
scope: keyword.control.tick
- match: \b(and|call|html|index|slice|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|le|gt|ge)\b
scope: variable.function.tick support.function.builtin.tick
- include: match-comment
- include: match-string
- include: match-reference