Skip to content

Commit 403ffc2

Browse files
committed
Add tree annotations back in
1 parent b004e6c commit 403ffc2

File tree

1 file changed

+92
-88
lines changed

1 file changed

+92
-88
lines changed

docs/docs/internals/syntax.md

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -117,112 +117,114 @@ ClassQualifier ::= ‘[’ id ‘]’
117117

118118
### Types
119119
```ebnf
120-
Type ::= [‘implicit’] FunArgTypes ‘=>’ Type
121-
| HkTypeParamClause ‘=>’ Type
120+
Type ::= [‘implicit’] FunArgTypes ‘=>’ Type Function(ts, t)
121+
| HkTypeParamClause ‘=>’ Type TypeLambda(ps, t)
122122
| InfixType
123123
FunArgTypes ::= InfixType
124124
| ‘(’ [ 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)
131131
| StableId
132-
| Path ‘.’ ‘type’
133-
| ‘(’ ArgTypes ‘)’
132+
| Path ‘.’ ‘type’ SingletonTypeTree(p)
133+
| ‘(’ ArgTypes ‘)’ Tuple(ts)
134134
| ‘_’ TypeBounds
135-
| Refinement
136-
| SimpleLiteral
135+
| Refinement RefinedTypeTree(EmptyTree, refinement)
136+
| SimpleLiteral SingletonTypeTree(l)
137137
ArgTypes ::= Type {‘,’ Type}
138138
| NamedTypeArg {‘,’ NamedTypeArg}
139139
FunArgType ::= Type
140-
| ‘=>’ Type
140+
| ‘=>’ Type PrefixOp(=>, t)
141141
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)
149149
```
150150

151151
### Expressions
152152
```ebnf
153-
Expr ::= [‘implicit’] FunParams ‘=>’ Expr
153+
Expr ::= [‘implicit’] FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr)
154154
| Expr1
155155
BlockResult ::= [‘implicit’] FunParams ‘=>’ Block
156156
| Expr1
157157
FunParams ::= Bindings
158158
| id
159159
| ‘_’
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?)
169169
| ForExpr
170-
| [SimpleExpr ‘.’] id ‘=’ Expr
171-
| SimpleExpr1 ArgumentExprs ‘=’ Expr
170+
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
171+
| SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
172172
| 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)*)
176176
Catches ::= ‘catch’ Expr
177-
PostfixExpr ::= InfixExpr [id]
177+
PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
178178
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)
182182
| BlockExpr
183-
| SimpleExpr1 [‘_’]
183+
| SimpleExpr1 [‘_’] PostfixOp(expr, _)
184184
SimpleExpr1 ::= Literal
185185
| Path
186186
| ‘_’
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)
191191
| XmlExpr
192192
ExprsInParens ::= ExprInParens {‘,’ ExprInParens}
193193
ExprInParens ::= PostfixExpr ‘:’ Type
194194
| Expr
195-
ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’
196-
| ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’
195+
ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ exprs
196+
| ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar))
197197
ArgumentExprs ::= ParArgumentExprs
198198
| [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?)
202202
BlockStat ::= Import
203203
| {Annotation} [‘implicit’ | ‘lazy’] Def
204204
| {Annotation} {LocalModifier} TmplDef
205205
| Expr1
206206
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)
209210
Enumerators ::= Generator {semi Enumerator | Guard}
210211
Enumerator ::= Generator
211212
| Guard
212-
| Pattern1 ‘=’ Expr
213-
Generator ::= Pattern1 ‘<-’ Expr
213+
| Pattern1 ‘=’ Expr GenAlias(pat, expr)
214+
Generator ::= Pattern1 ‘<-’ Expr GenFrom(pat, expr)
214215
Guard ::= ‘if’ PostfixExpr
215216
216-
CaseClauses ::= CaseClause { CaseClause }
217+
CaseClauses ::= CaseClause { CaseClause } CaseDef(pat, guard?, block) // block starts at =>
217218
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))
220222
| 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)
226228
| XmlPattern
227229
| SimplePattern1 [TypeArgs] [ArgumentPatterns]
228230
SimplePattern1 ::= Path
@@ -231,15 +233,15 @@ SimplePattern1 ::= Path
231233
PatVar ::= varid
232234
| ‘_’
233235
Patterns ::= Pattern {‘,’ Pattern}
234-
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
236+
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats)
235237
| ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ‘)’
236238
```
237239

238240
### Type and Value Parameters
239241
```ebnf
240242
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)
243245
244246
DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
245247
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
@@ -254,20 +256,21 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] |
254256
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ ‘implicit’ ClsParams ‘)’]
255257
ClsParamClause ::= [nl] ‘(’ [ClsParams] ‘)’
256258
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
258261
Param ::= id ‘:’ ParamType [‘=’ Expr]
259262
| INT
260263
261264
DefParamClauses ::= {DefParamClause} [[nl] ‘(’ ‘implicit’ DefParams ‘)’]
262265
DefParamClause ::= [nl] ‘(’ [DefParams] ‘)’
263266
DefParams ::= DefParam {‘,’ DefParam}
264-
DefParam ::= {Annotation} [‘inline’] Param
267+
DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
265268
```
266269

267270
### Bindings and Imports
268271
```ebnf
269272
Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’
270-
Binding ::= (id | ‘_’) [‘:’ Type]
273+
Binding ::= (id | ‘_’) [‘:’ Type] ValDef(_, id, tpe, EmptyTree)
271274
272275
Modifier ::= LocalModifier
273276
| AccessModifier
@@ -280,20 +283,20 @@ LocalModifier ::= ‘abstract’
280283
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
281284
AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
282285
283-
Annotation ::= ‘@’ SimpleType {ParArgumentExprs}
286+
Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args)
284287
285-
TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’
288+
TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats)
286289
TemplateStat ::= Import
287290
| {Annotation [nl]} {Modifier} Def
288291
| {Annotation [nl]} {Modifier} Dcl
289292
| Expr1
290-
SelfType ::= id [‘:’ InfixType] ‘=>’
293+
SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _)
291294
| ‘this’ ‘:’ InfixType ‘=>’
292295
293296
Import ::= ‘import’ ImportExpr {‘,’ ImportExpr}
294-
ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors)
297+
ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels)
295298
ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’
296-
ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’]
299+
ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] Ident(name), Pair(id, id)
297300
```
298301

299302
### Declarations and Definitions
@@ -304,37 +307,38 @@ Dcl ::= ‘val’ ValDcl
304307
| ‘type’ {nl} TypeDcl
305308
| INT
306309
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)
310313
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)
313316
314317
Def ::= ‘val’ PatDef
315318
| ‘var’ VarDef
316319
| ‘def’ DefDef
317320
| ‘type’ {nl} TypeDcl
318321
| TmplDef
319322
| INT
320-
PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr
323+
PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr)
321324
VarDef ::= PatDef
322325
| 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)
326329
(‘=’ ConstrExpr | [nl] ConstrBlock)
327330
328331
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
329332
| [‘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
331335
ConstrMods ::= AccessModifier
332336
| Annotation {Annotation} (AccessModifier | ‘this’)
333-
ObjectDef ::= id TemplateOpt
337+
ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor
334338
TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody]
335-
Template ::= ConstrApps [TemplateBody] | TemplateBody
339+
Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats)
336340
ConstrApps ::= ConstrApp {‘with’ ConstrApp}
337-
ConstrApp ::= AnnotType {ArgumentExprs}
341+
ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args)
338342
ConstrExpr ::= SelfInvocation
339343
| ConstrBlock
340344
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}
@@ -345,8 +349,8 @@ TopStat ::= {Annotation [nl]} {Modifier} TmplDef
345349
| Import
346350
| Packaging
347351
| 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.
350354
351-
CompilationUnit ::= {‘package’ QualId semi} TopStatSeq
355+
CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats)
352356
```

0 commit comments

Comments
 (0)