-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS.g
More file actions
64 lines (51 loc) · 1.57 KB
/
JS.g
File metadata and controls
64 lines (51 loc) · 1.57 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
tree grammar JS;
options {
tokenVocab = Sneakers;
ASTLabelType = SneakersAST;
output = template;
}
@header {
package sneakers;
}
/*compilationUnit
: ^(BLOCK stats+=stat+) -> file(stats={$stats})
;*/
compilationUnit
: ^(BLOCK stats+=stat+) -> file(stats={$stats})
;
stat
: ^('=' name=(ID | MUTID) value=expr)
-> assignment(name={$name}, value={$value.st})
| ^(CLASSDEF name=TYPEID (methods+=method | fields+=field)* )
-> classdef(name={$name}, fields={$fields}, methods={$methods})
| 'pass' -> pass()
| ^(RET e=expr) -> return(expr={$e.st})
;
field : ^(FIELDDEF name=ID type=TYPEID) -> identity(o={$name})
;
method : ^(METHODDEF name=ID ^(FNDECL ret=TYPEID params+=param* ^(BLOCK stats+=stat+)))
-> method(name={$name}, params={$params}, stats={$stats})
;
expr : ^((FNDECL | MUTDECL) ret=TYPEID params+=param* ^(BLOCK stats+=stat+))
-> fndecl(params={$params}, stats={$stats})
| ^(FNCALL names+=any_id+ params+=fncallparam*) -> fncall(names={$names},params={$params})
| ^(INSTANCE types+=any_id+ d=dict)
-> instance(types={$types}, attrs={$d.st})
| i=INT -> identity(o={$i})
| i=ID -> identity(o={$i})
| s=STRING -> identity(o={$s})
| d=dict -> identity(o={$d.st})
| ^(ARRAY exs+=expr*) -> array(exs={$exs})
;
dict : ^(DICT attrs+=dict_pair*) -> dict(attrs={$attrs})
;
dict_pair: ^(DICT_PAIR key=expr value=expr) -> dict_pair(key={$key.st}, value={$value.st})
;
fncallparam
: ^(PARAM ex=expr) -> identity(o={$ex.st})
;
any_id
: (i=ID | i=MUTID | i=TYPEID) -> identity(o={$i})
;
param : ^(FNPARAM name=ID type=TYPEID) -> identity(o={$name})
;