@pb-shrugged/tree-sitter-powerscript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -0
- package/binding.gyp +35 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/binding_test.js +11 -0
- package/bindings/node/index.d.ts +28 -0
- package/bindings/node/index.js +11 -0
- package/grammar.js +1381 -0
- package/package.json +64 -0
- package/src/grammar.json +8327 -0
- package/src/node-types.json +7114 -0
- package/src/parser.c +102746 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +330 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-powerscript.wasm +0 -0
- package/tree-sitter.json +43 -0
package/grammar.js
ADDED
|
@@ -0,0 +1,1381 @@
|
|
|
1
|
+
/* eslint-disable object-curly-spacing */
|
|
2
|
+
/**
|
|
3
|
+
* @file Powerscript grammar for tree-sitter
|
|
4
|
+
* @author Jose Cagnini
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
9
|
+
// @ts-check
|
|
10
|
+
|
|
11
|
+
const PREC = {
|
|
12
|
+
OR: 1,
|
|
13
|
+
AND: 2,
|
|
14
|
+
EQUALITY: 3,
|
|
15
|
+
RELATIONAL: 4,
|
|
16
|
+
ADDITIVE: 5,
|
|
17
|
+
MULTIPLICATIVE: 6,
|
|
18
|
+
EXPONENTIATION: 7,
|
|
19
|
+
UNARY: 8,
|
|
20
|
+
UPDATE_UNARY: 9,
|
|
21
|
+
FIELD_ACCESS: 10,
|
|
22
|
+
METHOD_INVOCATION: 11,
|
|
23
|
+
IMMEDIATE_CASE: 12,
|
|
24
|
+
KEYWORD: 20,
|
|
25
|
+
IDENTIFIER_EXPRESSION: -1,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = grammar({
|
|
30
|
+
name: 'powerscript',
|
|
31
|
+
|
|
32
|
+
word: $ => $.identifier,
|
|
33
|
+
|
|
34
|
+
extras: $ => [
|
|
35
|
+
/\s/,
|
|
36
|
+
$.line_comment,
|
|
37
|
+
$.block_comment,
|
|
38
|
+
$.line_continuation,
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
conflicts: $ => [
|
|
42
|
+
[$.inline_if_statement, $.if_then_statement],
|
|
43
|
+
[$.expression_statement, $.r_value_expression],
|
|
44
|
+
[$.parenthesized_expression, $.destroy_statement],
|
|
45
|
+
[$.halt_statement],
|
|
46
|
+
[$.assignment_statement, $.create_statement, $.r_value_expression],
|
|
47
|
+
[$.for_loop_statement, $.r_value_expression],
|
|
48
|
+
[$.return_statement],
|
|
49
|
+
[$.scriptable_block],
|
|
50
|
+
],
|
|
51
|
+
|
|
52
|
+
rules: {
|
|
53
|
+
|
|
54
|
+
source_file: $ => seq(
|
|
55
|
+
optional($.export_header),
|
|
56
|
+
$.class_file,
|
|
57
|
+
),
|
|
58
|
+
|
|
59
|
+
class_file: $ => repeat1(choice(
|
|
60
|
+
$.forward_declaration_section,
|
|
61
|
+
$.structure_definition,
|
|
62
|
+
$.global_variables_section,
|
|
63
|
+
$.shared_variables_section,
|
|
64
|
+
$.instance_variables_section,
|
|
65
|
+
$.class_type_definition,
|
|
66
|
+
$.global_var_declaration,
|
|
67
|
+
$.external_function_prototypes,
|
|
68
|
+
$.forward_function_prototypes,
|
|
69
|
+
$.event_definition,
|
|
70
|
+
$.function_definition,
|
|
71
|
+
$.on_event_definition,
|
|
72
|
+
// $.inner_class_type_definition,
|
|
73
|
+
)),
|
|
74
|
+
|
|
75
|
+
forward_declaration_section: $ => seq(
|
|
76
|
+
alias($.forward_keyword, $.forward_declaration_statement),
|
|
77
|
+
$.forward_declaration_statement_body,
|
|
78
|
+
$.forward_declaration_statement_end,
|
|
79
|
+
),
|
|
80
|
+
|
|
81
|
+
forward_declaration_statement_body: $ => seq(
|
|
82
|
+
repeat1($.class_type_definition),
|
|
83
|
+
repeat($.global_variable_declaration),
|
|
84
|
+
),
|
|
85
|
+
|
|
86
|
+
class_type_definition: $ => seq(
|
|
87
|
+
$.class_type_definition_statement,
|
|
88
|
+
optional($.class_type_definition_statement_body),
|
|
89
|
+
$.end_type_declaration_statement,
|
|
90
|
+
),
|
|
91
|
+
|
|
92
|
+
class_type_definition_statement: $ => seq(
|
|
93
|
+
optional($.global_keyword),
|
|
94
|
+
$.type_keyword,
|
|
95
|
+
alias($.identifier, $.class_type_name),
|
|
96
|
+
$.from_keyword,
|
|
97
|
+
alias($.identifier, $.ancenstor_type_name),
|
|
98
|
+
optional(seq($.native_keyword, alias($.string_literal, $.dll_path))),
|
|
99
|
+
optional($.autoinstantiate_keyword),
|
|
100
|
+
optional(seq(
|
|
101
|
+
$.within_keyword,
|
|
102
|
+
alias($.identifier, $.parent_class),
|
|
103
|
+
optional(seq(
|
|
104
|
+
$.descriptor_keyword,
|
|
105
|
+
alias($.string_literal, $.descriptor_type),
|
|
106
|
+
'=',
|
|
107
|
+
alias($.string_literal, $.descriptor_value),
|
|
108
|
+
)),
|
|
109
|
+
)),
|
|
110
|
+
),
|
|
111
|
+
|
|
112
|
+
class_type_definition_statement_body: $ => repeat1(choice(
|
|
113
|
+
$.event_declaration,
|
|
114
|
+
$.function_prototype,
|
|
115
|
+
alias($.local_variable_declaration, $.inner_class_variable_declaration),
|
|
116
|
+
)),
|
|
117
|
+
|
|
118
|
+
global_variable_declaration: $ => seq(
|
|
119
|
+
$.global_keyword,
|
|
120
|
+
$.type,
|
|
121
|
+
alias($.identifier, $.variable_name),
|
|
122
|
+
),
|
|
123
|
+
|
|
124
|
+
forward_declaration_statement_end: $ => seq(
|
|
125
|
+
$.end_keyword,
|
|
126
|
+
$.forward_keyword,
|
|
127
|
+
),
|
|
128
|
+
|
|
129
|
+
shared_variables_section: $ => seq(
|
|
130
|
+
$.shared_variables_section_statement,
|
|
131
|
+
optional($.shared_variables_section_body),
|
|
132
|
+
$.end_variables_section,
|
|
133
|
+
),
|
|
134
|
+
|
|
135
|
+
shared_variables_section_statement: $ => seq(
|
|
136
|
+
$.shared_keyword,
|
|
137
|
+
$.variables_keyword,
|
|
138
|
+
),
|
|
139
|
+
|
|
140
|
+
shared_variables_section_body: $ => repeat1($.local_variable_declaration),
|
|
141
|
+
|
|
142
|
+
end_variables_section: $ => seq(
|
|
143
|
+
$.end_keyword,
|
|
144
|
+
$.variables_keyword,
|
|
145
|
+
),
|
|
146
|
+
|
|
147
|
+
global_variables_section: $ => seq(
|
|
148
|
+
$.global_variables_section_statement,
|
|
149
|
+
optional($.global_variables_section_body),
|
|
150
|
+
$.end_variables_section,
|
|
151
|
+
),
|
|
152
|
+
|
|
153
|
+
global_variables_section_statement: $ => seq(
|
|
154
|
+
$.global_keyword,
|
|
155
|
+
$.variables_keyword,
|
|
156
|
+
),
|
|
157
|
+
|
|
158
|
+
global_variables_section_body: $ => repeat1($.local_variable_declaration),
|
|
159
|
+
|
|
160
|
+
global_var_declaration: $ => seq(
|
|
161
|
+
$.global_keyword,
|
|
162
|
+
$.type,
|
|
163
|
+
alias($.identifier, $.global_variable_name),
|
|
164
|
+
),
|
|
165
|
+
|
|
166
|
+
external_function_prototypes: $ => seq(
|
|
167
|
+
$.external_function_prototypes_statement,
|
|
168
|
+
repeat($.external_function_prototype),
|
|
169
|
+
$.end_function_prototypes_statement,
|
|
170
|
+
),
|
|
171
|
+
|
|
172
|
+
external_function_prototypes_statement: $ => seq(
|
|
173
|
+
$.type_keyword,
|
|
174
|
+
$.prototypes_keyword,
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
external_function_prototype: $ => seq(
|
|
178
|
+
$.function_prototype,
|
|
179
|
+
$.library_keyword,
|
|
180
|
+
alias($.string_literal, $.library_name),
|
|
181
|
+
optional(seq(
|
|
182
|
+
$.alias_keyword,
|
|
183
|
+
$.for_keyword,
|
|
184
|
+
alias($.string_literal, $.alias_name),
|
|
185
|
+
)),
|
|
186
|
+
),
|
|
187
|
+
|
|
188
|
+
instance_variables_section: $ => seq(
|
|
189
|
+
$.instance_variables_section_statement,
|
|
190
|
+
optional($.instance_variables_section_statement_body),
|
|
191
|
+
$.end_variables_section,
|
|
192
|
+
),
|
|
193
|
+
|
|
194
|
+
instance_variables_section_statement: $ => seq(
|
|
195
|
+
$.type_keyword,
|
|
196
|
+
$.variables_keyword,
|
|
197
|
+
),
|
|
198
|
+
|
|
199
|
+
instance_variables_section_statement_body: $ => repeat1(choice(
|
|
200
|
+
$.access_section,
|
|
201
|
+
$.instance_variable_declaration,
|
|
202
|
+
)),
|
|
203
|
+
|
|
204
|
+
access_section: $ => seq(
|
|
205
|
+
$.access_modifier,
|
|
206
|
+
':',
|
|
207
|
+
),
|
|
208
|
+
|
|
209
|
+
instance_variable_declaration: $ => seq(
|
|
210
|
+
// optional($.constant_keyword), TODO
|
|
211
|
+
optional($.access_modifier),
|
|
212
|
+
optional($.readacess_modifier),
|
|
213
|
+
optional($.writeaccess_modifier),
|
|
214
|
+
$.local_variable_declaration,
|
|
215
|
+
),
|
|
216
|
+
|
|
217
|
+
readacess_modifier: $ => choice(
|
|
218
|
+
$.protectedread_keyword,
|
|
219
|
+
$.privateread_keyword,
|
|
220
|
+
),
|
|
221
|
+
|
|
222
|
+
writeaccess_modifier: $ => choice(
|
|
223
|
+
$.protectedwrite_keyword,
|
|
224
|
+
$.privatewrite_keyword,
|
|
225
|
+
),
|
|
226
|
+
|
|
227
|
+
event_definition: $ => seq(
|
|
228
|
+
$.event_definition_statement,
|
|
229
|
+
optional(alias($.scriptable_block, $.event_definition_block)),
|
|
230
|
+
$.event_definition_statement_end,
|
|
231
|
+
),
|
|
232
|
+
|
|
233
|
+
event_definition_statement: $ => seq(
|
|
234
|
+
$.event_declaration,
|
|
235
|
+
$.statement_separation,
|
|
236
|
+
),
|
|
237
|
+
|
|
238
|
+
event_definition_statement_end: $ => seq(
|
|
239
|
+
$.end_keyword,
|
|
240
|
+
$.event_keyword,
|
|
241
|
+
),
|
|
242
|
+
|
|
243
|
+
on_event_definition: $ => seq(
|
|
244
|
+
$.on_event_definition_statement,
|
|
245
|
+
optional(alias($.scriptable_block, $.on_event_definition_block)),
|
|
246
|
+
$.on_event_definition_statement_end,
|
|
247
|
+
),
|
|
248
|
+
|
|
249
|
+
on_event_definition_statement: $ => seq(
|
|
250
|
+
$.on_keyword,
|
|
251
|
+
alias($.identifier, $.class_name),
|
|
252
|
+
'.',
|
|
253
|
+
choice($.create_keyword, $.destroy_keyword),
|
|
254
|
+
),
|
|
255
|
+
|
|
256
|
+
on_event_definition_statement_end: $ => seq($.end_keyword, $.on_keyword),
|
|
257
|
+
|
|
258
|
+
// inner_class_type_definition: $ => seq(
|
|
259
|
+
// $.class_type_definition,
|
|
260
|
+
// repeat(choice(
|
|
261
|
+
// $.event_definition,
|
|
262
|
+
// $.on_event_definition,
|
|
263
|
+
// )),
|
|
264
|
+
// ),
|
|
265
|
+
|
|
266
|
+
structure_definition: $ => seq(
|
|
267
|
+
$.structure_definition_statement,
|
|
268
|
+
optional($.structure_definition_body),
|
|
269
|
+
$.end_type_declaration_statement,
|
|
270
|
+
),
|
|
271
|
+
|
|
272
|
+
structure_definition_statement: $ => seq(
|
|
273
|
+
optional($.global_keyword),
|
|
274
|
+
$.type_keyword,
|
|
275
|
+
alias($.identifier, $.structure_name),
|
|
276
|
+
$.from_keyword,
|
|
277
|
+
caseInsensitiveAlias('structure'),
|
|
278
|
+
),
|
|
279
|
+
|
|
280
|
+
structure_definition_body: $ => repeat1($.structure_field),
|
|
281
|
+
|
|
282
|
+
structure_field: $ => seq(
|
|
283
|
+
$.type,
|
|
284
|
+
alias($.identifier, $.field_name),
|
|
285
|
+
optional($.array_suffix),
|
|
286
|
+
optional($.structure_field_comment),
|
|
287
|
+
),
|
|
288
|
+
|
|
289
|
+
structure_field_comment: $ => seq(
|
|
290
|
+
$.descriptor_keyword,
|
|
291
|
+
alias($.string_literal, $.descriptor_type),
|
|
292
|
+
'=',
|
|
293
|
+
alias($.string_literal, $.descriptor_value),
|
|
294
|
+
),
|
|
295
|
+
|
|
296
|
+
function_type_declaration: $ => seq(
|
|
297
|
+
$.function_type_declaration_statement,
|
|
298
|
+
$.end_type_declaration_statement,
|
|
299
|
+
),
|
|
300
|
+
|
|
301
|
+
function_type_declaration_statement: $ => seq(
|
|
302
|
+
$.global_keyword,
|
|
303
|
+
$.type_keyword,
|
|
304
|
+
alias($.identifier, $.function_type_name),
|
|
305
|
+
$.from_keyword,
|
|
306
|
+
caseInsensitiveAlias('function_object'),
|
|
307
|
+
),
|
|
308
|
+
|
|
309
|
+
end_type_declaration_statement: $ => seq($.end_keyword, $.type_keyword),
|
|
310
|
+
|
|
311
|
+
forward_function_prototypes: $ => seq(
|
|
312
|
+
$.forward_function_prototypes_statement,
|
|
313
|
+
repeat($.function_prototype),
|
|
314
|
+
$.end_function_prototypes_statement,
|
|
315
|
+
),
|
|
316
|
+
|
|
317
|
+
forward_function_prototypes_statement: $ => seq($.forward_keyword, $.prototypes_keyword),
|
|
318
|
+
|
|
319
|
+
end_function_prototypes_statement: $ => seq($.end_keyword, $.prototypes_keyword),
|
|
320
|
+
|
|
321
|
+
event_declaration: $ => seq(
|
|
322
|
+
$.event_keyword,
|
|
323
|
+
optional(seq($.type_keyword, alias($.type, $.return_type))),
|
|
324
|
+
alias($.identifier, $.event_name),
|
|
325
|
+
optional($.parameter_list),
|
|
326
|
+
optional($.throws_clause),
|
|
327
|
+
optional($.event_id),
|
|
328
|
+
),
|
|
329
|
+
|
|
330
|
+
event_id: $ => /pbm_[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
331
|
+
|
|
332
|
+
function_prototype: $ => choice(
|
|
333
|
+
$._function_prototype,
|
|
334
|
+
$._subroutine_prototype,
|
|
335
|
+
),
|
|
336
|
+
|
|
337
|
+
_function_prototype: $ => seq(
|
|
338
|
+
optional($.global_keyword),
|
|
339
|
+
optional($.access_modifier),
|
|
340
|
+
$.function_keyword,
|
|
341
|
+
alias($.type, $.return_type),
|
|
342
|
+
alias($.identifier, $.function_name),
|
|
343
|
+
$.parameter_list,
|
|
344
|
+
optional($.throws_clause),
|
|
345
|
+
),
|
|
346
|
+
|
|
347
|
+
_subroutine_prototype: $ => seq(
|
|
348
|
+
optional($.global_keyword),
|
|
349
|
+
optional($.access_modifier),
|
|
350
|
+
$.subroutine_keyword,
|
|
351
|
+
alias($.identifier, $.subroutine_name),
|
|
352
|
+
$.parameter_list,
|
|
353
|
+
optional($.throws_clause),
|
|
354
|
+
),
|
|
355
|
+
|
|
356
|
+
throws_clause: $ => seq(
|
|
357
|
+
$.throws_keyword,
|
|
358
|
+
commaSep1(alias($.identifier, $.throwable_name)),
|
|
359
|
+
),
|
|
360
|
+
|
|
361
|
+
function_definition: $ => choice(
|
|
362
|
+
$._function_definition,
|
|
363
|
+
$._subroutine_definition,
|
|
364
|
+
),
|
|
365
|
+
|
|
366
|
+
_function_definition: $ => seq(
|
|
367
|
+
$.function_definition_statement,
|
|
368
|
+
optional(alias($.scriptable_block, $.function_definition_block)),
|
|
369
|
+
$.function_definition_statement_end,
|
|
370
|
+
),
|
|
371
|
+
|
|
372
|
+
function_definition_statement: $ => seq($._function_prototype, $.statement_separation),
|
|
373
|
+
|
|
374
|
+
function_definition_statement_end: $ => seq($.end_keyword, $.function_keyword),
|
|
375
|
+
|
|
376
|
+
_subroutine_definition: $ => seq(
|
|
377
|
+
$.subroutine_definition_statement,
|
|
378
|
+
optional(alias($.scriptable_block, $.subroutine_definition_block)),
|
|
379
|
+
$.subroutine_definition_statement_end,
|
|
380
|
+
),
|
|
381
|
+
|
|
382
|
+
subroutine_definition_statement: $ => seq($._subroutine_prototype, $.statement_separation),
|
|
383
|
+
|
|
384
|
+
subroutine_definition_statement_end: $ => seq($.end_keyword, $.subroutine_keyword),
|
|
385
|
+
|
|
386
|
+
parameter_list: $ => seq($.open_parenthesis, commaSep($.parameter), $.close_parenthesis),
|
|
387
|
+
|
|
388
|
+
parameter: $ => seq(
|
|
389
|
+
optional(alias(choice(
|
|
390
|
+
$.ref_keyword,
|
|
391
|
+
$.readonly_keyword,
|
|
392
|
+
), $.parameter_pass_by_type)),
|
|
393
|
+
$.type,
|
|
394
|
+
alias($.identifier, $.parameter_name),
|
|
395
|
+
optional($.array_parameter_declaration_suffix),
|
|
396
|
+
),
|
|
397
|
+
|
|
398
|
+
local_variable_declaration: $ => seq(
|
|
399
|
+
optional($.constant_keyword),
|
|
400
|
+
alias($.type, $.variable_type),
|
|
401
|
+
optional($.variable_precision),
|
|
402
|
+
$.variable_declaration_list,
|
|
403
|
+
),
|
|
404
|
+
|
|
405
|
+
variable_precision: $ => seq($.open_curly_brackets, $.integer_literal, $.close_curly_brackets),
|
|
406
|
+
|
|
407
|
+
variable_declaration_list: $ => commaSep1($.variable_declaration),
|
|
408
|
+
|
|
409
|
+
variable_declaration: $ => seq(
|
|
410
|
+
alias($.identifier, $.variable_name),
|
|
411
|
+
optional($.array_suffix),
|
|
412
|
+
optional(seq('=', alias($.r_value_expression, $.initial_value))),
|
|
413
|
+
),
|
|
414
|
+
|
|
415
|
+
array_suffix: $ => seq(
|
|
416
|
+
$.open_brackets,
|
|
417
|
+
choice(
|
|
418
|
+
commaSep($.r_value_expression),
|
|
419
|
+
commaSep(seq($.r_value_expression, $.to_keyword, $.r_value_expression)),
|
|
420
|
+
),
|
|
421
|
+
$.close_brackets,
|
|
422
|
+
),
|
|
423
|
+
|
|
424
|
+
array_parameter_declaration_suffix: $ => seq($.open_brackets, $.close_brackets),
|
|
425
|
+
|
|
426
|
+
access_modifier: $ => choice(
|
|
427
|
+
$.public_keyword,
|
|
428
|
+
$.private_keyword,
|
|
429
|
+
$.protected_keyword,
|
|
430
|
+
),
|
|
431
|
+
|
|
432
|
+
scriptable_block: $ => repeat1($.statement),
|
|
433
|
+
|
|
434
|
+
statement: $ => choice(
|
|
435
|
+
$.conditional_compilation_statement,
|
|
436
|
+
$.choose_statement,
|
|
437
|
+
$.do_loop,
|
|
438
|
+
$.for_loop,
|
|
439
|
+
$.goto_label,
|
|
440
|
+
$.if_statement,
|
|
441
|
+
$.inline_if_statement,
|
|
442
|
+
$.local_variable_declaration_statement,
|
|
443
|
+
$.try_catch_statement,
|
|
444
|
+
$.while_loop,
|
|
445
|
+
seq($.inline_statement, optional($.statement_separation)),
|
|
446
|
+
$.sql_statement,
|
|
447
|
+
),
|
|
448
|
+
|
|
449
|
+
conditional_compilation_statement: $ => seq(
|
|
450
|
+
'#',
|
|
451
|
+
$.if_keyword,
|
|
452
|
+
optional($.not_keyword),
|
|
453
|
+
caseInsensitiveAlias('defined'),
|
|
454
|
+
alias($.identifier, $.predefined_symbol),
|
|
455
|
+
$.then_keyword,
|
|
456
|
+
optional(alias($.scriptable_block, $.conditional_compilation_if_block)),
|
|
457
|
+
optional(seq(
|
|
458
|
+
'#',
|
|
459
|
+
$.elseif_keyword,
|
|
460
|
+
optional($.not_keyword),
|
|
461
|
+
caseInsensitiveAlias('defined'),
|
|
462
|
+
alias($.identifier, $.predefined_symbol),
|
|
463
|
+
$.then_keyword,
|
|
464
|
+
optional(alias($.scriptable_block, $.conditional_compilation_elseif_block)),
|
|
465
|
+
)),
|
|
466
|
+
optional(seq(
|
|
467
|
+
'#',
|
|
468
|
+
$.else_keyword,
|
|
469
|
+
optional(alias($.scriptable_block, $.conditional_compilation_else_block)),
|
|
470
|
+
)),
|
|
471
|
+
'#',
|
|
472
|
+
$.end_keyword,
|
|
473
|
+
$.if_keyword,
|
|
474
|
+
),
|
|
475
|
+
|
|
476
|
+
choose_statement: $ => seq(
|
|
477
|
+
$.choose_case_statement,
|
|
478
|
+
seq(
|
|
479
|
+
repeat1($.choose_case_clause),
|
|
480
|
+
optional($.choose_case_else_clause),
|
|
481
|
+
),
|
|
482
|
+
$.choose_statement_end,
|
|
483
|
+
),
|
|
484
|
+
|
|
485
|
+
choose_case_statement: $ => seq(
|
|
486
|
+
$.choose_keyword,
|
|
487
|
+
$.case_keyword,
|
|
488
|
+
alias($.r_value_expression, $.test_expression),
|
|
489
|
+
optional($.statement_separation),
|
|
490
|
+
),
|
|
491
|
+
|
|
492
|
+
choose_case_clause: $ => seq(
|
|
493
|
+
$.case_keyword,
|
|
494
|
+
alias(choice(
|
|
495
|
+
$.choose_case_to_expression,
|
|
496
|
+
$.choose_case_is_relational_expression,
|
|
497
|
+
$.choose_case_condition_expression,
|
|
498
|
+
), $.choose_case_clause_condition),
|
|
499
|
+
optional($.statement_separation),
|
|
500
|
+
optional(alias($.scriptable_block, $.choose_case_block)),
|
|
501
|
+
),
|
|
502
|
+
|
|
503
|
+
choose_case_to_expression: $ => seq($.r_value_expression, $.to_keyword, $.r_value_expression),
|
|
504
|
+
|
|
505
|
+
choose_case_is_relational_expression: $ => seq($.is_keyword, $.relational_operator, $.r_value_expression),
|
|
506
|
+
|
|
507
|
+
choose_case_condition_expression: $ => commaSep1($.r_value_expression),
|
|
508
|
+
|
|
509
|
+
choose_case_else_clause: $ => seq(
|
|
510
|
+
$.case_keyword,
|
|
511
|
+
$.else_keyword,
|
|
512
|
+
optional($.statement_separation),
|
|
513
|
+
optional(alias($.scriptable_block, $.choose_case_else_block)),
|
|
514
|
+
),
|
|
515
|
+
|
|
516
|
+
choose_statement_end: $ => seq(
|
|
517
|
+
$.end_keyword,
|
|
518
|
+
$.choose_keyword,
|
|
519
|
+
optional($.statement_separation),
|
|
520
|
+
),
|
|
521
|
+
|
|
522
|
+
relational_operator: _ => choice('>', '<', '>=', '<='),
|
|
523
|
+
|
|
524
|
+
do_loop: $ => seq(
|
|
525
|
+
$.do_keyword,
|
|
526
|
+
optional($.statement_separation),
|
|
527
|
+
alias(optional($.scriptable_block), $.do_loop_block),
|
|
528
|
+
$.do_loop_end,
|
|
529
|
+
),
|
|
530
|
+
|
|
531
|
+
do_loop_end: $ => seq(
|
|
532
|
+
$.loop_keyword,
|
|
533
|
+
choice($.until_keyword, $.while_keyword),
|
|
534
|
+
alias($.r_value_expression, $.condition),
|
|
535
|
+
optional($.statement_separation),
|
|
536
|
+
),
|
|
537
|
+
|
|
538
|
+
for_loop: $ => seq(
|
|
539
|
+
$.for_loop_statement,
|
|
540
|
+
optional(alias($.scriptable_block, $.for_loop_block)),
|
|
541
|
+
$.next_keyword,
|
|
542
|
+
optional($.statement_separation),
|
|
543
|
+
),
|
|
544
|
+
|
|
545
|
+
for_loop_statement: $ => seq(
|
|
546
|
+
$.for_keyword,
|
|
547
|
+
alias($.l_value_expression, $.iterator_counter),
|
|
548
|
+
'=',
|
|
549
|
+
alias($.r_value_expression, $.initial_value),
|
|
550
|
+
$.to_keyword,
|
|
551
|
+
alias($.r_value_expression, $.final_value),
|
|
552
|
+
optional(seq($.step_keyword, alias($.r_value_expression, $.increment_value))),
|
|
553
|
+
optional($.statement_separation),
|
|
554
|
+
),
|
|
555
|
+
|
|
556
|
+
goto_label: $ => seq(alias($.identifier, $.label), ':', optional($.statement_separation)),
|
|
557
|
+
|
|
558
|
+
if_statement: $ => seq(
|
|
559
|
+
$.if_then_statement,
|
|
560
|
+
optional(alias($.scriptable_block, $.if_block)),
|
|
561
|
+
repeat($.elseif_clause),
|
|
562
|
+
optional($.else_clause),
|
|
563
|
+
$.if_then_statement_end,
|
|
564
|
+
),
|
|
565
|
+
|
|
566
|
+
if_then_statement: $ => seq(
|
|
567
|
+
$.if_keyword,
|
|
568
|
+
alias($.r_value_expression, $.condition),
|
|
569
|
+
$.then_keyword,
|
|
570
|
+
optional($.statement_separation),
|
|
571
|
+
),
|
|
572
|
+
|
|
573
|
+
if_then_statement_end: $ => seq(
|
|
574
|
+
$.end_keyword,
|
|
575
|
+
$.if_keyword,
|
|
576
|
+
optional($.statement_separation),
|
|
577
|
+
),
|
|
578
|
+
|
|
579
|
+
elseif_clause: $ => seq(
|
|
580
|
+
$.elseif_keyword,
|
|
581
|
+
alias($.r_value_expression, $.condition),
|
|
582
|
+
$.then_keyword,
|
|
583
|
+
optional($.statement_separation),
|
|
584
|
+
optional(alias($.scriptable_block, $.elseif_block)),
|
|
585
|
+
),
|
|
586
|
+
|
|
587
|
+
else_clause: $ => seq(
|
|
588
|
+
$.else_keyword,
|
|
589
|
+
optional($.statement_separation),
|
|
590
|
+
optional(alias($.scriptable_block, $.else_block)),
|
|
591
|
+
),
|
|
592
|
+
|
|
593
|
+
inline_if_statement: $ => prec.left(seq(
|
|
594
|
+
$.if_keyword,
|
|
595
|
+
alias($.r_value_expression, $.condition),
|
|
596
|
+
$.then_keyword,
|
|
597
|
+
alias($.inline_statement, $.if_case_statement),
|
|
598
|
+
optional(seq($.else_keyword, alias($.inline_statement, $.else_case_statement))),
|
|
599
|
+
optional($.statement_separation),
|
|
600
|
+
)),
|
|
601
|
+
|
|
602
|
+
local_variable_declaration_statement: $ => seq(
|
|
603
|
+
$.local_variable_declaration,
|
|
604
|
+
optional($.statement_separation),
|
|
605
|
+
),
|
|
606
|
+
|
|
607
|
+
try_catch_statement: $ => seq(
|
|
608
|
+
$.try_keyword,
|
|
609
|
+
optional($.statement_separation),
|
|
610
|
+
optional(alias($.scriptable_block, $.try_block)),
|
|
611
|
+
repeat($.catch_clause),
|
|
612
|
+
optional($.finally_clause),
|
|
613
|
+
$.try_catch_statement_end,
|
|
614
|
+
),
|
|
615
|
+
|
|
616
|
+
try_catch_statement_end: $ => seq(
|
|
617
|
+
$.end_keyword,
|
|
618
|
+
$.try_keyword,
|
|
619
|
+
optional($.statement_separation),
|
|
620
|
+
),
|
|
621
|
+
|
|
622
|
+
catch_clause: $ => seq(
|
|
623
|
+
$.catch_clause_statement,
|
|
624
|
+
optional(alias($.scriptable_block, $.catch_block)),
|
|
625
|
+
),
|
|
626
|
+
|
|
627
|
+
catch_clause_statement: $ => seq(
|
|
628
|
+
$.catch_keyword,
|
|
629
|
+
$.open_parenthesis,
|
|
630
|
+
alias($.type, $.throwable_type),
|
|
631
|
+
alias($.identifier, $.throwable_name),
|
|
632
|
+
$.close_parenthesis,
|
|
633
|
+
optional($.statement_separation),
|
|
634
|
+
),
|
|
635
|
+
|
|
636
|
+
finally_clause: $ => seq(
|
|
637
|
+
$.finally_keyword,
|
|
638
|
+
optional($.statement_separation),
|
|
639
|
+
optional(alias($.scriptable_block, $.finally_block)),
|
|
640
|
+
),
|
|
641
|
+
|
|
642
|
+
while_loop: $ => seq(
|
|
643
|
+
$.while_loop_statement,
|
|
644
|
+
optional(alias($.scriptable_block, $.while_loop_block)),
|
|
645
|
+
$.loop_keyword,
|
|
646
|
+
optional($.statement_separation),
|
|
647
|
+
),
|
|
648
|
+
|
|
649
|
+
while_loop_statement: $ => seq(
|
|
650
|
+
$.do_keyword,
|
|
651
|
+
choice($.until_keyword, $.while_keyword),
|
|
652
|
+
alias($.r_value_expression, $.condition),
|
|
653
|
+
optional($.statement_separation),
|
|
654
|
+
),
|
|
655
|
+
|
|
656
|
+
inline_statement: $ => choice(
|
|
657
|
+
$.assignment_statement,
|
|
658
|
+
$.call_statement,
|
|
659
|
+
$.continue_statement,
|
|
660
|
+
$.create_statement,
|
|
661
|
+
$.destroy_statement,
|
|
662
|
+
$.exit_statement,
|
|
663
|
+
$.goto_statement,
|
|
664
|
+
$.halt_statement,
|
|
665
|
+
$.return_statement,
|
|
666
|
+
$.throw_statement,
|
|
667
|
+
$.expression_statement,
|
|
668
|
+
),
|
|
669
|
+
|
|
670
|
+
assignment_statement: $ => seq(
|
|
671
|
+
alias($.l_value_expression, $.l_value),
|
|
672
|
+
alias(choice('=', '+=', '-=', '*=', '/=', '^='), $.operator),
|
|
673
|
+
alias($.r_value_expression, $.r_value),
|
|
674
|
+
),
|
|
675
|
+
|
|
676
|
+
call_statement: $ => seq(
|
|
677
|
+
$.call_keyword,
|
|
678
|
+
alias($.r_value_expression, $.ancestor_name),
|
|
679
|
+
optional(seq('`', alias($.identifier, $.control_name))),
|
|
680
|
+
'::',
|
|
681
|
+
alias($.identifier, $.event_name),
|
|
682
|
+
),
|
|
683
|
+
|
|
684
|
+
continue_statement: $ => $.continue_keyword,
|
|
685
|
+
|
|
686
|
+
create_statement: $ => choice(
|
|
687
|
+
seq(
|
|
688
|
+
alias($.l_value_expression, $.l_value),
|
|
689
|
+
'=',
|
|
690
|
+
$.create_keyword,
|
|
691
|
+
$.type,
|
|
692
|
+
),
|
|
693
|
+
seq(
|
|
694
|
+
alias($.l_value_expression, $.l_value),
|
|
695
|
+
'=',
|
|
696
|
+
$.create_keyword,
|
|
697
|
+
$.using_keyword,
|
|
698
|
+
alias($.r_value_expression, $.dynamic_type),
|
|
699
|
+
),
|
|
700
|
+
),
|
|
701
|
+
|
|
702
|
+
destroy_statement: $ => choice(
|
|
703
|
+
seq($.destroy_keyword, $.open_parenthesis, alias($.r_value_expression, $.variable_name), $.close_parenthesis),
|
|
704
|
+
seq($.destroy_keyword, alias($.r_value_expression, $.variable_name)),
|
|
705
|
+
),
|
|
706
|
+
|
|
707
|
+
exit_statement: $ => $.exit_keyword,
|
|
708
|
+
|
|
709
|
+
goto_statement: $ => seq($.goto_keyword, alias($.identifier, $.label)),
|
|
710
|
+
|
|
711
|
+
halt_statement: $ => seq($.halt_keyword, optional($.close_keyword)),
|
|
712
|
+
|
|
713
|
+
return_statement: $ => seq(
|
|
714
|
+
$.return_keyword,
|
|
715
|
+
optional(alias($.r_value_expression, $.return_value)),
|
|
716
|
+
),
|
|
717
|
+
|
|
718
|
+
throw_statement: $ => seq(
|
|
719
|
+
$.throw_keyword,
|
|
720
|
+
choice(
|
|
721
|
+
seq($.create_keyword, $.type),
|
|
722
|
+
$.r_value_expression,
|
|
723
|
+
),
|
|
724
|
+
),
|
|
725
|
+
|
|
726
|
+
expression_statement: $ => seq(
|
|
727
|
+
choice(
|
|
728
|
+
$.method_invocation,
|
|
729
|
+
$.update_expression,
|
|
730
|
+
),
|
|
731
|
+
),
|
|
732
|
+
|
|
733
|
+
method_invocation: $ => prec(PREC.METHOD_INVOCATION, seq(
|
|
734
|
+
optional(seq(
|
|
735
|
+
alias(choice($.r_value_expression), $.method_object),
|
|
736
|
+
alias(choice('.', '::'), $.operator)),
|
|
737
|
+
),
|
|
738
|
+
optional(alias(choice($.function_keyword, $.event_keyword), $.method_type)),
|
|
739
|
+
optional(alias(choice($.static_keyword, $.dynamic_keyword), $.call_type)),
|
|
740
|
+
optional(alias(choice($.trigger_keyword, $.post_keyword), $.when_type)),
|
|
741
|
+
alias($.identifier, $.method_name),
|
|
742
|
+
$.argument_list,
|
|
743
|
+
)),
|
|
744
|
+
|
|
745
|
+
argument_list: $ => seq(
|
|
746
|
+
$.open_parenthesis,
|
|
747
|
+
commaSep(seq(optional($.ref_keyword), $.r_value_expression)),
|
|
748
|
+
$.close_parenthesis,
|
|
749
|
+
),
|
|
750
|
+
|
|
751
|
+
update_expression: $ => {
|
|
752
|
+
const argument = alias($.l_value_expression, $.argument);
|
|
753
|
+
const operator = alias(choice('--', '++'), $.operator);
|
|
754
|
+
return prec.right(PREC.UPDATE_UNARY, seq(argument, operator));
|
|
755
|
+
},
|
|
756
|
+
|
|
757
|
+
l_value_expression: $ => choice(
|
|
758
|
+
$.identifier_expression,
|
|
759
|
+
$.field_access,
|
|
760
|
+
$.array_access,
|
|
761
|
+
),
|
|
762
|
+
|
|
763
|
+
r_value_expression: $ => choice(
|
|
764
|
+
$.l_value_expression,
|
|
765
|
+
|
|
766
|
+
$.binary_expression,
|
|
767
|
+
$.unary_expression,
|
|
768
|
+
|
|
769
|
+
$._literal,
|
|
770
|
+
$.array_literal,
|
|
771
|
+
$.this_keyword,
|
|
772
|
+
$.parent_keyword,
|
|
773
|
+
$.super_keyword,
|
|
774
|
+
$.enumetation_datatype,
|
|
775
|
+
$.method_invocation,
|
|
776
|
+
$.parenthesized_expression,
|
|
777
|
+
),
|
|
778
|
+
|
|
779
|
+
binary_expression: $ => {
|
|
780
|
+
const table = [
|
|
781
|
+
{ operator: '+', precedence: PREC.ADDITIVE },
|
|
782
|
+
{ operator: '-', precedence: PREC.ADDITIVE },
|
|
783
|
+
{ operator: '*', precedence: PREC.MULTIPLICATIVE },
|
|
784
|
+
{ operator: '/', precedence: PREC.MULTIPLICATIVE },
|
|
785
|
+
{ operator: '^', precedence: PREC.EXPONENTIATION },
|
|
786
|
+
{ operator: $.or_keyword, precedence: PREC.OR },
|
|
787
|
+
{ operator: $.and_keyword, precedence: PREC.AND },
|
|
788
|
+
{ operator: '=', precedence: PREC.EQUALITY },
|
|
789
|
+
{ operator: '<>', precedence: PREC.EQUALITY },
|
|
790
|
+
{ operator: '>', precedence: PREC.RELATIONAL },
|
|
791
|
+
{ operator: '<', precedence: PREC.RELATIONAL },
|
|
792
|
+
{ operator: '>=', precedence: PREC.RELATIONAL },
|
|
793
|
+
{ operator: '<=', precedence: PREC.RELATIONAL },
|
|
794
|
+
];
|
|
795
|
+
|
|
796
|
+
return choice(...table.map(({ operator, precedence }) => {
|
|
797
|
+
return prec.left(precedence, seq(
|
|
798
|
+
alias($.r_value_expression, $.left_expression),
|
|
799
|
+
alias(operator, $.operator),
|
|
800
|
+
alias($.r_value_expression, $.right_expression),
|
|
801
|
+
));
|
|
802
|
+
}));
|
|
803
|
+
},
|
|
804
|
+
|
|
805
|
+
unary_expression: $ => prec.left(PREC.UNARY, seq(
|
|
806
|
+
alias(choice($.not_keyword, '-', '+'), $.operator),
|
|
807
|
+
field('argument', $.r_value_expression),
|
|
808
|
+
)),
|
|
809
|
+
|
|
810
|
+
array_literal: $ => seq(
|
|
811
|
+
$.open_curly_brackets,
|
|
812
|
+
commaSep1($.r_value_expression),
|
|
813
|
+
$.close_curly_brackets,
|
|
814
|
+
),
|
|
815
|
+
|
|
816
|
+
array_access: $ => seq(
|
|
817
|
+
alias($.r_value_expression, $.array_name),
|
|
818
|
+
$.open_brackets,
|
|
819
|
+
alias($.r_value_expression, $.array_index),
|
|
820
|
+
$.close_brackets,
|
|
821
|
+
),
|
|
822
|
+
|
|
823
|
+
enumetation_datatype: $ => seq(alias($.identifier, $.enum_name), '!'),
|
|
824
|
+
|
|
825
|
+
field_access: $ => prec(PREC.FIELD_ACCESS, seq(
|
|
826
|
+
alias(choice($.r_value_expression), $.object),
|
|
827
|
+
'.',
|
|
828
|
+
alias($.identifier, $.field_name),
|
|
829
|
+
optional($.array_suffix_ref),
|
|
830
|
+
)),
|
|
831
|
+
|
|
832
|
+
array_suffix_ref: _ => /\[[ \t]*\]/,
|
|
833
|
+
|
|
834
|
+
identifier_expression: $ => prec(PREC.IDENTIFIER_EXPRESSION, seq($.identifier, optional($.array_suffix_ref))),
|
|
835
|
+
|
|
836
|
+
parenthesized_expression: $ => seq($.open_parenthesis, $.r_value_expression, $.close_parenthesis),
|
|
837
|
+
|
|
838
|
+
type: $ => choice(
|
|
839
|
+
$.primitive_type,
|
|
840
|
+
alias($.identifier, $.custom_type),
|
|
841
|
+
),
|
|
842
|
+
|
|
843
|
+
_literal: $ => choice(
|
|
844
|
+
$.integer_literal,
|
|
845
|
+
$.decimal_literal,
|
|
846
|
+
$.real_literal,
|
|
847
|
+
$.string_literal,
|
|
848
|
+
$.date_literal,
|
|
849
|
+
$.time_literal,
|
|
850
|
+
$.boolean_literal,
|
|
851
|
+
),
|
|
852
|
+
|
|
853
|
+
integer_literal: _ => /\d+/,
|
|
854
|
+
decimal_literal: _ => /\d*\.\d+/,
|
|
855
|
+
real_literal: _ => /(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)[Ee][+-]?[0-9]+/,
|
|
856
|
+
date_literal: _ => /(?:\d{4}-\d{2}-\d{2})/,
|
|
857
|
+
time_literal: $ => /(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,6})?/,
|
|
858
|
+
|
|
859
|
+
string_literal: $ => choice(
|
|
860
|
+
seq($.double_quote, alias(repeat(token.immediate(prec(1, choice(/[^"\\]/, /\\./, /~"/)))), $.string_content), $.double_quote),
|
|
861
|
+
seq($.single_quote, alias(repeat(token.immediate(prec(1, choice(/[^'\\]/, /\\./, /~'/)))), $.string_content), $.single_quote),
|
|
862
|
+
),
|
|
863
|
+
|
|
864
|
+
boolean_literal: $ => choice(
|
|
865
|
+
$.true_keyword,
|
|
866
|
+
$.false_keyword,
|
|
867
|
+
),
|
|
868
|
+
|
|
869
|
+
primitive_type: _ => choice(
|
|
870
|
+
caseInsensitiveAlias('blob'),
|
|
871
|
+
caseInsensitiveAlias('boolean'),
|
|
872
|
+
caseInsensitiveAlias('byte'),
|
|
873
|
+
caseInsensitiveAlias('char'),
|
|
874
|
+
caseInsensitiveAlias('character'),
|
|
875
|
+
caseInsensitiveAlias('date'),
|
|
876
|
+
caseInsensitiveAlias('datetime'),
|
|
877
|
+
caseInsensitiveAlias('decimal'),
|
|
878
|
+
caseInsensitiveAlias('dec'),
|
|
879
|
+
caseInsensitiveAlias('double'),
|
|
880
|
+
caseInsensitiveAlias('integer'),
|
|
881
|
+
caseInsensitiveAlias('int'),
|
|
882
|
+
caseInsensitiveAlias('longlong'),
|
|
883
|
+
caseInsensitiveAlias('long'),
|
|
884
|
+
caseInsensitiveAlias('real'),
|
|
885
|
+
caseInsensitiveAlias('string'),
|
|
886
|
+
caseInsensitiveAlias('time'),
|
|
887
|
+
caseInsensitiveAlias('unsignedinteger'),
|
|
888
|
+
caseInsensitiveAlias('unsignedint'),
|
|
889
|
+
caseInsensitiveAlias('uint'),
|
|
890
|
+
caseInsensitiveAlias('unsignedlong'),
|
|
891
|
+
caseInsensitiveAlias('ulong'),
|
|
892
|
+
caseInsensitiveAlias('any'),
|
|
893
|
+
),
|
|
894
|
+
|
|
895
|
+
open_parenthesis: _ => '(',
|
|
896
|
+
close_parenthesis: _ => ')',
|
|
897
|
+
open_brackets: _ => '[',
|
|
898
|
+
close_brackets: _ => ']',
|
|
899
|
+
open_curly_brackets: _ => '{',
|
|
900
|
+
close_curly_brackets: _ => '}',
|
|
901
|
+
single_quote: _ => '\'',
|
|
902
|
+
double_quote: _ => '"',
|
|
903
|
+
statement_separation: _ => ';',
|
|
904
|
+
|
|
905
|
+
public_keyword: _ => reservedWord('public'),
|
|
906
|
+
private_keyword: _ => reservedWord('private'),
|
|
907
|
+
protected_keyword: _ => reservedWord('protected'),
|
|
908
|
+
alias_keyword: _ => reservedWord('alias'),
|
|
909
|
+
and_keyword: _ => reservedWord('and'),
|
|
910
|
+
autoinstantiate_keyword: _ => reservedWord('autoinstantiate'),
|
|
911
|
+
call_keyword: _ => reservedWord('call'),
|
|
912
|
+
case_keyword: _ => reservedWord('case'),
|
|
913
|
+
catch_keyword: _ => reservedWord('catch'),
|
|
914
|
+
choose_keyword: _ => reservedWord('choose'),
|
|
915
|
+
close_keyword: _ => reservedWord('close'),
|
|
916
|
+
commit_keyword: _ => reservedWord('commit'),
|
|
917
|
+
connect_keyword: _ => reservedWord('connect'),
|
|
918
|
+
constant_keyword: _ => reservedWord('constant'),
|
|
919
|
+
continue_keyword: _ => reservedWord('continue'),
|
|
920
|
+
create_keyword: _ => reservedWord('create'),
|
|
921
|
+
cursor_keyword: _ => reservedWord('cursor'),
|
|
922
|
+
declare_keyword: _ => reservedWord('declare'),
|
|
923
|
+
delete_keyword: _ => reservedWord('delete'),
|
|
924
|
+
describe_keyword: _ => reservedWord('describe'),
|
|
925
|
+
descriptor_keyword: _ => reservedWord('descriptor'),
|
|
926
|
+
destroy_keyword: _ => reservedWord('destroy'),
|
|
927
|
+
disconnect_keyword: _ => reservedWord('disconnect'),
|
|
928
|
+
do_keyword: _ => reservedWord('do'),
|
|
929
|
+
dynamic_keyword: _ => reservedWord('dynamic'),
|
|
930
|
+
else_keyword: _ => reservedWord('else'),
|
|
931
|
+
elseif_keyword: _ => reservedWord('elseif'),
|
|
932
|
+
end_keyword: _ => reservedWord('end'),
|
|
933
|
+
enumerated_keyword: _ => reservedWord('enumerated'),
|
|
934
|
+
event_keyword: _ => reservedWord('event'),
|
|
935
|
+
execute_keyword: _ => reservedWord('execute'),
|
|
936
|
+
exit_keyword: _ => reservedWord('exit'),
|
|
937
|
+
external_keyword: _ => reservedWord('external'),
|
|
938
|
+
false_keyword: _ => reservedWord('false'),
|
|
939
|
+
fetch_keyword: _ => reservedWord('fetch'),
|
|
940
|
+
finally_keyword: _ => reservedWord('finally'),
|
|
941
|
+
first_keyword: _ => reservedWord('first'),
|
|
942
|
+
for_keyword: _ => reservedWord('for'),
|
|
943
|
+
forward_keyword: _ => reservedWord('forward'),
|
|
944
|
+
from_keyword: _ => reservedWord('from'),
|
|
945
|
+
function_keyword: _ => reservedWord('function'),
|
|
946
|
+
global_keyword: _ => reservedWord('global'),
|
|
947
|
+
goto_keyword: _ => reservedWord('goto'),
|
|
948
|
+
halt_keyword: _ => reservedWord('halt'),
|
|
949
|
+
if_keyword: _ => reservedWord('if'),
|
|
950
|
+
immediate_keyword: _ => reservedWord('immediate'),
|
|
951
|
+
indirect_keyword: _ => reservedWord('indirect'),
|
|
952
|
+
insert_keyword: _ => reservedWord('insert'),
|
|
953
|
+
into_keyword: _ => reservedWord('into'),
|
|
954
|
+
intrinsic_keyword: _ => reservedWord('intrinsic'),
|
|
955
|
+
is_keyword: _ => reservedWord('is'),
|
|
956
|
+
last_keyword: _ => reservedWord('last'),
|
|
957
|
+
library_keyword: _ => reservedWord('library'),
|
|
958
|
+
loop_keyword: _ => reservedWord('loop'),
|
|
959
|
+
native_keyword: _ => reservedWord('native'),
|
|
960
|
+
next_keyword: _ => reservedWord('next'),
|
|
961
|
+
not_keyword: _ => reservedWord('not'),
|
|
962
|
+
of_keyword: _ => reservedWord('of'),
|
|
963
|
+
on_keyword: _ => reservedWord('on'),
|
|
964
|
+
open_keyword: _ => reservedWord('open'),
|
|
965
|
+
or_keyword: _ => reservedWord('or'),
|
|
966
|
+
parent_keyword: _ => reservedWord('parent'),
|
|
967
|
+
post_keyword: _ => reservedWord('post'),
|
|
968
|
+
prepare_keyword: _ => reservedWord('prepare'),
|
|
969
|
+
prior_keyword: _ => reservedWord('prior'),
|
|
970
|
+
privateread_keyword: _ => reservedWord('privateread'),
|
|
971
|
+
privatewrite_keyword: _ => reservedWord('privatewrite'),
|
|
972
|
+
procedure_keyword: _ => reservedWord('procedure'),
|
|
973
|
+
protectedread_keyword: _ => reservedWord('protectedread'),
|
|
974
|
+
protectedwrite_keyword: _ => reservedWord('protectedwrite'),
|
|
975
|
+
prototypes_keyword: _ => reservedWord('prototypes'),
|
|
976
|
+
readonly_keyword: _ => reservedWord('readonly'),
|
|
977
|
+
ref_keyword: _ => reservedWord('ref'),
|
|
978
|
+
return_keyword: _ => reservedWord('return'),
|
|
979
|
+
rollback_keyword: _ => reservedWord('rollback'),
|
|
980
|
+
rpcfunc_keyword: _ => reservedWord('rpcfunc'),
|
|
981
|
+
select_keyword: _ => reservedWord('select'),
|
|
982
|
+
selectblob_keyword: _ => reservedWord('selectblob'),
|
|
983
|
+
shared_keyword: _ => reservedWord('shared'),
|
|
984
|
+
static_keyword: _ => reservedWord('static'),
|
|
985
|
+
step_keyword: _ => reservedWord('step'),
|
|
986
|
+
subroutine_keyword: _ => reservedWord('subroutine'),
|
|
987
|
+
super_keyword: _ => reservedWord('super'),
|
|
988
|
+
system_keyword: _ => reservedWord('system'),
|
|
989
|
+
systemread_keyword: _ => reservedWord('systemread'),
|
|
990
|
+
systemwrite_keyword: _ => reservedWord('systemwrite'),
|
|
991
|
+
then_keyword: _ => reservedWord('then'),
|
|
992
|
+
this_keyword: _ => reservedWord('this'),
|
|
993
|
+
throw_keyword: _ => reservedWord('throw'),
|
|
994
|
+
throws_keyword: _ => reservedWord('throws'),
|
|
995
|
+
to_keyword: _ => reservedWord('to'),
|
|
996
|
+
trigger_keyword: _ => reservedWord('trigger'),
|
|
997
|
+
true_keyword: _ => reservedWord('true'),
|
|
998
|
+
try_keyword: _ => reservedWord('try'),
|
|
999
|
+
type_keyword: _ => reservedWord('type'),
|
|
1000
|
+
until_keyword: _ => reservedWord('until'),
|
|
1001
|
+
update_keyword: _ => reservedWord('update'),
|
|
1002
|
+
updateblob_keyword: _ => reservedWord('updateblob'),
|
|
1003
|
+
using_keyword: _ => reservedWord('using'),
|
|
1004
|
+
variables_keyword: _ => reservedWord('variables'),
|
|
1005
|
+
while_keyword: _ => reservedWord('while'),
|
|
1006
|
+
with_keyword: _ => reservedWord('with'),
|
|
1007
|
+
within_keyword: _ => reservedWord('within'),
|
|
1008
|
+
debug_keyword: _ => reservedWord('_debug'),
|
|
1009
|
+
where_keyword: _ => reservedWord('where'),
|
|
1010
|
+
current_keyword: _ => reservedWord('current'),
|
|
1011
|
+
|
|
1012
|
+
export_header: $ => seq(
|
|
1013
|
+
$.export_header_identifier,
|
|
1014
|
+
optional($.export_header_comments),
|
|
1015
|
+
),
|
|
1016
|
+
|
|
1017
|
+
export_header_identifier: $ => seq(
|
|
1018
|
+
alias(/(HA)?\$PBExportHeader\$/, $.export_header_identifier_text),
|
|
1019
|
+
$.export_header_identifier_content,
|
|
1020
|
+
),
|
|
1021
|
+
|
|
1022
|
+
export_header_identifier_content: $ => seq(alias($.identifier, $.file_name), '.', $.file_extension),
|
|
1023
|
+
|
|
1024
|
+
export_header_comments: $ => seq(
|
|
1025
|
+
alias('$PBExportComments$', $.export_header_comments_text),
|
|
1026
|
+
alias(/[^\r\n]*/, $.export_header_comments_content),
|
|
1027
|
+
),
|
|
1028
|
+
|
|
1029
|
+
file_extension: $ => choice(
|
|
1030
|
+
alias('sra', $.application_file_extension),
|
|
1031
|
+
alias('sru', $.user_object_file_extension),
|
|
1032
|
+
alias('srw', $.window_file_extension),
|
|
1033
|
+
alias('srm', $.menu_file_extension),
|
|
1034
|
+
alias('srs', $.structure_file_extension),
|
|
1035
|
+
alias('srf', $.function_file_extension),
|
|
1036
|
+
),
|
|
1037
|
+
|
|
1038
|
+
identifier: _ => /[a-zA-Z_][a-zA-Z0-9\-_$#%]*/,
|
|
1039
|
+
|
|
1040
|
+
line_comment: _ => seq('//', token.immediate(prec(1, /.*/))),
|
|
1041
|
+
block_comment: _ => token(seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/')),
|
|
1042
|
+
line_continuation: _ => '&',
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
sql_statement: $ => choice(
|
|
1046
|
+
$.connect_statement,
|
|
1047
|
+
$.disconnect_statement,
|
|
1048
|
+
$.commit_statement,
|
|
1049
|
+
$.rollback_statement,
|
|
1050
|
+
$.fetch_statement,
|
|
1051
|
+
$.open_cursor_statement,
|
|
1052
|
+
$.close_cursor_procedure_statement,
|
|
1053
|
+
$.execute_statement,
|
|
1054
|
+
|
|
1055
|
+
$.delete_statement,
|
|
1056
|
+
$.insert_statement,
|
|
1057
|
+
$.select_statement,
|
|
1058
|
+
$.update_statement,
|
|
1059
|
+
|
|
1060
|
+
$.declare_cursor_statement,
|
|
1061
|
+
$.declare_procedure_statement,
|
|
1062
|
+
$.declare_dynamic_statement,
|
|
1063
|
+
$.describe_sql_statement,
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
$.prepare_sql_statement,
|
|
1067
|
+
|
|
1068
|
+
/*
|
|
1069
|
+
|
|
1070
|
+
*/
|
|
1071
|
+
),
|
|
1072
|
+
|
|
1073
|
+
close_cursor_procedure_statement: $ => seq(
|
|
1074
|
+
$.close_keyword,
|
|
1075
|
+
alias($.identifier, $.cursor_procedure_name),
|
|
1076
|
+
$.statement_separation,
|
|
1077
|
+
),
|
|
1078
|
+
|
|
1079
|
+
using_transaction_statement: $ => seq(
|
|
1080
|
+
$.using_keyword,
|
|
1081
|
+
alias($.identifier, $.transaction_name),
|
|
1082
|
+
),
|
|
1083
|
+
|
|
1084
|
+
commit_statement: $ => seq(
|
|
1085
|
+
$.commit_keyword,
|
|
1086
|
+
optional($.using_transaction_statement),
|
|
1087
|
+
$.statement_separation,
|
|
1088
|
+
),
|
|
1089
|
+
|
|
1090
|
+
connect_statement: $ => seq(
|
|
1091
|
+
$.connect_keyword,
|
|
1092
|
+
optional($.using_transaction_statement),
|
|
1093
|
+
$.statement_separation,
|
|
1094
|
+
),
|
|
1095
|
+
|
|
1096
|
+
declare_cursor_statement: $ => seq(
|
|
1097
|
+
$.declare_keyword,
|
|
1098
|
+
alias($.identifier, $.cursor_name),
|
|
1099
|
+
$.cursor_keyword,
|
|
1100
|
+
$.for_keyword,
|
|
1101
|
+
$.select_statement,
|
|
1102
|
+
),
|
|
1103
|
+
|
|
1104
|
+
declare_procedure_statement: $ => seq(
|
|
1105
|
+
$.declare_keyword,
|
|
1106
|
+
alias($.identifier, $.procedure_name),
|
|
1107
|
+
$.procedure_keyword,
|
|
1108
|
+
$.for_keyword,
|
|
1109
|
+
alias($.identifier, $.store_procedure_name),
|
|
1110
|
+
optional($.stored_procedure_param_list),
|
|
1111
|
+
optional($.using_transaction_statement),
|
|
1112
|
+
$.statement_separation,
|
|
1113
|
+
),
|
|
1114
|
+
|
|
1115
|
+
declare_dynamic_statement: $ => seq(
|
|
1116
|
+
$.declare_keyword,
|
|
1117
|
+
alias($.identifier, $.cursor_procedure_name),
|
|
1118
|
+
$.dynamic_keyword,
|
|
1119
|
+
choice($.cursor_keyword, $.procedure_keyword),
|
|
1120
|
+
$.for_keyword,
|
|
1121
|
+
alias($.identifier, $.dynamic_stage_area),
|
|
1122
|
+
$.statement_separation,
|
|
1123
|
+
),
|
|
1124
|
+
|
|
1125
|
+
describe_sql_statement: $ => seq(
|
|
1126
|
+
$.describe_keyword,
|
|
1127
|
+
alias($.identifier, $.dynamic_stage_area),
|
|
1128
|
+
$.into_keyword,
|
|
1129
|
+
alias($.identifier, $.dynamic_description_area),
|
|
1130
|
+
$.statement_separation,
|
|
1131
|
+
),
|
|
1132
|
+
|
|
1133
|
+
stored_procedure_param_list: $ => choice(
|
|
1134
|
+
commaSep1($.stored_procedure_param_ase),
|
|
1135
|
+
seq($.open_parenthesis, commaSep1($.stored_procedure_param_oracle), $.close_parenthesis),
|
|
1136
|
+
),
|
|
1137
|
+
|
|
1138
|
+
stored_procedure_param_ase: $ => seq(
|
|
1139
|
+
'@',
|
|
1140
|
+
alias($.identifier, $.param_name),
|
|
1141
|
+
'=',
|
|
1142
|
+
optional(':'),
|
|
1143
|
+
alias($.r_value_expression, $.variable_name),
|
|
1144
|
+
),
|
|
1145
|
+
|
|
1146
|
+
stored_procedure_param_oracle: $ => seq(
|
|
1147
|
+
optional(':'),
|
|
1148
|
+
alias($.r_value_expression, $.variable_name),
|
|
1149
|
+
),
|
|
1150
|
+
|
|
1151
|
+
delete_statement: $ => choice(
|
|
1152
|
+
seq(
|
|
1153
|
+
$.delete_keyword,
|
|
1154
|
+
$.from_keyword,
|
|
1155
|
+
alias($.identifier, $.table_name),
|
|
1156
|
+
$.where_keyword,
|
|
1157
|
+
$.where_criteria,
|
|
1158
|
+
$.rest_of_sql,
|
|
1159
|
+
$.statement_separation,
|
|
1160
|
+
),
|
|
1161
|
+
seq(
|
|
1162
|
+
$.delete_keyword,
|
|
1163
|
+
$.from_keyword,
|
|
1164
|
+
alias($.identifier, $.table_name),
|
|
1165
|
+
$.where_keyword,
|
|
1166
|
+
$.current_keyword,
|
|
1167
|
+
$.of_keyword,
|
|
1168
|
+
alias($.identifier, $.cursor_name),
|
|
1169
|
+
$.statement_separation,
|
|
1170
|
+
),
|
|
1171
|
+
),
|
|
1172
|
+
|
|
1173
|
+
disconnect_statement: $ => seq(
|
|
1174
|
+
$.disconnect_keyword,
|
|
1175
|
+
optional($.using_transaction_statement),
|
|
1176
|
+
$.statement_separation,
|
|
1177
|
+
),
|
|
1178
|
+
|
|
1179
|
+
execute_statement: $ => choice(
|
|
1180
|
+
seq($.execute_keyword, alias($.identifier, $.procedure_name), $.statement_separation),
|
|
1181
|
+
$.execute_statement_immediate_case,
|
|
1182
|
+
seq(
|
|
1183
|
+
$.execute_keyword,
|
|
1184
|
+
alias($.identifier, $.dynamic_stage_area),
|
|
1185
|
+
$.using_keyword,
|
|
1186
|
+
commaSep1($.stored_procedure_param_oracle),
|
|
1187
|
+
$.statement_separation,
|
|
1188
|
+
),
|
|
1189
|
+
seq(
|
|
1190
|
+
$.execute_keyword,
|
|
1191
|
+
$.dynamic_keyword,
|
|
1192
|
+
alias($.identifier, $.procedure_name),
|
|
1193
|
+
optional(seq(
|
|
1194
|
+
$.using_keyword,
|
|
1195
|
+
commaSep1($.stored_procedure_param_oracle),
|
|
1196
|
+
)),
|
|
1197
|
+
$.statement_separation,
|
|
1198
|
+
),
|
|
1199
|
+
seq(
|
|
1200
|
+
$.execute_keyword,
|
|
1201
|
+
$.dynamic_keyword,
|
|
1202
|
+
alias($.identifier, $.procedure_name),
|
|
1203
|
+
$.using_keyword,
|
|
1204
|
+
$.descriptor_keyword,
|
|
1205
|
+
alias($.identifier, $.dynamic_description_area),
|
|
1206
|
+
$.statement_separation),
|
|
1207
|
+
),
|
|
1208
|
+
|
|
1209
|
+
execute_statement_immediate_case: $ => prec(PREC.IMMEDIATE_CASE, seq(
|
|
1210
|
+
$.execute_keyword,
|
|
1211
|
+
$.immediate_keyword,
|
|
1212
|
+
choice($.stored_procedure_param_oracle, $.string_literal),
|
|
1213
|
+
optional($.using_transaction_statement),
|
|
1214
|
+
$.statement_separation,
|
|
1215
|
+
)),
|
|
1216
|
+
|
|
1217
|
+
fetch_statement: $ => choice(
|
|
1218
|
+
seq(
|
|
1219
|
+
$.fetch_keyword,
|
|
1220
|
+
alias($.identifier, $.cursor_procedure_name),
|
|
1221
|
+
$.into_keyword,
|
|
1222
|
+
$.fetch_variable_list,
|
|
1223
|
+
$.statement_separation,
|
|
1224
|
+
),
|
|
1225
|
+
seq(
|
|
1226
|
+
$.fetch_keyword,
|
|
1227
|
+
alias($.identifier, $.cursor_procedure_name),
|
|
1228
|
+
$.using_keyword,
|
|
1229
|
+
$.descriptor_keyword,
|
|
1230
|
+
alias($.identifier, $.dynamic_stage_area),
|
|
1231
|
+
$.statement_separation,
|
|
1232
|
+
),
|
|
1233
|
+
),
|
|
1234
|
+
|
|
1235
|
+
fetch_variable_list: $ => commaSep1(seq(
|
|
1236
|
+
':',
|
|
1237
|
+
alias($.identifier, $.variable_name),
|
|
1238
|
+
optional(seq(
|
|
1239
|
+
':',
|
|
1240
|
+
alias($.identifier, $.indicator_var),
|
|
1241
|
+
)),
|
|
1242
|
+
)),
|
|
1243
|
+
|
|
1244
|
+
insert_statement: $ => seq(
|
|
1245
|
+
$.insert_keyword,
|
|
1246
|
+
$.rest_of_sql,
|
|
1247
|
+
$.statement_separation,
|
|
1248
|
+
),
|
|
1249
|
+
|
|
1250
|
+
open_cursor_statement: $ => choice(
|
|
1251
|
+
seq(
|
|
1252
|
+
$.open_keyword,
|
|
1253
|
+
alias($.identifier, $.cursor_name),
|
|
1254
|
+
$.statement_separation,
|
|
1255
|
+
),
|
|
1256
|
+
seq(
|
|
1257
|
+
$.open_keyword,
|
|
1258
|
+
$.dynamic_keyword,
|
|
1259
|
+
alias($.identifier, $.cursor_name),
|
|
1260
|
+
optional(seq(
|
|
1261
|
+
$.using_keyword,
|
|
1262
|
+
commaSep1($.stored_procedure_param_oracle),
|
|
1263
|
+
)),
|
|
1264
|
+
$.statement_separation,
|
|
1265
|
+
),
|
|
1266
|
+
seq(
|
|
1267
|
+
$.open_keyword,
|
|
1268
|
+
$.dynamic_keyword,
|
|
1269
|
+
alias($.identifier, $.cursor_name),
|
|
1270
|
+
$.using_keyword,
|
|
1271
|
+
$.descriptor_keyword,
|
|
1272
|
+
alias($.identifier, $.dynamic_staging_area),
|
|
1273
|
+
$.statement_separation,
|
|
1274
|
+
),
|
|
1275
|
+
),
|
|
1276
|
+
|
|
1277
|
+
rollback_statement: $ => seq(
|
|
1278
|
+
$.rollback_keyword,
|
|
1279
|
+
optional($.using_transaction_statement),
|
|
1280
|
+
$.statement_separation,
|
|
1281
|
+
),
|
|
1282
|
+
|
|
1283
|
+
select_statement: $ => seq(
|
|
1284
|
+
choice($.select_keyword, $.selectblob_keyword),
|
|
1285
|
+
$.rest_of_sql,
|
|
1286
|
+
$.statement_separation,
|
|
1287
|
+
),
|
|
1288
|
+
|
|
1289
|
+
update_statement: $ => seq(
|
|
1290
|
+
choice($.update_keyword, $.updateblob_keyword),
|
|
1291
|
+
alias($.identifier, $.table_name),
|
|
1292
|
+
$.rest_of_sql,
|
|
1293
|
+
$.statement_separation,
|
|
1294
|
+
),
|
|
1295
|
+
|
|
1296
|
+
prepare_sql_statement: $ => seq(
|
|
1297
|
+
$.prepare_keyword,
|
|
1298
|
+
alias($.identifier, $.dynamic_staging_area),
|
|
1299
|
+
$.from_keyword,
|
|
1300
|
+
choice(
|
|
1301
|
+
alias($.string_literal, $.sql_statement),
|
|
1302
|
+
seq(':', alias($.r_value_expression, $.sql_statement)),
|
|
1303
|
+
),
|
|
1304
|
+
$.statement_separation,
|
|
1305
|
+
),
|
|
1306
|
+
|
|
1307
|
+
rest_of_sql: $ => token(/[^;]*/),
|
|
1308
|
+
|
|
1309
|
+
where_criteria: $ => $.rest_of_sql,
|
|
1310
|
+
|
|
1311
|
+
},
|
|
1312
|
+
});
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Creates a reserved word
|
|
1316
|
+
*
|
|
1317
|
+
* @param {string} word
|
|
1318
|
+
*
|
|
1319
|
+
* @returns {AliasRule}
|
|
1320
|
+
*/
|
|
1321
|
+
function reservedWord(word) {
|
|
1322
|
+
return alias(reserved(caseInsensitiveRegExp(word)), word);
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* Creates a reserved word regex
|
|
1327
|
+
*
|
|
1328
|
+
* @param {RegExp} regex
|
|
1329
|
+
*
|
|
1330
|
+
* @returns {TokenRule}
|
|
1331
|
+
*/
|
|
1332
|
+
function reserved(regex) {
|
|
1333
|
+
return token(prec(PREC.KEYWORD, regex));
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
* Creates a case insensitive word
|
|
1338
|
+
*
|
|
1339
|
+
* @param {string} word
|
|
1340
|
+
*
|
|
1341
|
+
* @returns {RegExp}
|
|
1342
|
+
*/
|
|
1343
|
+
function caseInsensitiveRegExp(word) {
|
|
1344
|
+
return new RegExp(word.split('')
|
|
1345
|
+
.map(letter => `[${letter}${letter.toUpperCase()}]`)
|
|
1346
|
+
.join(''),
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Creates a case insensitive alias rule
|
|
1352
|
+
*
|
|
1353
|
+
* @param {string} word
|
|
1354
|
+
*
|
|
1355
|
+
* @returns {AliasRule}
|
|
1356
|
+
*/
|
|
1357
|
+
function caseInsensitiveAlias(word) {
|
|
1358
|
+
return alias(caseInsensitiveRegExp(word), word);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1363
|
+
*
|
|
1364
|
+
* @param {Rule} rule
|
|
1365
|
+
*
|
|
1366
|
+
* @returns {ChoiceRule}
|
|
1367
|
+
*/
|
|
1368
|
+
function commaSep(rule) {
|
|
1369
|
+
return optional(commaSep1(rule));
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* Creates a rule to match one or more of the rules separated by a comma
|
|
1374
|
+
*
|
|
1375
|
+
* @param {Rule} rule
|
|
1376
|
+
*
|
|
1377
|
+
* @returns {SeqRule}
|
|
1378
|
+
*/
|
|
1379
|
+
function commaSep1(rule) {
|
|
1380
|
+
return seq(rule, repeat(seq(',', rule)));
|
|
1381
|
+
}
|