This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPureBasic.sublime-syntax
438 lines (393 loc) · 13.7 KB
/
PureBasic.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
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
%YAML 1.2
---
file_extensions:
- pb
- pbi
- pbf
scope: source.purebasic
version: 2
variables:
following_pointer: '(\s*(\*))?'
opening_parens: '(\()(\*)?'
return_type: '(\s*(\.)\s*(\w+))?'
variables: '(\@)?(\w+)(\$)?'
contexts:
calls:
- match: '\b(\w+)(\()'
captures:
1: variable.function.purebasic
2: punctuation.section.parens.begin.purebasic
push:
- meta_scope: meta.function-call.purebasic
- match: '\)'
scope: punctuation.section.parens.end.purebasic
pop: true
- include: literals
- include: keywords
- include: types
- include: punctuation
- include: calls
- include: variables
- include: constants
comments:
- match: ';'
scope: punctuation.definition.comment.purebasic
push:
- meta_scope: comment.line.purebasic
- match: '$'
pop: true
constants:
- match: '(#)([\w_]+)\b'
captures:
0: variable.other.constant.purebasic
1: punctuation.definition.variable.purebasic
declarations:
- match: '\b(?i:(Enumeration|EnumerationBinary))(\s+(\D\w+))?\b'
captures:
1: storage.type.enum.purebasic keyword.declaration.enum.purebasic
3: entity.name.enum.purebasic
push:
- include: comments
- include: terminators
- include: literals
- include: keywords
- include: types
- include: punctuation
- include: variables
- include: constants
- match: '\b(?i:(Declare|DeclareCDLL|DeclareDLL|Prototype))(\s*(\.)\s*(\w+))?\s+(\w+)'
captures:
1: storage.type.function.purebasic keyword.declaration.function.purebasic
3: punctuation.separator.purebasic
4: meta.function.return-type.purebasic storage.type.purebasic
5: entity.name.function.forward-decl.purebasic
push: parameters
- match: '\b(?i:(Define)){{following_pointer}}\b'
captures:
1: keyword.declaration.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
push:
- include: terminators
- include: literals
- include: keywords
- include: types
- include: punctuation
- include: variables
- include: constants
- match: '\b(?i:(Dim|NewList|NewMap|ReDim))\s+(\w+)\b'
captures:
1: keyword.declaration.purebasic
2: entity.name.function.purebasic
push:
- include: terminators
- include: literals
- include: keywords
- include: types
- include: punctuation
- include: variables
- include: constants
- match: '\b(?i:Global|Protected|Runtime|Shared|Static|Threaded)\b'
scope: storage.modifier.purebasic
- match: '\b(?i:(DeclareModule|Module)\s+(\w+))\b'
captures:
1: keyword.declaration.purebasic
2: entity.name.namespace.purebasic
push:
- meta_scope: meta.namespace.purebasic
- match: '\b(?i:EndDeclareModule|EndModule)\b'
scope: keyword.other.purebasic
pop: true
- include: comments
- include: literals
- include: declarations
- include: keywords
- include: types
- include: punctuation
- include: variables
- include: constants
- match: '\b(?i:(Procedure|ProcedureC|ProcedureCDLL|ProcedureDLL){{return_type}}\s+(\w+))\b'
captures:
1: storage.type.function.purebasic keyword.declaration.function.purebasic
3: punctuation.separator.purebasic
4: meta.function.return-type.purebasic storage.type.purebasic
5: entity.name.function.purebasic
push: procedures
- match: '\b(?i:(Import))\b'
captures:
1: keyword.control.import.purebasic
push:
- include: comments
- include: literals
- match: '\bEndImport\b'
scope: keyword.control.import.purebasic
pop: true
- include: parameter_keywords
- include: members
- include: keywords
- include: types
- include: punctuation
- match: '\b(?i:(Interface)\s+(\w+)(\s+(Extends)\s+(\w+))?)\b'
captures:
1: storage.type.interface.purebasic keyword.declaration.interface.purebasic
2: entity.name.interface.purebasic
4: keyword.other.purebasic
5: entity.name.interface.purebasic
push:
- include: comments
- include: literals
- match: '\bEndInterface\b'
scope: keyword.other.purebasic
pop: true
- include: parameter_keywords
- include: members
- include: keywords
- include: types
- include: punctuation
- match: '\b(?i:(Structure)\s+(\w+)(\s+(Extends)\s+(\w+))?)\b'
captures:
1: storage.type.struct.purebasic keyword.declaration.struct.purebasic
2: entity.name.struct.purebasic
4: keyword.other.purebasic
5: entity.name.struct.purebasic
push:
- include: comments
- include: literals
- match: '\bEndStructure\b'
scope: keyword.other.purebasic
pop: true
#
# "StructureUnion" blocks can only appear inside "Structure" definitions.
#
- match: '\b(?i:StructureUnion|EndStructureUnion)\b'
scope: keyword.other.purebasic
- include: parameter_keywords
- include: members
- include: keywords
- include: types
- include: punctuation
leading_pointers:
- match: '^\s*(\*)'
captures:
1: punctuation.definition.variable.purebasic variable.other.purebasic
main:
- include: comments
- include: literals
- include: declarations
- include: leading_pointers
- include: keywords
- include: types
- include: punctuation
- include: calls
- include: labels
- include: variables
- include: constants
#
# Variable and procedure definitions inside structure definitions and interface blocks.
#
members:
- match: '\b(\w+){{return_type}}(\()'
captures:
1: entity.name.function.forward-decl.purebasic
3: punctuation.separator.purebasic
4: meta.function.return-type.purebasic storage.type.purebasic
5: punctuation.section.parens.begin.purebasic
push: parameters
#
# Variables are scoped slightly different than all other variables.
#
- match: '(\*)?(\w+)(\$)?'
captures:
0: variable.other.member.purebasic
1: punctuation.definition.variable.purebasic
3: punctuation.definition.variable.purebasic
labels:
- match: '\b((\w+)(:))\s*$'
captures:
2: entity.name.label.purebasic
3: punctuation.separator.purebasic
#
# Strings and numbers.
#
literals:
# Strings with escape sequences require a tilde before the beginning double quote.
- match: '~"'
scope: punctuation.definition.string.begin.purebasic
push:
- meta_scope: string.quoted.double.purebasic
- match: '\\[\w\d"]'
scope: constant.character.escape.purebasic
- match: '"'
scope: punctuation.definition.string.end.purebasic
pop: true
# Literal strings without escape sequences.
- match: '"'
scope: punctuation.definition.string.begin.purebasic
push:
- meta_scope: string.quoted.double.purebasic
- match: '"'
scope: punctuation.definition.string.end.purebasic
pop: true
- match: '\-?\d+(\.\d+)?(e\-\d+)?'
scope: constant.numeric.purebasic
keywords:
- include: operators_all
- match: '\b(?i:Break|Case|Continue|CompilerCase|CompilerDefault|CompilerElse|CompilerElseIf|CompilerEndIf|CompilerEndSelect|CompilerIf|CompilerSelect|Default|Else|End|EndIf|EndSelect|ElseIf|Else|FakeReturn|For|ForEach|Forever|Gosub|Goto|If|Next|Repeat|Select|To|Until|Wend|While)\b'
scope: keyword.control.purebasic
- match: '\b(?i:DataSection|EndDataSection|IncludeFile|IncludePath|XIncludeFile)\b'
scope: keyword.control.import.purebasic
- match: '\b(?i:Interface)\b'
scope: keyword.declaration.purebasic
- match: '\b(?i:(CallDebugger|CompilerError|CompilerWarning|Data|Debug|DebugLevel|DisableASM|DisableDebugger|DisableExplicit|EnableASM|EnableDebugger|EnableExplicit|EndEnumeration|EndInterface|EndMacro|EndWith|Extends|Macro|MacroExpandedCount|Module|ProcedureReturn|Read|Restore|Step|Swap|UndefineMacro|UnuseModule|UseModule|With))\b{{following_pointer}}'
captures:
1: keyword.other.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
operators_all:
- include: operators_arithmetic
- include: operators_assignment
- include: operators_comparison
- include: operators_logical
- include: operators_bitwise
operators_arithmetic:
- match: '(\+|-|\*|/|%|<<|>>){{following_pointer}}'
captures:
1: keyword.operator.arithmetic.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
operators_assignment:
- match: '(=(?![<>])){{following_pointer}}'
captures:
1: keyword.operator.assignment.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
operators_bitwise:
- match: '(&|\||!|~){{following_pointer}}'
captures:
1: keyword.operator.bitwise.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
operators_comparison:
- match: '(<=?|>=?|=<?|=>?|<>){{following_pointer}}'
captures:
1: keyword.operator.comparison.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
operators_logical:
- match: '(?i)\b(And|Or|XOr|Not)\b{{following_pointer}}'
captures:
1: keyword.operator.word.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
#
# Whatever can occur inside the parenthesis of a procedure declaration.
#
parameter_list_contents:
- include: literals
- include: keywords
- include: types
- include: punctuation
- include: calls
#
# Function parameters should have a dedicated scope according to the Sublime Text documentation.
#
- match: '{{variables}}'
captures:
0: variable.parameter.purebasic
1: punctuation.definition.variable.purebasic
3: punctuation.definition.variable.purebasic
- include: constants
#
# The "Array" and "List" keywords may appear in structure and interface definitions.
# They must be matched before the generic variable pattern gets them.
#
parameter_keywords:
- match: '\b(?i:Array|List)\b'
scope: keyword.declaration.purebasic
#
# Generic parameter list of procedure declarations.
#
# Important: procedure implementation have their distinct context.
#
parameters:
- meta_content_scope: meta.function.parameters.purebasic
- match: '{{opening_parens}}'
captures:
1: punctuation.section.parens.begin.purebasic
2: variable.parameter.purebasic punctuation.definition.variable.purebasic
- match: '\)'
scope: punctuation.section.parens.end.purebasic
pop: true
- include: parameter_list_contents
procedures:
- meta_scope: meta.function.purebasic
- match: '{{opening_parens}}'
captures:
1: punctuation.section.parens.begin.purebasic
2: variable.parameter.purebasic punctuation.definition.variable.purebasic
set: procedure_implementation_parameters
- match: '\bEndProcedure\b'
scope: keyword.other.purebasic
pop: true
- include: calls
- include: comments
- include: literals
- include: declarations
- include: keywords
- include: types
- include: punctuation
- include: variables
- include: constants
#
# This is a special context for the parameter list of procedure implementations.
# The sublime text scope naming documentation requires a scope shift back to "procedures" in such case.
# That would be wrong for other parameter lists like in interface blocks.
#
procedure_implementation_parameters:
- meta_scope: meta.function.parameters.purebasic
- match: '\)'
scope: punctuation.section.parens.end.purebasic
set: procedures
- include: parameter_list_contents
punctuation:
- match: '(,){{following_pointer}}'
captures:
1: punctuation.separator.purebasic
3: variable.other.purebasic punctuation.definition.variable.purebasic
- match: '{{opening_parens}}'
captures:
1: punctuation.section.parens.begin.purebasic
2: variable.other.purebasic punctuation.definition.variable
- match: '\)'
scope: punctuation.section.parens.end.purebasic
- match: '\['
scope: punctuation.section.brackets.begin.purebasic
- match: '\]'
scope: punctuation.section.brackets.end.purebasic
#
# Used for accessing members of a module.
#
- match: '::'
scope: punctuation.accessor.purebasic
#
# Used for accessing structure fields.
#
- match: '(\\)({{variables}})'
captures:
1: punctuation.accessor.purebasic
2: variable.other.member.purebasic
5: punctuation.definition.variable.purebasic
#
# Commands in PureBasic are typically terminated by the end of the line.
# However there is also the possibility to concatenate multiple commands in one line by using ":".
#
terminators:
- match: ':'
scope: punctuation.separator.purebasic
pop: true
- match: '$'
pop: true
types:
- match: (\.)\s*(\w[\w-]*)
captures:
1: punctuation.separator.purebasic
2: storage.type.purebasic
variables:
- match: '{{variables}}'
captures:
0: variable.other.purebasic
1: punctuation.definition.variable.purebasic
3: punctuation.definition.variable.purebasic