Skip to content

Commit e5b4115

Browse files
smartersjrd
authored andcommitted
Synchronize {reference,TODOreference}/syntax.md
1 parent 757d01d commit e5b4115

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

docs/_spec/TODOreference/syntax.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ semi ::= ‘;’ | nl {nl}
105105

106106
## Optional Braces
107107

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).
109112

110113
In the context-free productions below we use the notation `<<< ts >>>`
111114
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)
249252
PostfixExpr ::= InfixExpr [id] -- only if language.postfixOperators is enabled
250253
InfixExpr ::= PrefixExpr
251254
| InfixExpr id [nl] InfixExpr
255+
| InfixExpr id ColonArgument
252256
| InfixExpr MatchClause
253257
MatchClause ::= ‘match’ <<< CaseClauses >>>
254258
PrefixExpr ::= [PrefixOperator] SimpleExpr
@@ -267,6 +271,11 @@ SimpleExpr ::= SimpleRef
267271
| SimpleExpr ‘.’ MatchClause
268272
| SimpleExpr TypeArgs
269273
| SimpleExpr ArgumentExprs
274+
| SimpleExpr ColonArgument
275+
ColonArgument ::= colon [LambdaStart]
276+
indent (CaseClauses | Block) outdent
277+
LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
278+
| HkTypeParamClause ‘=>’
270279
Quoted ::= ‘'’ ‘{’ Block ‘}’
271280
| ‘'’ ‘[’ Type ‘]’
272281
ExprSplice ::= spliceId -- if inside quoted block
@@ -306,7 +315,10 @@ TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
306315
TypeCaseClause ::= ‘case’ (InfixType | ‘_’) ‘=>’ Type [semi]
307316
308317
Pattern ::= Pattern1 { ‘|’ Pattern1 }
309-
Pattern1 ::= Pattern2 [‘:’ RefinedType]
318+
Pattern1 ::= PatVar ‘:’ RefinedType
319+
| [‘-’] integerLiteral ‘:’ RefinedType
320+
| [‘-’] floatingPointLiteral ‘:’ RefinedType
321+
| Pattern2
310322
Pattern2 ::= [id ‘@’] InfixPattern [‘*’]
311323
InfixPattern ::= SimplePattern { id [nl] SimplePattern }
312324
SimplePattern ::= PatVar
@@ -329,9 +341,6 @@ ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
329341
ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
330342
ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds
331343
332-
DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
333-
DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
334-
335344
TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
336345
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
337346
@@ -343,13 +352,20 @@ ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
343352
| [nl] ‘(’ ‘using’ (ClsParams | FunArgTypes) ‘)’
344353
ClsParams ::= ClsParam {‘,’ ClsParam}
345354
ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
346-
Param ::= id ‘:’ ParamType [‘=’ Expr]
347355
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]
353369
```
354370

355371
### Bindings and Imports
@@ -400,8 +416,8 @@ Dcl ::= RefineDcl
400416
ValDcl ::= ids ‘:’ Type
401417
VarDcl ::= ids ‘:’ Type
402418
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
405421
406422
Def ::= ‘val’ PatDef
407423
| ‘var’ PatDef
@@ -411,7 +427,7 @@ Def ::= ‘val’ PatDef
411427
PatDef ::= ids [‘:’ Type] ‘=’ Expr
412428
| Pattern2 [‘:’ Type] ‘=’ Expr
413429
DefDef ::= DefSig [‘:’ Type] ‘=’ Expr
414-
| ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr
430+
| ‘this’ TypelessClauses [DefImplicitClause] ‘=’ ConstrExpr
415431
416432
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
417433
| [‘case’] ‘object’ ObjectDef
@@ -423,10 +439,10 @@ ConstrMods ::= {Annotation} [AccessModifier]
423439
ObjectDef ::= id [Template]
424440
EnumDef ::= id ClassConstr InheritClauses EnumBody
425441
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
427443
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
428444
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
429-
‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods
445+
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods
430446
ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>>
431447
ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef
432448
| Export

0 commit comments

Comments
 (0)