From 669c5a8ed52f77942ee1ed7cf5813451d3762579 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 5 Feb 2017 15:55:44 +1100 Subject: Add enum syntax Modify syntax.md and Tokens/Parser/untpd to support enums. --- docs/docs/internals/syntax.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 7f06cdc2a..804a0f57a 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -289,7 +289,9 @@ TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} TemplateStat ::= Import | {Annotation [nl]} {Modifier} Def | {Annotation [nl]} {Modifier} Dcl + | EnumCaseStat | Expr1 + | SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _) | ‘this’ ‘:’ InfixType ‘=>’ @@ -328,13 +330,20 @@ DefDef ::= DefSig [‘:’ Type] ‘=’ Expr | ‘this’ DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) (‘=’ ConstrExpr | [nl] ConstrBlock) -TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef - | [‘case’] ‘object’ ObjectDef -ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) - [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat +TmplDef ::= ([‘case’ | `enum'] ‘class’ | [`enum'] trait’) ClassDef + | [‘case’ | `enum'] ‘object’ ObjectDef + | `enum' EnumDef +ClassDef ::= id ClassConstr TemplateOpt ClassDef(mods, name, tparams, templ) +ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat ConstrMods ::= AccessModifier | Annotation {Annotation} (AccessModifier | ‘this’) ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor +EnumDef ::= id ClassConstr [`extends' [ConstrApps]] EnumDef(mods, name, tparams, template) + [nl] ‘{’ EnumCaseStat {semi EnumCaseStat ‘}’ +EnumCaseStat ::= {Annotation [nl]} {Modifier} EnumCase +EnumCase ::= `case' (EnumClassDef | ObjectDef) +EnumClassDef ::= id [ClsTpeParamClause | ClsParamClause] ClassDef(mods, name, tparams, templ) + ClsParamClauses TemplateOpt TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody] Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) ConstrApps ::= ConstrApp {‘with’ ConstrApp} -- cgit v1.2.3