Skip to content

Commit 116c1c0

Browse files
committed
Adapt grammar
Adapt grammar to use `:` instead of `with` to start a template. Also, update to new syntax of extension definitions.
1 parent 117b9de commit 116c1c0

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ object Parsers {
14691469
def infixTypeRest(t: Tree): Tree =
14701470
infixOps(t, canStartTypeTokens, refinedType, isType = true, isOperator = !isPostfixStar)
14711471

1472-
/** RefinedType ::= WithType {[nl | `with'] Refinement}
1472+
/** RefinedType ::= WithType {[nl] Refinement}
14731473
*/
14741474
val refinedType: () => Tree = () => refinedTypeRest(withType())
14751475

@@ -2093,7 +2093,8 @@ object Parsers {
20932093
}
20942094
else simpleExpr()
20952095

2096-
/** SimpleExpr ::= ‘new’ (ConstrApp [[‘with’] TemplateBody] | TemplateBody)
2096+
/** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
2097+
* | ‘new’ TemplateBody
20972098
* | BlockExpr
20982099
* | ‘$’ ‘{’ Block ‘}’
20992100
* | Quoted
@@ -2188,7 +2189,7 @@ object Parsers {
21882189
}
21892190
}
21902191

2191-
/** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [[‘with’] TemplateBody]
2192+
/** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
21922193
* | ‘new’ TemplateBody
21932194
*/
21942195
def newExpr(): Tree =
@@ -3363,7 +3364,7 @@ object Parsers {
33633364
syntaxError(s"Only access modifiers are allowed on enum $where")
33643365
mods1
33653366

3366-
/** EnumDef ::= id ClassConstr InheritClauses [‘with’] EnumBody
3367+
/** EnumDef ::= id ClassConstr InheritClauses EnumBody
33673368
*/
33683369
def enumDef(start: Offset, mods: Modifiers): TypeDef = atSpan(start, nameStart) {
33693370
val mods1 = checkAccessOnly(mods, "definitions")
@@ -3426,8 +3427,7 @@ object Parsers {
34263427
}
34273428

34283429
/** GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} AnnotType ‘=’ Expr
3429-
* | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [‘:’ nl | ‘with’] TemplateBody]
3430-
* | [id ‘:’] ExtParamClause {GivenParamClause} ‘extended’ ‘with’ ExtMethods
3430+
* | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [TemplateBody]
34313431
* GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
34323432
* ExtParamClause ::= [DefTypeParamClause] DefParamClause
34333433
* ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
@@ -3530,7 +3530,7 @@ object Parsers {
35303530
finalizeDef(gdef, mods1, start)
35313531
}
35323532

3533-
/** ExtensionDef ::= [id] ‘of’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
3533+
/** ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ExtMethods
35343534
*/
35353535
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
35363536
in.nextToken()
@@ -3576,7 +3576,7 @@ object Parsers {
35763576
else Nil
35773577
t :: ts
35783578

3579-
/** Template ::= InheritClauses [[‘with’] TemplateBody]
3579+
/** Template ::= InheritClauses [TemplateBody]
35803580
* InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
35813581
*/
35823582
def template(constr: DefDef, isEnum: Boolean = false): Template = {
@@ -3646,7 +3646,7 @@ object Parsers {
36463646
case x: RefTree => atSpan(start, pointOffset(pkg))(PackageDef(x, stats))
36473647
}
36483648

3649-
/** Packaging ::= package QualId [nl | `with'] `{' TopStatSeq `}'
3649+
/** Packaging ::= package QualId [nl] `{' TopStatSeq `}'
36503650
*/
36513651
def packaging(start: Int): Tree = {
36523652
val pkg = qualId()

docs/docs/internals/syntax.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ FunArgTypes ::= InfixType
149149
TypedFunParam ::= id ‘:’ Type
150150
MatchType ::= InfixType `match` ‘{’ TypeCaseClauses ‘}’
151151
InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
152-
RefinedType ::= WithType {[nl | ‘with’] Refinement} RefinedTypeTree(t, ds)
152+
RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds)
153153
WithType ::= AnnotType {‘with’ AnnotType} (deprecated)
154154
AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
155155
SimpleType ::= SimpleType TypeArgs AppliedTypeTree(t, args)
@@ -214,7 +214,7 @@ SimpleExpr ::= Path
214214
| ‘$’ ‘{’ Block ‘}’
215215
| Quoted
216216
| quoteId // only inside splices
217-
| ‘new’ ConstrApp {‘with’ ConstrApp} [[‘with’] TemplateBody] New(constr | templ)
217+
| ‘new’ ConstrApp {‘with’ ConstrApp} [TemplateBody] New(constr | templ)
218218
| ‘new’ TemplateBody
219219
| ‘(’ ExprsInParens ‘)’ Parens(exprs)
220220
| SimpleExpr ‘.’ id Select(expr, id)
@@ -383,16 +383,16 @@ ClassDef ::= id ClassConstr [Template]
383383
ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, <init>, Nil, vparamss, EmptyTree, EmptyTree) as first stat
384384
ConstrMods ::= {Annotation} [AccessModifier]
385385
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
386-
EnumDef ::= id ClassConstr InheritClauses [‘with’] EnumBody EnumDef(mods, name, tparams, template)
386+
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
387387
GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’}
388388
AnnotType ‘=’ Expr
389389
| [GivenSig ‘:’] {FunArgTypes ‘=>’}
390-
ConstrApps [[‘with’] TemplateBody]
390+
ConstrApps [TemplateBody]
391391
GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
392-
ExtensionDef ::= [id] ‘of’ ExtParamClause {GivenParamClause} ExtMethods
392+
ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ExtMethods
393393
ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
394394
ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’
395-
Template ::= InheritClauses [[‘with’] TemplateBody] Template(constr, parents, self, stats)
395+
Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats)
396396
InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
397397
ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp}
398398
ConstrApp ::= AnnotType {ParArgumentExprs} Apply(tp, args)
@@ -410,7 +410,7 @@ TemplateStat ::= Import
410410
SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _)
411411
| ‘this’ ‘:’ InfixType ‘=>’
412412
413-
EnumBody ::= [nl | ‘with’] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’
413+
EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’
414414
EnumStat ::= TemplateStat
415415
| {Annotation [nl]} {Modifier} EnumCase
416416
EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids)
@@ -422,7 +422,7 @@ TopStat ::= Import
422422
| Packaging
423423
| PackageObject
424424
|
425-
Packaging ::= ‘package’ QualId [nl | ‘with’] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
425+
Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
426426
PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods.
427427
428428
CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats)

0 commit comments

Comments
 (0)