Skip to content

Commit bf9bf1c

Browse files
committed
Update syntax.md
The new syntax allows arbitrary interweaving of type and term clauses for methods TypelessClause{|s} is added for class constructors since they still don't allow interweaving of type parameters Also unifies the affected grammar variable names so that <x>s means "one or more <x>" Implicit clauses are moved apart from term clause to make it more obvious they can only be the last clause
1 parent 2f16da6 commit bf9bf1c

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

docs/docs/internals/syntax.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
319319
ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] TypeDef(Modifiers, name, tparams, bounds)
320320
id [HkTypeParamClause] TypeParamBounds Bound(below, above, context)
321321
322-
DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
323-
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
324-
325322
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
326323
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
327324
@@ -335,13 +332,24 @@ ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
335332
ClsParams ::= ClsParam {‘,’ ClsParam}
336333
ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var
337334
[{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
338-
Param ::= id ‘:’ ParamType [‘=’ Expr]
339335
340-
DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
341-
DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause
342-
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | FunArgTypes) ‘)’
343-
DefParams ::= DefParam {‘,’ DefParam}
344-
DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
336+
DefParamClauses ::= DefParamClause { DefParamClause }
337+
DefParamClause ::= DefTypeParamClause
338+
| DefTermParamClause
339+
| UsingParamClause
340+
TypelessClauses ::= TypelessClause {TypelessClause}
341+
TypelessClause ::= DefTermParamClause
342+
| UsingParamClause
343+
344+
DefTypeParamClause::= [nl] ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
345+
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
346+
DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
347+
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefTermParams | FunArgTypes) ‘)’
348+
DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
349+
350+
DefTermParams ::= DefTermParam {‘,’ DefTermParam}
351+
DefTermParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
352+
Param ::= id ‘:’ ParamType [‘=’ Expr]
345353
```
346354

347355
### Bindings and Imports
@@ -392,7 +400,7 @@ Dcl ::= RefineDcl
392400
ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
393401
VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
394402
DefDcl ::= DefSig ‘:’ Type DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
395-
DefSig ::= id [DefTypeParamClause] DefParamClauses
403+
DefSig ::= id [DefParamClauses] [DefImplicitClause]
396404
TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds TypeDefTree(_, name, tparams, bound
397405
[‘=’ Type]
398406
@@ -403,8 +411,8 @@ Def ::= ‘val’ PatDef
403411
| TmplDef
404412
PatDef ::= ids [‘:’ Type] ‘=’ Expr
405413
| Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr)
406-
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr)
407-
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr DefDef(_, <init>, Nil, vparamss, EmptyTree, expr | Block)
414+
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, paramss, tpe, expr)
415+
| ‘this’ TypelessClauses [DefImplicitClause] ‘=’ ConstrExpr DefDef(_, <init>, vparamss, EmptyTree, expr | Block)
408416
409417
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
410418
| [‘case’] ‘object’ ObjectDef
@@ -416,10 +424,10 @@ ConstrMods ::= {Annotation} [AccessModifier]
416424
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
417425
EnumDef ::= id ClassConstr InheritClauses EnumBody
418426
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
419-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present
427+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
420428
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody]
421429
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
422-
‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods
430+
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
423431
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>
424432
ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
425433
Template ::= InheritClauses [TemplateBody]

docs/docs/reference/syntax.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
310310
ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
311311
ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds
312312
313-
DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
314-
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
315-
316313
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
317314
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
318315
@@ -324,13 +321,24 @@ ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
324321
| [nl] ‘(’ ‘using’ (ClsParams | FunArgTypes) ‘)’
325322
ClsParams ::= ClsParam {‘,’ ClsParam}
326323
ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
327-
Param ::= id ‘:’ ParamType [‘=’ Expr]
328324
329-
DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
330-
DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause
331-
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | FunArgTypes) ‘)’
332-
DefParams ::= DefParam {‘,’ DefParam}
333-
DefParam ::= {Annotation} [‘inline’] Param
325+
DefParamClauses ::= DefParamClause { DefParamClause }
326+
DefParamClause ::= DefTypeParamClause
327+
| DefTermParamClause
328+
| UsingParamClause
329+
TypelessClauses ::= TypelessClause {TypelessClause}
330+
TypelessClause ::= DefTermParamClause
331+
| UsingParamClause
332+
333+
DefTypeParamClause::= [nl] ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
334+
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
335+
DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
336+
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefTermParams | FunArgTypes) ‘)’
337+
DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
338+
339+
DefTermParams ::= DefTermParam {‘,’ DefTermParam}
340+
DefTermParam ::= {Annotation} [‘inline’] Param
341+
Param ::= id ‘:’ ParamType [‘=’ Expr]
334342
```
335343

336344
### Bindings and Imports
@@ -381,8 +389,8 @@ Dcl ::= RefineDcl
381389
ValDcl ::= ids ‘:’ Type
382390
VarDcl ::= ids ‘:’ Type
383391
DefDcl ::= DefSig ‘:’ Type
384-
DefSig ::= id [DefTypeParamClause] DefParamClauses
385-
TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type]
392+
DefSig ::= id [DefParamClauses] [DefImplicitClause]
393+
TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds
386394
387395
Def ::= ‘val’ PatDef
388396
| ‘var’ PatDef
@@ -392,7 +400,7 @@ Def ::= ‘val’ PatDef
392400
PatDef ::= ids [‘:’ Type] ‘=’ Expr
393401
| Pattern2 [‘:’ Type] ‘=’ Expr
394402
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
395-
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr
403+
| ‘this’ TypelessClauses [DefImplicitClause] ‘=’ ConstrExpr
396404
397405
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
398406
| [‘case’] ‘object’ ObjectDef
@@ -404,10 +412,10 @@ ConstrMods ::= {Annotation} [AccessModifier]
404412
ObjectDef ::= id [Template]
405413
EnumDef ::= id ClassConstr InheritClauses EnumBody
406414
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
407-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present
415+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
408416
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody]
409417
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
410-
‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods
418+
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
411419
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>
412420
ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
413421
Template ::= InheritClauses [TemplateBody]

0 commit comments

Comments
 (0)