Skip to content

Commit f7e8d2e

Browse files
Merged global and member func nodes + resolved #9
1 parent 4880ab7 commit f7e8d2e

File tree

7 files changed

+64
-119
lines changed

7 files changed

+64
-119
lines changed

grammar.js

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,14 @@ module.exports = grammar({
102102

103103
conflicts: $ => [
104104
[$._expr, $._paren_ident], // nested expr
105-
[$.struct_specifier, $.state_specifier, $.class_specifier, $.global_func_specifier], // import
106-
[$.state_specifier, $.class_specifier], // abstract
107-
[$.member_var_specifier, $.member_func_specifier],
108-
[$.autobind_specifier, $.member_var_specifier, $.member_func_specifier] // access_modifier
109105
],
110106

111107
rules: {
112108

113109
// TOP LEVEL RULE ===============================================
114110

115111
script: $ => repeat(choice(
116-
$.global_func_decl_stmt,
112+
$.func_decl_stmt,
117113
$.class_decl_stmt,
118114
$.state_decl_stmt,
119115
$.struct_decl_stmt,
@@ -164,7 +160,7 @@ module.exports = grammar({
164160
// STRUCT DECLARATION ==================
165161

166162
struct_decl_stmt: $ => seq(
167-
field('specifiers', repeat($.struct_specifier)),
163+
field('specifiers', repeat($.specifier)),
168164
$._struct_decl_intro,
169165
field('definition', $.struct_block)
170166
),
@@ -177,10 +173,6 @@ module.exports = grammar({
177173
$._struct_stmt
178174
),
179175

180-
struct_specifier: $ => choice(
181-
'import'
182-
),
183-
184176
_struct_stmt: $ => choice(
185177
$.member_var_decl_stmt,
186178
$.member_default_val_stmt,
@@ -193,7 +185,7 @@ module.exports = grammar({
193185
// STATE DECLARATION ===================
194186

195187
state_decl_stmt: $ => seq(
196-
field('specifiers', repeat($.state_specifier)),
188+
field('specifiers', repeat($.specifier)),
197189
$._state_decl_intro,
198190
$._state_decl_parent,
199191
optional($._class_base),
@@ -208,16 +200,11 @@ module.exports = grammar({
208200
'in', field('parent', $.ident),
209201
),
210202

211-
state_specifier: $ => choice(
212-
'import',
213-
'abstract'
214-
),
215-
216203

217204
// CLASS DECLARATION ===================
218205

219206
class_decl_stmt: $ => seq(
220-
field('specifiers', repeat($.class_specifier)),
207+
field('specifiers', repeat($.specifier)),
221208
$._class_decl_intro,
222209
optional($._class_base),
223210
field('definition', $.class_block)
@@ -235,12 +222,6 @@ module.exports = grammar({
235222
'extends', field('base', $.ident)
236223
),
237224

238-
class_specifier: $ => choice(
239-
'import',
240-
'abstract',
241-
'statemachine'
242-
),
243-
244225

245226
// CLASS ===============================
246227

@@ -250,13 +231,13 @@ module.exports = grammar({
250231
$.member_defaults_block_stmt,
251232
$.member_hint_stmt,
252233
$.autobind_stmt,
253-
$.member_func_decl_stmt,
234+
$.func_decl_stmt,
254235
$.event_decl_stmt,
255236
$.nop
256237
),
257238

258239
autobind_stmt: $ => seq(
259-
field('specifiers', repeat($.autobind_specifier)),
240+
field('specifiers', repeat($.specifier)),
260241
$._autobind_intro,
261242
':',
262243
field('autobind_type', $.type_annot),
@@ -280,11 +261,6 @@ module.exports = grammar({
280261

281262
autobind_single: $ => 'single',
282263

283-
autobind_specifier: $ => choice(
284-
$._access_modifier,
285-
'optional',
286-
),
287-
288264
member_defaults_block_stmt: $ => seq(
289265
'defaults',
290266
block($.member_defaults_block_assign)
@@ -323,22 +299,13 @@ module.exports = grammar({
323299
),
324300

325301
member_var_decl_stmt: $ => seq(
326-
field('specifiers', repeat($.member_var_specifier)),
302+
field('specifiers', repeat($.specifier)),
327303
$._var_decl_intro,
328304
':',
329305
field('var_type', $.type_annot),
330306
';'
331307
),
332308

333-
member_var_specifier: $ => choice(
334-
$._access_modifier,
335-
'import',
336-
'const',
337-
'editable',
338-
'inlined',
339-
'saved',
340-
),
341-
342309

343310
// FUNCTION DECLARATION ================
344311

@@ -356,21 +323,9 @@ module.exports = grammar({
356323
'event', field('name', $.ident),
357324
),
358325

359-
member_func_decl_stmt: $ => seq(
360-
field('specifiers', repeat($.member_func_specifier)),
361-
field('flavour', optional($.member_func_flavour)),
362-
$._func_decl_intro,
363-
field('params', $.func_params),
364-
optional(seq(
365-
':',
366-
field('return_type', $.type_annot)
367-
)),
368-
field('definition', $._func_definition)
369-
),
370-
371-
global_func_decl_stmt: $ => seq(
372-
field('specifiers', repeat($.global_func_specifier)),
373-
field('flavour', optional($.global_func_flavour)),
326+
func_decl_stmt: $ => seq(
327+
field('specifiers', repeat($.specifier)),
328+
field('flavour', optional($.func_flavour)),
374329
$._func_decl_intro,
375330
field('params', $.func_params),
376331
optional(seq(
@@ -395,48 +350,38 @@ module.exports = grammar({
395350
),
396351

397352
func_param_group: $ => seq(
398-
field('specifiers', repeat($.func_param_specifier)),
353+
field('specifiers', repeat($.specifier)),
399354
field('names', comma1($.ident)),
400355
':',
401356
field('param_type', $.type_annot),
402357
),
403358

404-
func_param_specifier: $ => choice(
405-
'optional',
406-
'out'
407-
),
408359

409-
410-
member_func_flavour: $ => choice(
411-
'entry',
360+
func_flavour: $ => choice(
412361
'cleanup',
413-
'timer',
414-
),
415-
416-
member_func_specifier: $ => choice(
417-
$._access_modifier,
418-
'import',
419-
'latent',
420-
'final',
421-
),
422-
423-
_access_modifier: $ => choice(
424-
"private",
425-
"protected",
426-
"public"
427-
),
428-
429-
430-
global_func_flavour: $ => choice(
362+
'entry',
431363
'exec',
432364
'quest',
365+
'reward',
433366
'storyscene',
434-
'reward' // present in the code exactly once, LOL
367+
'timer',
435368
),
436369

437-
global_func_specifier: $ => choice(
370+
specifier: $ => choice(
371+
'abstract',
372+
'const',
373+
'editable',
374+
'final',
438375
'import',
376+
'inlined',
439377
'latent',
378+
'optional',
379+
'out',
380+
'private',
381+
'protected',
382+
'public',
383+
'saved',
384+
'statemachine'
440385
),
441386

442387

test/corpus/classes.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ abstract statemachine class Player extends Actor {
3333

3434
(script
3535
(class_decl_stmt
36-
specifiers: (class_specifier)
37-
specifiers: (class_specifier)
36+
specifiers: (specifier)
37+
specifiers: (specifier)
3838
name: (ident)
3939
base: (ident)
4040
definition: (class_block
4141
(member_var_decl_stmt
42-
specifiers: (member_var_specifier)
43-
specifiers: (member_var_specifier)
44-
specifiers: (member_var_specifier)
42+
specifiers: (specifier)
43+
specifiers: (specifier)
44+
specifiers: (specifier)
4545
names: (ident)
4646
var_type: (type_annot
4747
type_name: (ident)))
@@ -52,17 +52,17 @@ abstract statemachine class Player extends Actor {
5252
member: (ident)
5353
value: (literal_string))
5454
(member_var_decl_stmt
55-
specifiers: (member_var_specifier)
56-
specifiers: (member_var_specifier)
57-
specifiers: (member_var_specifier)
55+
specifiers: (specifier)
56+
specifiers: (specifier)
57+
specifiers: (specifier)
5858
names: (ident)
5959
names: (ident)
6060
names: (ident)
6161
var_type: (type_annot
6262
type_name: (ident)))
6363
(member_var_decl_stmt
64-
specifiers: (member_var_specifier)
65-
specifiers: (member_var_specifier)
64+
specifiers: (specifier)
65+
specifiers: (specifier)
6666
names: (ident)
6767
var_type: (type_annot
6868
type_name: (ident)
@@ -81,14 +81,14 @@ abstract statemachine class Player extends Actor {
8181
member: (ident)
8282
value: (literal_float)))
8383
(autobind_stmt
84-
specifiers: (autobind_specifier)
84+
specifiers: (specifier)
8585
name: (ident)
8686
autobind_type: (type_annot
8787
type_name: (ident))
8888
value: (literal_string))
8989
(autobind_stmt
90-
specifiers: (autobind_specifier)
91-
specifiers: (autobind_specifier)
90+
specifiers: (specifier)
91+
specifiers: (specifier)
9292
name: (ident)
9393
autobind_type: (type_annot
9494
type_name: (ident))
@@ -101,17 +101,17 @@ abstract statemachine class Player extends Actor {
101101
param_type: (type_annot
102102
type_name: (ident))))
103103
definition: (func_block))
104-
(member_func_decl_stmt
105-
specifiers: (member_func_specifier)
106-
specifiers: (member_func_specifier)
104+
(func_decl_stmt
105+
specifiers: (specifier)
106+
specifiers: (specifier)
107107
name: (ident)
108108
params: (func_params
109109
(func_param_group
110110
names: (ident)
111111
param_type: (type_annot
112112
type_name: (ident)))
113113
(func_param_group
114-
specifiers: (func_param_specifier)
114+
specifiers: (specifier)
115115
names: (ident)
116116
names: (ident)
117117
param_type: (type_annot

test/corpus/comments.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function foo() { // comment after some code
1414

1515
(script
1616
(comment)
17-
(global_func_decl_stmt
17+
(func_decl_stmt
1818
name: (ident)
1919
params: (func_params)
2020
definition: (func_block

test/corpus/expressions.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function test() {
1616
---------------------------------------------------------------------------------------------------
1717

1818
(script
19-
(global_func_decl_stmt
19+
(func_decl_stmt
2020
name: (ident)
2121
params: (func_params)
2222
definition: (func_block
@@ -54,7 +54,7 @@ function test() {
5454
---------------------------------------------------------------------------------------------------
5555

5656
(script
57-
(global_func_decl_stmt
57+
(func_decl_stmt
5858
name: (ident)
5959
params: (func_params)
6060
definition: (func_block
@@ -99,7 +99,7 @@ function test() {
9999
---------------------------------------------------------------------------------------------------
100100

101101
(script
102-
(global_func_decl_stmt
102+
(func_decl_stmt
103103
name: (ident)
104104
params: (func_params)
105105
definition: (func_block
@@ -199,7 +199,7 @@ function test() {
199199
---------------------------------------------------------------------------------------------------
200200

201201
(script
202-
(global_func_decl_stmt
202+
(func_decl_stmt
203203
name: (ident)
204204
params: (func_params)
205205
definition: (func_block
@@ -260,7 +260,7 @@ function test() {
260260
---------------------------------------------------------------------------------------------------
261261

262262
(script
263-
(global_func_decl_stmt
263+
(func_decl_stmt
264264
name: (ident)
265265
params: (func_params)
266266
definition: (func_block
@@ -342,7 +342,7 @@ function test() {
342342
---------------------------------------------------------------------------------------------------
343343

344344
(script
345-
(global_func_decl_stmt
345+
(func_decl_stmt
346346
name: (ident)
347347
params: (func_params)
348348
definition: (func_block
@@ -384,7 +384,7 @@ function test() {
384384
---------------------------------------------------------------------------------------------------
385385

386386
(script
387-
(global_func_decl_stmt
387+
(func_decl_stmt
388388
name: (ident)
389389
params: (func_params)
390390
definition: (func_block

0 commit comments

Comments
 (0)