@@ -117,112 +117,114 @@ ClassQualifier ::= ‘[’ id ‘]’
117
117
118
118
### Types
119
119
``` ebnf
120
- Type ::= [‘implicit’] FunArgTypes ‘=>’ Type
121
- | HkTypeParamClause ‘=>’ Type
120
+ Type ::= [‘implicit’] FunArgTypes ‘=>’ Type Function(ts, t)
121
+ | HkTypeParamClause ‘=>’ Type TypeLambda(ps, t)
122
122
| InfixType
123
123
FunArgTypes ::= InfixType
124
124
| ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’
125
- InfixType ::= RefinedType {id [nl] RefinedType}
126
- RefinedType ::= WithType {[nl] Refinement}
127
- WithType ::= AnnotType {‘with’ AnnotType}
128
- AnnotType ::= SimpleType {Annotation}
129
- SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs)
130
- | SimpleType ‘#’ id
125
+ InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
126
+ RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds)
127
+ WithType ::= AnnotType {‘with’ AnnotType} (deprecated)
128
+ AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
129
+ SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args)
130
+ | SimpleType ‘#’ id Select(t, name)
131
131
| StableId
132
- | Path ‘.’ ‘type’
133
- | ‘(’ ArgTypes ‘)’
132
+ | Path ‘.’ ‘type’ SingletonTypeTree(p)
133
+ | ‘(’ ArgTypes ‘)’ Tuple(ts)
134
134
| ‘_’ TypeBounds
135
- | Refinement
136
- | SimpleLiteral
135
+ | Refinement RefinedTypeTree(EmptyTree, refinement)
136
+ | SimpleLiteral SingletonTypeTree(l)
137
137
ArgTypes ::= Type {‘,’ Type}
138
138
| NamedTypeArg {‘,’ NamedTypeArg}
139
139
FunArgType ::= Type
140
- | ‘=>’ Type
140
+ | ‘=>’ Type PrefixOp(=>, t)
141
141
ParamType ::= [‘=>’] ParamValueType
142
- ParamValueType ::= Type [‘*’]
143
- TypeArgs ::= ‘[’ ArgTypes ‘]’
144
- NamedTypeArg ::= id ‘=’ Type
145
- NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’
146
- Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’
147
- TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT
148
- TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type}
142
+ ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
143
+ TypeArgs ::= ‘[’ ArgTypes ‘]’ ts
144
+ NamedTypeArg ::= id ‘=’ Type NamedArg(id, t)
145
+ NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
146
+ Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ ds
147
+ TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi)
148
+ TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} ContextBounds(typeBounds, tps)
149
149
```
150
150
151
151
### Expressions
152
152
``` ebnf
153
- Expr ::= [‘implicit’] FunParams ‘=>’ Expr
153
+ Expr ::= [‘implicit’] FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr)
154
154
| Expr1
155
155
BlockResult ::= [‘implicit’] FunParams ‘=>’ Block
156
156
| Expr1
157
157
FunParams ::= Bindings
158
158
| id
159
159
| ‘_’
160
- Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr]
161
- | ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr]
162
- | ‘while’ ‘(’ Expr ‘)’ {nl} Expr
163
- | ‘while’ Expr ‘do’ Expr
164
- | ‘do’ Expr [semi] ‘while’ Expr
165
- | ‘try’ Expr Catches [‘finally’ Expr]
166
- | ‘try’ Expr [‘finally’ Expr]
167
- | ‘throw’ Expr
168
- | ‘return’ [Expr]
160
+ Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] If(Parens(cond), thenp, elsep?)
161
+ | ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?)
162
+ | ‘while’ ‘(’ Expr ‘)’ {nl} Expr WhileDo(Parens(cond), body)
163
+ | ‘while’ Expr ‘do’ Expr WhileDo(cond, body)
164
+ | ‘do’ Expr [semi] ‘while’ Expr DoWhile(expr, cond)
165
+ | ‘try’ Expr Catches [‘finally’ Expr] Try(expr, catches, expr?)
166
+ | ‘try’ Expr [‘finally’ Expr] Try(expr, Nil, expr?)
167
+ | ‘throw’ Expr Throw(expr)
168
+ | ‘return’ [Expr] Return(expr?)
169
169
| ForExpr
170
- | [SimpleExpr ‘.’] id ‘=’ Expr
171
- | SimpleExpr1 ArgumentExprs ‘=’ Expr
170
+ | [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
171
+ | SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
172
172
| PostfixExpr [Ascription]
173
- | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’
174
- Ascription ::= ‘:’ InfixType
175
- | ‘:’ Annotation {Annotation}
173
+ | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) -- point on match
174
+ Ascription ::= ‘:’ InfixType Typed(expr, tp)
175
+ | ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*)
176
176
Catches ::= ‘catch’ Expr
177
- PostfixExpr ::= InfixExpr [id]
177
+ PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
178
178
InfixExpr ::= PrefixExpr
179
- | InfixExpr id [nl] InfixExpr
180
- PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr
181
- SimpleExpr ::= ‘new’ Template
179
+ | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr)
180
+ PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op)
181
+ SimpleExpr ::= ‘new’ Template New(templ)
182
182
| BlockExpr
183
- | SimpleExpr1 [‘_’]
183
+ | SimpleExpr1 [‘_’] PostfixOp(expr, _)
184
184
SimpleExpr1 ::= Literal
185
185
| Path
186
186
| ‘_’
187
- | ‘(’ ExprsInParens ‘)’
188
- | SimpleExpr ‘.’ id
189
- | SimpleExpr (TypeArgs | NamedTypeArgs)
190
- | SimpleExpr1 ArgumentExprs
187
+ | ‘(’ ExprsInParens ‘)’ Parens(exprs)
188
+ | SimpleExpr ‘.’ id Select(expr, id)
189
+ | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args)
190
+ | SimpleExpr1 ArgumentExprs Apply(expr, args)
191
191
| XmlExpr
192
192
ExprsInParens ::= ExprInParens {‘,’ ExprInParens}
193
193
ExprInParens ::= PostfixExpr ‘:’ Type
194
194
| Expr
195
- ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’
196
- | ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’
195
+ ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ exprs
196
+ | ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar))
197
197
ArgumentExprs ::= ParArgumentExprs
198
198
| [nl] BlockExpr
199
- BlockExpr ::= ‘{’ CaseClauses ‘}’
200
- | ‘{’ Block ‘}’
201
- Block ::= {BlockStat semi} [BlockResult]
199
+ BlockExpr ::= ‘{’ CaseClauses ‘}’ Match(EmptyTree, cases)
200
+ | ‘{’ Block ‘}’ block // starts at {
201
+ Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?)
202
202
BlockStat ::= Import
203
203
| {Annotation} [‘implicit’ | ‘lazy’] Def
204
204
| {Annotation} {LocalModifier} TmplDef
205
205
| Expr1
206
206
207
- ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr
208
- | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr)
207
+ ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) ForYield(enums, expr)
208
+ {nl} [‘yield’] Expr
209
+ | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr)
209
210
Enumerators ::= Generator {semi Enumerator | Guard}
210
211
Enumerator ::= Generator
211
212
| Guard
212
- | Pattern1 ‘=’ Expr
213
- Generator ::= Pattern1 ‘<-’ Expr
213
+ | Pattern1 ‘=’ Expr GenAlias(pat, expr)
214
+ Generator ::= Pattern1 ‘<-’ Expr GenFrom(pat, expr)
214
215
Guard ::= ‘if’ PostfixExpr
215
216
216
- CaseClauses ::= CaseClause { CaseClause }
217
+ CaseClauses ::= CaseClause { CaseClause } CaseDef(pat, guard?, block) // block starts at =>
217
218
CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT)
218
- Pattern ::= Pattern1 { ‘|’ Pattern1 }
219
- Pattern1 ::= PatVar ‘:’ RefinedType
219
+
220
+ Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
221
+ Pattern1 ::= PatVar ‘:’ RefinedType Bind(name, Typed(Ident(wildcard), tpe))
220
222
| Pattern2
221
- Pattern2 ::= [varid ‘@’] InfixPattern
222
- InfixPattern ::= SimplePattern { id [nl] SimplePattern }
223
- SimplePattern ::= PatVar
224
- | Literal
225
- | ‘(’ [Patterns] ‘)’
223
+ Pattern2 ::= [varid ‘@’] InfixPattern Bind(name, pat)
224
+ InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat)
225
+ SimplePattern ::= PatVar Ident(wildcard)
226
+ | Literal Bind(name, Ident(wildcard))
227
+ | ‘(’ [Patterns] ‘)’ Parens(pats) Tuple(pats)
226
228
| XmlPattern
227
229
| SimplePattern1 [TypeArgs] [ArgumentPatterns]
228
230
SimplePattern1 ::= Path
@@ -231,15 +233,15 @@ SimplePattern1 ::= Path
231
233
PatVar ::= varid
232
234
| ‘_’
233
235
Patterns ::= Pattern {‘,’ Pattern}
234
- ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
236
+ ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats)
235
237
| ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ‘)’
236
238
```
237
239
238
240
### Type and Value Parameters
239
241
``` ebnf
240
242
ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
241
- ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’]
242
- id [HkTypeParamClause] TypeParamBounds
243
+ ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] TypeDef(Modifiers, name, tparams, bounds)
244
+ id [HkTypeParamClause] TypeParamBounds Bound(below, above, context)
243
245
244
246
DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
245
247
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
@@ -254,20 +256,21 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] |
254
256
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ ‘implicit’ ClsParams ‘)’]
255
257
ClsParamClause ::= [nl] ‘(’ [ClsParams] ‘)’
256
258
ClsParams ::= ClsParam {‘,’ ClsParam}
257
- ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
259
+ ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var
260
+ [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
258
261
Param ::= id ‘:’ ParamType [‘=’ Expr]
259
262
| INT
260
263
261
264
DefParamClauses ::= {DefParamClause} [[nl] ‘(’ ‘implicit’ DefParams ‘)’]
262
265
DefParamClause ::= [nl] ‘(’ [DefParams] ‘)’
263
266
DefParams ::= DefParam {‘,’ DefParam}
264
- DefParam ::= {Annotation} [‘inline’] Param
267
+ DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
265
268
```
266
269
267
270
### Bindings and Imports
268
271
``` ebnf
269
272
Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’
270
- Binding ::= (id | ‘_’) [‘:’ Type]
273
+ Binding ::= (id | ‘_’) [‘:’ Type] ValDef(_, id, tpe, EmptyTree)
271
274
272
275
Modifier ::= LocalModifier
273
276
| AccessModifier
@@ -280,20 +283,20 @@ LocalModifier ::= ‘abstract’
280
283
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
281
284
AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
282
285
283
- Annotation ::= ‘@’ SimpleType {ParArgumentExprs}
286
+ Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args)
284
287
285
- TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’
288
+ TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats)
286
289
TemplateStat ::= Import
287
290
| {Annotation [nl]} {Modifier} Def
288
291
| {Annotation [nl]} {Modifier} Dcl
289
292
| Expr1
290
- SelfType ::= id [‘:’ InfixType] ‘=>’
293
+ SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _)
291
294
| ‘this’ ‘:’ InfixType ‘=>’
292
295
293
296
Import ::= ‘import’ ImportExpr {‘,’ ImportExpr}
294
- ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors)
297
+ ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels)
295
298
ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’
296
- ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’]
299
+ ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] Ident(name), Pair(id, id)
297
300
```
298
301
299
302
### Declarations and Definitions
@@ -304,37 +307,38 @@ Dcl ::= ‘val’ ValDcl
304
307
| ‘type’ {nl} TypeDcl
305
308
| INT
306
309
307
- ValDcl ::= ids ‘:’ Type
308
- VarDcl ::= ids ‘:’ Type
309
- DefDcl ::= DefSig [‘:’ Type]
310
+ ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
311
+ VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
312
+ DefDcl ::= DefSig [‘:’ Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
310
313
DefSig ::= id [DefTypeParamClause] DefParamClauses
311
- TypeDcl ::= id [TypTypeParamClause] [‘=’ Type]
312
- | id [HkTypeParamClause] TypeBounds
314
+ TypeDcl ::= id [TypTypeParamClause] [‘=’ Type] TypeDefTree(_, name, tparams, tpt)
315
+ | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds)
313
316
314
317
Def ::= ‘val’ PatDef
315
318
| ‘var’ VarDef
316
319
| ‘def’ DefDef
317
320
| ‘type’ {nl} TypeDcl
318
321
| TmplDef
319
322
| INT
320
- PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr
323
+ PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr)
321
324
VarDef ::= PatDef
322
325
| ids ‘:’ Type ‘=’ ‘_’
323
- DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
324
- | DefSig [nl] ‘{’ Block ‘}’
325
- | ‘this’ DefParamClause DefParamClauses
326
+ DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
327
+ | DefSig [nl] ‘{’ Block ‘}’ DefDef(_, name, tparams, vparamss, tpe, Block)
328
+ | ‘this’ DefParamClause DefParamClauses DefDef(_, <init>, Nil, vparamss, EmptyTree, expr | Block)
326
329
(‘=’ ConstrExpr | [nl] ConstrBlock)
327
330
328
331
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
329
332
| [‘case’] ‘object’ ObjectDef
330
- ClassDef ::= id [ClsTypeParamClause] [ConstrMods] ClsParamClauses TemplateOpt
333
+ ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ)
334
+ [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, <init>, Nil, vparamss, EmptyTree, EmptyTree) as first stat
331
335
ConstrMods ::= AccessModifier
332
336
| Annotation {Annotation} (AccessModifier | ‘this’)
333
- ObjectDef ::= id TemplateOpt
337
+ ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor
334
338
TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody]
335
- Template ::= ConstrApps [TemplateBody] | TemplateBody
339
+ Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats)
336
340
ConstrApps ::= ConstrApp {‘with’ ConstrApp}
337
- ConstrApp ::= AnnotType {ArgumentExprs}
341
+ ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args)
338
342
ConstrExpr ::= SelfInvocation
339
343
| ConstrBlock
340
344
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}
@@ -345,8 +349,8 @@ TopStat ::= {Annotation [nl]} {Modifier} TmplDef
345
349
| Import
346
350
| Packaging
347
351
| PackageObject
348
- Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’
349
- PackageObject ::= ‘package’ ‘object’ ObjectDef
352
+ Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
353
+ PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods.
350
354
351
- CompilationUnit ::= {‘package’ QualId semi} TopStatSeq
355
+ CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats)
352
356
```
0 commit comments