aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/SyntaxSummary.txt13
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala24
2 files changed, 21 insertions, 16 deletions
diff --git a/docs/SyntaxSummary.txt b/docs/SyntaxSummary.txt
index e40b3fd6c..dadf15bed 100644
--- a/docs/SyntaxSummary.txt
+++ b/docs/SyntaxSummary.txt
@@ -99,8 +99,9 @@ grammar.
FunArgTypes ::= InfixType
| `(' [ FunArgType {`,' FunArgType } ] `)'
InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
- RefinedType ::= WithType {Annotation | [nl] Refinement} Annotated(t, annot), RefinedTypeTree(t, ds)
- WithType ::= SimpleType {`with' SimpleType} (deprecated)
+ RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds)
+ WithType ::= AnnotType {`with' AnnotType} (deprecated)
+ AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
SimpleType ::= SimpleType TypeArgs AppliedTypeTree(t, args)
| SimpleType `#' id SelectFromTypeTree(t, name)
| StableId
@@ -121,9 +122,9 @@ grammar.
Expr ::= FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr)
| Expr1
- FunParams ::= Bindings
- | [`implicit'] id
- | `_'
+ FunParams ::= Bindings
+ | [`implicit'] id
+ | `_'
ExprInParens ::= PostfixExpr `:' Type
| Expr
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) => Block
@@ -301,7 +302,7 @@ grammar.
TemplateOpt ::= [`extends' Template | [nl] TemplateBody]
Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats)
ConstrApps ::= ConstrApp {`with' ConstrApp}
- ConstrApp ::= SimpleType {ArgumentExprs} Apply(tp, args)
+ ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args)
ConstrExpr ::= SelfInvocation
| ConstrBlock
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index dd2c9bcaa..dbf57c22e 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -679,25 +679,29 @@ object Parsers {
def refinedTypeRest(t: Tree): Tree = {
newLineOptWhenFollowedBy(LBRACE)
- in.token match {
- case AT => refinedTypeRest(atPos(t.pos.start) { Annotated(annot(), t) })
- case LBRACE => refinedTypeRest(atPos(t.pos.start) { RefinedTypeTree(t, refinement()) })
- case _ => t
- }
+ if (in.token == LBRACE) refinedTypeRest(atPos(t.pos.start) { RefinedTypeTree(t, refinement()) })
+ else t
}
- /** WithType ::= SimpleType {`with' SimpleType} (deprecated)
+ /** WithType ::= AnnotType {`with' AnnotType} (deprecated)
*/
- def withType(): Tree = withTypeRest(simpleType())
+ def withType(): Tree = withTypeRest(annotType())
- def withTypeRest(t: Tree): Tree = {
+ def withTypeRest(t: Tree): Tree =
if (in.token == WITH) {
deprecationWarning("`with' as a type operator has been deprecated; use `&' instead")
in.nextToken()
AndTypeTree(t, withType())
}
else t
- }
+
+ /** AnnotType ::= SimpleType {Annotation}
+ */
+ def annotType(): Tree = annotTypeRest(simpleType())
+
+ def annotTypeRest(t: Tree): Tree =
+ if (in.token == AT) annotTypeRest(atPos(t.pos.start) { Annotated(annot(), t) })
+ else t
/** SimpleType ::= SimpleType TypeArgs
* | SimpleType `#' Id
@@ -1834,7 +1838,7 @@ object Parsers {
/** ConstrApp ::= SimpleType {ParArgumentExprs}
*/
val constrApp = () => {
- val t = simpleType()
+ val t = annotType()
if (in.token == LPAREN) parArgumentExprss(wrapNew(t))
else t
}