@@ -48,6 +48,13 @@ object Parsers {
48
48
val Class, Type, TypeParam, Def = Value
49
49
}
50
50
51
+ private implicit class AddDeco (val buf : ListBuffer [Tree ]) extends AnyVal {
52
+ def +++= (x : Tree ) = x match {
53
+ case x : Thicket => buf ++= x.trees
54
+ case x => buf += x
55
+ }
56
+ }
57
+
51
58
/** The parse starting point depends on whether the source file is self-contained:
52
59
* if not, the AST will be supplemented.
53
60
*/
@@ -2049,8 +2056,9 @@ object Parsers {
2049
2056
case CASEOBJECT =>
2050
2057
objectDef(start, posMods(start, mods | Case | Module ))
2051
2058
case ENUM =>
2052
- val mods1 = addMod(mods, atPos(in.skipToken()) { Mod .Enum () })
2053
- if (in.token == CLASS ) tmplDef(start, mods1) else enumDef(start, mods)
2059
+ val enumMod = atPos(in.skipToken()) { Mod .Enum () }
2060
+ if (in.token == CLASS ) tmplDef(start, addMod(mods, enumMod))
2061
+ else enumDef(start, mods, enumMod)
2054
2062
case _ =>
2055
2063
syntaxErrorOrIncomplete(" expected start of definition" )
2056
2064
EmptyTree
@@ -2103,20 +2111,29 @@ object Parsers {
2103
2111
/** id ClassConstr [`extends' [ConstrApps]]
2104
2112
* [nl] ‘{’ EnumCaseStats ‘}’
2105
2113
*/
2106
- def enumDef (start : Offset , mods : Modifiers ): EnumDef = atPos(start, nameStart) {
2107
- val name = ident().toTypeName
2108
- val constr = classConstr(name)
2114
+ def enumDef (start : Offset , mods : Modifiers , enumMod : Mod ): Thicket = {
2115
+ val point = nameStart
2116
+ val modName = ident()
2117
+ val clsName = modName.toTypeName
2118
+ val constr = classConstr(clsName)
2109
2119
val parents =
2110
2120
if (in.token == EXTENDS ) {
2111
2121
in.nextToken();
2112
2122
newLineOptWhenFollowedBy(LBRACE )
2113
2123
if (in.token == LBRACE ) Nil else tokenSeparated(WITH , constrApp)
2114
2124
}
2115
2125
else Nil
2126
+ val clsDef = atPos(start, point) {
2127
+ TypeDef (clsName, Template (constr, parents, EmptyValDef , Nil ))
2128
+ .withMods(addMod(mods, enumMod)).setComment(in.getDocComment(start))
2129
+ }
2116
2130
newLineOptWhenFollowedBy(LBRACE )
2117
- val body = inBraces(enumCaseStats)
2118
- EnumDef (name, Template (constr, Nil , EmptyValDef , body))
2119
- .withMods(mods).setComment(in.getDocComment(start)).asInstanceOf [EnumDef ]
2131
+ val modDef = atPos(in.offset) {
2132
+ val body = inBraces(enumCaseStats)
2133
+ ModuleDef (modName, Template (emptyConstructor, Nil , EmptyValDef , body))
2134
+ .withMods(mods)
2135
+ }
2136
+ Thicket (clsDef :: modDef :: Nil )
2120
2137
}
2121
2138
2122
2139
/** EnumCaseStats = EnumCaseStat {semi EnumCaseStat */
@@ -2237,7 +2254,7 @@ object Parsers {
2237
2254
else if (in.token == IMPORT )
2238
2255
stats ++= importClause()
2239
2256
else if (in.token == AT || isTemplateIntro || isModifier)
2240
- stats += tmplDef(in.offset, defAnnotsMods(modifierTokens))
2257
+ stats +++ = tmplDef(in.offset, defAnnotsMods(modifierTokens))
2241
2258
else if (! isStatSep) {
2242
2259
if (in.token == CASE )
2243
2260
syntaxErrorOrIncomplete(" only `case class` or `case object` allowed" )
@@ -2287,7 +2304,7 @@ object Parsers {
2287
2304
else if (isExprIntro)
2288
2305
stats += expr1()
2289
2306
else if (isDefIntro(modifierTokensOrCase))
2290
- stats += defOrDcl(in.offset, defAnnotsMods(modifierTokens))
2307
+ stats +++ = defOrDcl(in.offset, defAnnotsMods(modifierTokens))
2291
2308
else if (! isStatSep) {
2292
2309
exitOnError = mustStartStat
2293
2310
syntaxErrorOrIncomplete(" illegal start of definition" )
@@ -2345,9 +2362,9 @@ object Parsers {
2345
2362
val start = in.offset
2346
2363
val imods = implicitMods()
2347
2364
if (isBindingIntro) stats += implicitClosure(start, Location .InBlock , imods)
2348
- else stats += localDef(start, imods)
2365
+ else stats +++ = localDef(start, imods)
2349
2366
} else {
2350
- stats += localDef(in.offset)
2367
+ stats +++ = localDef(in.offset)
2351
2368
}
2352
2369
else if (! isStatSep && (in.token != CASE )) {
2353
2370
exitOnError = mustStartStat
0 commit comments