@@ -105,7 +105,10 @@ semi ::= ‘;’ | nl {nl}
105
105
106
106
## Optional Braces
107
107
108
- The lexical analyzer also inserts ` indent ` and ` outdent ` tokens that represent regions of indented code [ at certain points] ( ./other-new-features/indentation.md ) .
108
+ The principle of optional braces is that any keyword that can be followed by ` { ` can also be followed by an indented block, without needing an intervening ` : ` .
109
+ (Allowing an optional ` : ` would be counterproductive since it would introduce several ways to do the same thing.)
110
+
111
+ The lexical analyzer inserts ` indent ` and ` outdent ` tokens that represent regions of indented code [ at certain points] ( ./other-new-features/indentation.md ) .
109
112
110
113
In the context-free productions below we use the notation ` <<< ts >>> `
111
114
to indicate a token sequence ` ts ` that is either enclosed in a pair of braces ` { ts } ` or that constitutes an indented region ` indent ts outdent ` . Analogously, the
@@ -249,6 +252,7 @@ Catches ::= ‘catch’ (Expr | ExprCaseClause)
249
252
PostfixExpr ::= InfixExpr [id] -- only if language.postfixOperators is enabled
250
253
InfixExpr ::= PrefixExpr
251
254
| InfixExpr id [nl] InfixExpr
255
+ | InfixExpr id ColonArgument
252
256
| InfixExpr MatchClause
253
257
MatchClause ::= ‘match’ <<< CaseClauses >>>
254
258
PrefixExpr ::= [PrefixOperator] SimpleExpr
@@ -267,6 +271,11 @@ SimpleExpr ::= SimpleRef
267
271
| SimpleExpr ‘.’ MatchClause
268
272
| SimpleExpr TypeArgs
269
273
| SimpleExpr ArgumentExprs
274
+ | SimpleExpr ColonArgument
275
+ ColonArgument ::= colon [LambdaStart]
276
+ indent (CaseClauses | Block) outdent
277
+ LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
278
+ | HkTypeParamClause ‘=>’
270
279
Quoted ::= ‘'’ ‘{’ Block ‘}’
271
280
| ‘'’ ‘[’ Type ‘]’
272
281
ExprSplice ::= spliceId -- if inside quoted block
@@ -306,7 +315,10 @@ TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
306
315
TypeCaseClause ::= ‘case’ (InfixType | ‘_’) ‘=>’ Type [semi]
307
316
308
317
Pattern ::= Pattern1 { ‘|’ Pattern1 }
309
- Pattern1 ::= Pattern2 [‘:’ RefinedType]
318
+ Pattern1 ::= PatVar ‘:’ RefinedType
319
+ | [‘-’] integerLiteral ‘:’ RefinedType
320
+ | [‘-’] floatingPointLiteral ‘:’ RefinedType
321
+ | Pattern2
310
322
Pattern2 ::= [id ‘@’] InfixPattern [‘*’]
311
323
InfixPattern ::= SimplePattern { id [nl] SimplePattern }
312
324
SimplePattern ::= PatVar
@@ -329,9 +341,6 @@ ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
329
341
ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
330
342
ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds
331
343
332
- DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
333
- DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
334
-
335
344
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
336
345
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
337
346
@@ -343,13 +352,20 @@ ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
343
352
| [nl] ‘(’ ‘using’ (ClsParams | FunArgTypes) ‘)’
344
353
ClsParams ::= ClsParam {‘,’ ClsParam}
345
354
ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
346
- Param ::= id ‘:’ ParamType [‘=’ Expr]
347
355
348
- DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
349
- DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause
350
- UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | FunArgTypes) ‘)’
351
- DefParams ::= DefParam {‘,’ DefParam}
352
- DefParam ::= {Annotation} [‘inline’] Param
356
+ TypelessClauses ::= TypelessClause {TypelessClause}
357
+ TypelessClause ::= DefTermParamClause
358
+ | UsingParamClause
359
+
360
+ DefTypeParamClause::= [nl] ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
361
+ DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
362
+ DefTermParamClause::= [nl] ‘(’ [DefTermParams] ‘)’
363
+ UsingParamClause ::= [nl] ‘(’ ‘using’ (DefTermParams | FunArgTypes) ‘)’
364
+ DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
365
+
366
+ DefTermParams ::= DefTermParam {‘,’ DefTermParam}
367
+ DefTermParam ::= {Annotation} [‘inline’] Param
368
+ Param ::= id ‘:’ ParamType [‘=’ Expr]
353
369
```
354
370
355
371
### Bindings and Imports
@@ -400,8 +416,8 @@ Dcl ::= RefineDcl
400
416
ValDcl ::= ids ‘:’ Type
401
417
VarDcl ::= ids ‘:’ Type
402
418
DefDcl ::= DefSig ‘:’ Type
403
- DefSig ::= id [DefTypeParamClause] DefParamClauses
404
- TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type]
419
+ DefSig ::= id [DefTypeParamClause] [TypelessClauses] [DefImplicitClause]
420
+ TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds
405
421
406
422
Def ::= ‘val’ PatDef
407
423
| ‘var’ PatDef
@@ -411,7 +427,7 @@ Def ::= ‘val’ PatDef
411
427
PatDef ::= ids [‘:’ Type] ‘=’ Expr
412
428
| Pattern2 [‘:’ Type] ‘=’ Expr
413
429
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
414
- | ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr
430
+ | ‘this’ TypelessClauses [DefImplicitClause] ‘=’ ConstrExpr
415
431
416
432
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
417
433
| [‘case’] ‘object’ ObjectDef
@@ -423,10 +439,10 @@ ConstrMods ::= {Annotation} [AccessModifier]
423
439
ObjectDef ::= id [Template]
424
440
EnumDef ::= id ClassConstr InheritClauses EnumBody
425
441
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
426
- GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause `, `UsingParamClause` must be present
442
+ GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause `, `UsingParamClause` must be present
427
443
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
428
444
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
429
- ‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods
445
+ ‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
430
446
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>
431
447
ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
432
448
| Export
0 commit comments