1
1
grammar Module;
2
2
3
- moduleDefinition : (documentation = Doc)? annotations?
4
- ' module' (name = qualifiedName)
5
- (' as' (alias = Name) )?
3
+ moduleDefinition : ( documentation = Doc )? annotations?
4
+ ' module' qualifiedName
5
+ ( ' as' Name )?
6
6
moduleElement*
7
7
;
8
8
@@ -12,7 +12,7 @@ moduleElement : importDeclaration
12
12
| moduleMethodDefinition
13
13
;
14
14
15
- importDeclaration : ' import' (name = qualifiedName) ( ' as' (alias = Name) )?
15
+ importDeclaration : ' import' qualifiedName ( ' as' Name )?
16
16
;
17
17
18
18
typeDefinition : interfaceDefinition
@@ -21,9 +21,9 @@ typeDefinition : interfaceDefinition
21
21
| enumDefinition
22
22
;
23
23
24
- interfaceDefinition : (documentation = Doc)? annotations?
25
- ' interface' (name = Name) typeParameters?
26
- ( ' extends' superInterfaceDefinition (' ,' superInterfaceDefinition )* )?
24
+ interfaceDefinition : ( documentation = Doc )? annotations?
25
+ ' interface' Name typeParameters?
26
+ ( ' extends' superInterfaceDefinition ( ' ,' superInterfaceDefinition )* )?
27
27
' {'
28
28
interfaceMethodDefinition*
29
29
' }'
@@ -32,116 +32,128 @@ interfaceDefinition : (documentation = Doc)? annotations?
32
32
superInterfaceDefinition : qualifiedName typeArguments?
33
33
;
34
34
35
- externTypeDefinition : (documentation = Doc)? annotations?
36
- ' extern' ' interface' (name = qualifiedName)
35
+ externTypeDefinition : ( documentation = Doc )? annotations?
36
+ ' extern' ' interface' qualifiedName
37
37
;
38
38
39
- typeParameters : ' <' (parameters += typeParameter ) ( ' ,' ( parameters += typeParameter ) )* ' >'
39
+ typeParameters : ' <' Name ( ' ,' Name )* ' >'
40
40
;
41
41
42
- typeParameter : (name = Name)
43
- ;
44
-
45
- structDefinition : (documentation = Doc)? annotations?
46
- ' struct' (name = Name) ' {'
42
+ structDefinition : ( documentation = Doc )? annotations?
43
+ ' struct' Name ' {'
47
44
propertyDefinition*
48
45
' }'
49
46
;
50
47
51
- constDefinition : (documentation = Doc)? annotations?
52
- ' const' ( name = Name ) ' {'
48
+ constDefinition : ( documentation = Doc )? annotations?
49
+ ' const' Name ' {'
53
50
constEntry*
54
51
' }'
55
52
;
56
53
57
- constEntry : (documentation = Doc)? annotations?
54
+ constEntry : ( documentation = Doc )? annotations?
58
55
constEntryDecl
59
56
;
60
57
61
58
constEntryDecl
62
- : boolType? ( name = Name ) ' =' ( boolValue = Boolean )
63
- | intType? ( name = Name ) ' =' ( intValue = Integer )
64
- | floatType? ( name = Name ) ' =' ( floatValue = Float )
65
- | stringType? ( name = Name ) ' =' ( stringValue = String )
59
+ : boolType? Name ' =' Boolean
60
+ | intType? Name ' =' Integer
61
+ | floatType? Name ' =' Float
62
+ | stringType? Name ' =' String
66
63
;
67
64
68
- enumDefinition : (documentation = Doc)? annotations?
69
- ' enum' (name = Name) ' {'
70
- (values += enumValue) *
65
+ enumDefinition : ( documentation = Doc )? annotations?
66
+ ' enum' Name ' {'
67
+ enumValue*
71
68
' }'
72
69
;
73
70
74
- enumValue : (documentation = Doc)? annotations?
75
- (name = Name)
71
+ enumValue : ( documentation = Doc )? annotations?
72
+ Name
76
73
;
77
74
78
- moduleMethodDefinition : (documentation = Doc)? annotations?
75
+ moduleMethodDefinition : ( documentation = Doc )? annotations?
79
76
(isStatic = ' static' )?
80
77
methodDefinition
81
78
;
82
79
83
- interfaceMethodDefinition : (documentation = Doc)? annotations?
80
+ interfaceMethodDefinition : ( documentation = Doc )? annotations?
84
81
methodDefinition
85
82
;
86
83
87
84
methodDefinition :
88
85
typeParameters?
89
- returnTypeChain
90
- (name = Name)
91
- ' (' ( parameters = typeNamePairs ) ? ' )'
86
+ returnType
87
+ Name
88
+ ' (' methodParameters ? ' )'
92
89
;
93
90
94
- propertyDefinition : (documentation = Doc)? annotations?
95
- (property = typeNamePair)
91
+ propertyDefinition : ( documentation = Doc )? annotations?
92
+ typeNamePair
96
93
;
97
94
98
95
annotations : annotation+
99
96
;
100
97
101
- annotation : ' @' (name = Name) ( ' (' annotationParameters? ' )' )?
98
+ annotation : ' @' Name ( ' (' annotationParameters? ' )' )?
102
99
;
103
100
104
101
annotationParameters : annotationValue
105
102
| annotationParameter ( ' ,' annotationParameter )*
106
103
;
107
104
108
- annotationParameter : ( name = Name ) ' =' annotationValue
105
+ annotationParameter : Name ' =' annotationValue
106
+ ;
107
+
108
+ annotationValue : Null
109
+ | Boolean
110
+ | Integer
111
+ | Float
112
+ | String
113
+ ;
114
+
115
+ methodParameters : methodParameter ( ' ,' methodParameter )*
109
116
;
110
117
111
- annotationValue : ( nullValue = Null ) # annotationNullParameter
112
- | ( boolValue = Boolean ) # annotationBooleanParameter
113
- | ( intValue = Integer ) # annotationIntParameter
114
- | ( floatValue = Float ) # annotationFloatParameter
115
- | ( stringValue = String ) # annotationStringParameter
118
+ methodParameter : annotations? typeNamePair
116
119
;
117
120
118
- typeNamePairs : ( elements += typeNamePair ) ( ' , ' elements += typeNamePair )*
121
+ typeNamePair : complexType Name
119
122
;
120
123
121
- typeNamePair : annotations? (type = typeChain) (name = Name)
124
+ returnType
125
+ : voidType
126
+ | complexType
122
127
;
123
128
124
- returnTypeChain : voidType # voidReturnTypeChain
125
- | typeChain # normalReturnTypeChain
129
+ complexType
130
+ : type
131
+ | typeChain
126
132
;
127
133
128
- typeChain : valueType
129
- | callbackTypeChain
134
+ type
135
+ : primitiveType ArrayQualifier*
136
+ | objectType ArrayQualifier*
130
137
;
131
138
132
- callbackTypeChain : ( elements += typeChainElement ) ( ' ->' ( elements += typeChainElement) )+
139
+ typeChain
140
+ : typeChainElements
141
+ | ' (' typeChainElements ' )' ArrayQualifier+
133
142
;
134
143
135
- typeChainElement : returnType # simpleTypeChainElement
136
- | ' (' typeChain ' )' # subTypeChainElement
144
+ typeChainElements
145
+ : voidType ' ->' typeChainReturnType
146
+ | typeChainElement ( ' ->' typeChainElement )* ' ->' typeChainReturnType
137
147
;
138
148
139
- returnType : voidType
140
- | valueType
149
+ typeChainReturnType
150
+ : voidType
151
+ | typeChainElement
141
152
;
142
153
143
- valueType : primitiveType ArrayQualifier*
144
- | moduleType ArrayQualifier*
154
+ typeChainElement
155
+ : type
156
+ | ' (' typeChain ' )'
145
157
;
146
158
147
159
primitiveType : boolType
@@ -169,21 +181,21 @@ anyType : 'any'
169
181
voidType : ' void'
170
182
;
171
183
172
- moduleType : ( name = qualifiedName ) ( arguments = typeArguments ) ?
184
+ objectType : qualifiedName typeArguments?
173
185
;
174
186
175
- typeArguments : ' <' ( arguments += returnType ) ( ' ,' ( arguments += returnType ) )* ' >'
187
+ typeArguments : ' <' returnType ( ' ,' returnType )* ' >'
176
188
;
177
189
178
- qualifiedName : ( parts += Name ) ( ' .' parts += Name )*
190
+ qualifiedName : Name ( ' .' Name )*
179
191
;
180
192
181
193
Null : ' null' ;
182
194
Boolean : ( ' true' | ' false' );
183
195
Integer : SIGN ? INTEGER_NUMBER ;
184
196
Float : SIGN ? NON_INTEGER_NUMBER ;
185
197
String : ' "' STRING_GUTS ' "' ;
186
- Doc : ' /**' .*? ' */' ' \r ' * ' \n ' ? ;
198
+ Doc : ' /**' .*? ' */' ;
187
199
Name : [_a-zA-Z ][_a-zA-Z0 -9]*;
188
200
ArrayQualifier : ' [' ' ]' ;
189
201
0 commit comments