-
Notifications
You must be signed in to change notification settings - Fork 0
/
technique.sublime-syntax
288 lines (209 loc) · 6.7 KB
/
technique.sublime-syntax
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
282
283
284
285
286
287
288
%YAML 1.2
---
name: Technique
file_extensions: [t]
scope: source.technique
contexts:
main:
# skip blank lines
- match: '^\s*$'
# magic version string and top-level metadata
- match: '^% technique v1'
scope: entity.name.namespace.technique
- match: '^!.*$'
scope: entity.name.namespace.technique
- match: '^&.*$'
scope: entity.name.namespace.technique
# identify a procedure definition and stack the function context
- match: '^([a-z]\w*)(?=(?:\([\w\s,]+\))?\s+:)'
captures:
1: entity.name.function.technique
push:
- signature
- definition
- parameters
# include: bail-out
# push: function
# top-level section declaration
- match: '^([IVXLCMD]+\.)'
captures:
1: markup.list.numbered.technique
# individual steps within a procedure
- match: '^\s+(\d+\.)'
captures:
1: markup.list.numbered.technique
# individual sub-steps within a procedure
- match: '^\s+([a-z]\.)'
captures:
1: markup.list.numbered.technique
# individual tasks within a procedure
- match: '^\s+(\-)'
captures:
1: markup.list.unnumbered.technique
- match: '(~)\s*([a-z]\w*)'
captures:
1: keyword.operator.assignment
2: variable.parameter.technique
- match: '^\s+(?=@\w+)'
push:
- role
# procedure title if present
- match: '^(#)\s*(.*)$'
captures:
1: punctuation.definition.heading.technique
2: markup.heading.technique
# procedure call
- include: procedure-call
# Sum type
- match: (\')(?:\w(?:[\w\s]*\w)*\')
scope: entity.name.constant.technique
# Code block
- match: '{'
scope: punctuation.section.braces.begin
push: code-block
- match: '\s*\|'
scope: punctuation.separator.constant.technique
procedure-call:
- match: '(<)([a-z]\w*)(>)'
captures:
1: punctuation.definition.generic.begin
2: variable.function.technique
3: punctuation.definition.generic.end
push:
- parameters
parameters:
- meta_scope: meta.parameters.technique
- match: '\('
scope: punctuation.definition.parameters.begin
- match: '\)'
scope: punctuation.definition.parameters.end
pop: true
- match: ','
scope: punctuation.separator.parameters
- match: '[a-z]\w*'
scope: variable.parameter.technique
- match: '(?=\s*[:~}])'
pop: true
- match: '$'
pop: true
definition:
- match: ':'
scope: punctuation.definition.function.technique
pop: true
signature:
- meta_scope: meta.type.technique
- match: '$'
pop: true
- match: ','
scope: punctuation.separator.parameters
- match: '(\[)?([A-Z]\w*)(\])?'
captures:
1: punctuation.section.brackets.start
2: entity.name.type.technique
3: punctuation.section.brackets.end
- match: '\(\)'
scope: entity.name.type.technique
- match: '->'
scope: keyword.operator.function
role:
- meta_scope: meta.trait
- match: '@\w+'
scope: entity.name.trait
- match: '\+'
scope: keyword.operator
- match: '$'
pop: true
values:
- include: procedure-call
# numeric constants
- match: \d+
scope: constant.numeric
# built-in function invocation
- match: '([a-z]\w*)(?=\()(?!:)'
captures:
1: support.function.technique
push: embedded
# remaining identifiers are variables
- match: '[a-z]\w*'
scope: variable.parameter.technique
- match: (\")(?=[^\"]*\")
captures:
1: punctuation.definition.string.begin
push: value-string
value-string:
- meta_scope: meta.string
- match: '"'
scope: punctuation.definition.string.end
pop: true
- match: '{'
scope: punctuation.section.braces.begin
push: code-block
- match: '[^"{]+'
scope: string.quoted.double
code-block:
- meta_scope: meta.block
- match: '}'
scope: punctuation.section.braces.end
pop: true
- match: '(foreach)\s'
captures:
1: keyword.control.technique
- match: '(in)\s'
captures:
1: keyword.control.technique
- match: '(repeat)\s'
captures:
1: keyword.control.technique
# Handle a tablet if encountered
- match: '\['
scope: punctuation.section.brackets.start
push: tablet
- match: '~(?=\s*[a-z]\w*)'
scope: keyword.operator.assignment
- include: values
tablet:
- meta_scope: meta.tablet.technique
- match: '\]'
scope: punctuation.section.brackets.end
pop: true
# an empty name is not a valid field but we want the highlighting to
# for the rest of the tablet when writing.
- match: '(\")([\w\d\s]*)(\")\s*(=)'
captures:
1: punctuation.definition.field.begin
2: variable.other.tablet
3: punctuation.definition.field.end
4: punctuation.separator.parameters
push: tablet-value
tablet-value:
- include: values
- match: '$'
pop: true
embedded:
- meta_scope: meta.embedded.technique
- match: '\('
scope: punctuation.definition.parameters.begin
- match: '\)'
scope: punctuation.definition.parameters.end
pop: true
- match: '(```)(\w+)'
captures:
1: punctuation.definition.string.begin
2: storage.type.embedded
push: embedded-string
- match: '(```)'
captures:
1: punctuation.definition.string.begin
push: embedded-string
# - match: '[^\)]*'
# scope: string.quoted.other
embedded-string:
- meta_scope: meta.string
- match: '```'
scope: punctuation.definition.string.end
pop: true
- match: '[^`]+'
scope: string.quoted.triple
bail-out:
- match: '(?=\S)'
pop: true