Repository navigation
Expand file tree
/
Copy pathlbnf.sublime-syntax
More file actions
370 lines (334 loc) · 10.6 KB
/
Copy pathlbnf.sublime-syntax
File metadata and controls
370 lines (334 loc) · 10.6 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
%YAML 1.2
---
name: LBNF
file_extensions: [cf]
scope: source.lbnf
variables:
ident: '[a-zA-Z]\w*'
contexts:
main:
- include: terminal_string
- include: multiline_comment
- include: line_comment
- include: def_comment
- include: def_separator
- include: def_terminator
- include: def_coercions
- include: def_entrypoints
- include: def_layout
- include: def_rules
- include: def_pos_token
- include: def_token
- include: def_internal
- include: production_rule
# token <Ident> <Reg>
def_pos_token:
- match: '\b(position)\b\s+\b(token)\b'
captures:
1: keyword.control.position.lbnf
2: keyword.control.token.lbnf
push:
- reg
- production_cat
# token <Ident> <Reg>
def_token:
- match: '\b(token)\b'
captures:
1: keyword.control.token.lbnf
push:
- reg
- production_cat
reg:
- match: '\;'
scope: punctuation.terminator.lbnf
pop: true
- match: '\-|\|'
scope: punctuation.separator.lbnf
- match: '\('
scope: punctuation.section.group.begin.lbnf
- match: '\)'
scope: punctuation.section.group.end.lbnf
- match: '(\+)|(\*)|(\?)'
captures:
1: keyword.operator.regplus.lbnf
2: keyword.operator.regstar.lbnf
3: keyword.operator.reglazy.lbnf
- match: '(\bchar\b)|(\blower\b)|(\bupper\b)|(\bletter\b)|(\bdigit\b)|(\beps\b)'
captures:
1: entity.name.char.lbnf
2: entity.name.lower.lbnf
3: entity.name.upper.lbnf
4: entity.name.letter.lbnf
5: entity.name.digit.lbnf
6: entity.name.eps.lbnf
- include: terminal_char
- match: '\['
scope: punctuation.section.group.begin
set:
- include: terminal_string
- match: '\]'
meta_scope: meta.group
scope: punctuation.section.group.end
- match: '\{'
scope: punctuation.section.group.begin
set:
- include: terminal_string
- match: '\}'
meta_scope: meta.group
scope: punctuation.section.group.end
# comment <String>
def_comment:
- match: '\b(comment)\b'
captures:
1: keyword.control.comment.lbnf
push:
- include: terminal_string
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
# rules <Ident> ::= <ListRHS>
def_rules:
- match: '\b(rules)\b'
captures:
1: keyword.control.rules.lbnf
set:
- rules_list
- production_op_replace
- production_cat
# <ListRHS>
rules_list:
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
- match: '(\|)'
captures:
1: punctuation.separator.lbnf
set: rules_list
- include: nt_builtin
set: rules_list
- include: terminal_string
set: rules_list
- include: production_cat0
push: rules_list
# layout <ListString> | layout stop <ListString> | layout toplevel
def_layout:
- include: def_layout_inner
def_layout_inner:
- match: '\b(layout)\b\s+\b(toplevel)\b'
captures:
1: keyword.control.layout.lbnf
2: storage.modifier.toplevel.lbnf
- match: '\b(layout)\b\s+\b(stop)\b'
captures:
1: keyword.control.layout.lbnf
2: storage.modifier.stop.lbnf
push: list_string
- match: '\b(layout)\b'
captures:
1: keyword.control.layout.lbnf
push: list_string
list_string:
- include: terminal_string
- match: '(,)'
captures:
1: punctuation.separator
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
# coercions <Ident> <Integer>
def_coercions:
- match: '(\bcoercions\b)\s*({{ident}})\s*(\d+)\s*(;)'
captures:
1: keyword.control.coercions.lbnf
2: storage.type.category.lbnf category.lbnf
3: constant.numeric.integer
4: punctuation.terminator.production.lbnf
# entrypoints <ListIdent>
# <ListIdent> ::= <Ident> | <Ident> , <ListIdent>
def_entrypoints:
- match: '\b(entrypoints)\b'
captures:
1: keyword.control.entrypoints.lbnf
push: list_ident
list_ident:
- match: '{{ident}}'
scope: storage.type.category.lbnf category.lbnf
set:
- match: '(,)'
captures:
1: punctuation.separator
set: list_ident
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
# separator <MinimumSize> <Cat> <String>
def_separator:
- match: '(\bseparator\b)\s+(\bnonempty\b)?'
captures:
1: keyword.control.separator.lbnf
2: storage.modifier.nonempty.lbnf
set: def_sep_common
# terminator <MinimumSize> <Cat> <String>
def_terminator:
- match: '(\bterminator\b)\s+(\bnonempty\b)?'
captures:
1: keyword.control.terminator.lbnf
2: storage.modifier.nonempty.lbnf
set: def_sep_common
def_sep_common:
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
- include: terminal_string
- include: production_cat0
def_internal:
- match: '\b(internal)\b\s+'
captures:
1: keyword.control.internal.lbnf
set:
# Current: <Label>
- match: '({{ident}})'
scope: production.rule.lbnf
captures:
1: entity.name.label.lbnf
set:
- production_replace
- production_op_replace
- production_cat
- production_op_label
# Production Rule
# Starts: <Def> ::= <Label> . <Cat> ::= <ListItem>
production_rule:
# Current: <Label>
- match: '(({{ident}})|(_)|(\[\s*\])|(\(\s*:\s*\))|(\(\s*:\s*\[\s*\]\)))'
scope: production.rule.lbnf
captures:
2: entity.name.label.lbnf label.lbnf
3: constant.language.ignore.lbnf label.ignore.lbnf
4: constant.language.list.empty.lbnf label.list.empty.lbnf
5: constant.language.list.cons.lbnf label.list.cons.lbnf
6: constant.language.list.cons.empty.lbnf label.list.cons.empty.lbnf
push:
- production_replace
- production_op_replace
- production_cat
- production_op_label
# Production Rule
# Current: .
production_op_label:
- match: '(\.)'
captures:
1: keyword.operator.label.lbnf operator.label.lbnf
pop: true
# Production Rule
# Current: <Cat>
production_cat:
- match: '{{ident}}'
scope: storage.type.category.lbnf category.lbnf
pop: true
- match: '(\[)'
captures:
1: punctuation.section.array.begin
set:
- list_cat_end
- production_cat
list_cat_end:
- match: '(\])'
captures:
1: punctuation.section.array.end
pop: true
# Production Rule
# Current: <Cat>
production_cat0:
- match: '{{ident}}'
scope: storage.type.category.lbnf category.lbnf
- match: '(\[)'
captures:
1: punctuation.section.array.begin
push:
- list_cat_end
- production_cat
# Production Rule
# Current: ::=
production_op_replace:
- match: '(::=)'
captures:
1: keyword.operator.production.lbnf
pop: true
# Production Rule
# Current: <ListItem>
production_replace:
- match: '\;'
scope: punctuation.terminator.production.lbnf
pop: true
- include: nt_builtin
set: production_replace
- include: terminal_string
set: production_replace
- include: production_cat0
push: production_replace
# Built-in Non-Terminals:
nt_builtin:
- include: nt_builtin_ident
- include: nt_builtin_integer
- include: nt_builtin_double
- include: nt_builtin_char
- include: nt_builtin_string
nt_builtin_ident:
- match: '\b(Ident)\b'
scope: constant.language.ident.lbnf nonterminal.builtin.ident.lbnf
nt_builtin_integer:
- match: '\b(Integer)\b'
scope: constant.language.integer.lbnf
nonterminal.builtin.integer.lbnf
nt_builtin_double:
- match: '\b(Double)\b'
scope: constant.language.double.lbnf
nonterminal.builtin.double.lbnf
nt_builtin_char:
- match: '\b(Char)\b'
scope: constant.language.char.lbnf
nonterminal.builtin.char.lbnf
nt_builtin_string:
- match: '\b(String)\b'
scope: constant.language.string.lbnf
nonterminal.builtin.string.lbnf
# <Char>:
terminal_char:
- match: "\'[^\']\'"
scope: string.quoted.single.lbnf
# <String>:
terminal_string:
- match: '"'
scope: punctuation.definition.string.begin.lbnf
terminal.string.begin.lbnf
push: terminal_string_end
terminal_string_end:
- meta_scope: string.quoted.double.lbnf
terminal.string.lbnf
- match: '\\.'
scope: constant.character.escape.lbnf
terminal.string.escape.lbnf
- match: '"'
scope: punctuation.definition.string.end.lbnf
terminal.string.end.lbnf
pop: true
# Multiline Comments:
multiline_comment:
- match: '{-'
scope: punctuation.definition.comment.start.lbnf
push: multiline_comment_end
multiline_comment_end:
- meta_scope: comment.block.lbnf
- match: '-}'
scope: punctuation.definition.comment.end.lbnf
pop: true
# Line Comments:
line_comment:
- match: '--'
scope: punctuation.definition.comment.lbnf
push: line_comment_end
line_comment_end:
- meta_scope: comment.line.lbnf
- match: $
pop: true