@@ -130,6 +130,23 @@ object Parsers {
130130 ctx.error(msg, source atPos pos)
131131 }
132132
133+ trait OutlineParserCommon extends ParserCommon {
134+ def accept (token : Int ): Int
135+
136+ def skipBracesHook (): Option [Tree ]
137+ def skipBraces (): Unit = {
138+ accept(LBRACE )
139+ var openBraces = 1
140+ while (in.token != EOF && openBraces > 0 ) {
141+ skipBracesHook() getOrElse {
142+ if (in.token == LBRACE ) openBraces += 1
143+ else if (in.token == RBRACE ) openBraces -= 1
144+ in.nextToken()
145+ }
146+ }
147+ }
148+ }
149+
133150 class Parser (source : SourceFile )(implicit ctx : Context ) extends ParserCommon (source) {
134151
135152 val in : Scanner = new Scanner (source)
@@ -2641,20 +2658,10 @@ object Parsers {
26412658 /** OutlineParser parses top-level declarations in `source` to find declared classes, ignoring their bodies (which
26422659 * must only have balanced braces). This is used to map class names to defining sources.
26432660 */
2644- class OutlineParser (source : SourceFile )(implicit ctx : Context ) extends Parser (source) {
2661+ class OutlineParser (source : SourceFile )(implicit ctx : Context ) extends Parser (source) with OutlineParserCommon {
26452662
2646- def skipBraces (): Unit = {
2647- accept(LBRACE )
2648- var openBraces = 1
2649- while (in.token != EOF && openBraces > 0 ) {
2650- if (in.token == XMLSTART ) xmlLiteral()
2651- else {
2652- if (in.token == LBRACE ) openBraces += 1
2653- else if (in.token == RBRACE ) openBraces -= 1
2654- in.nextToken()
2655- }
2656- }
2657- }
2663+ def skipBracesHook (): Option [Tree ] =
2664+ if (in.token == XMLSTART ) Some (xmlLiteral()) else None
26582665
26592666 override def blockExpr (): Tree = {
26602667 skipBraces()
@@ -2663,7 +2670,7 @@ object Parsers {
26632670
26642671 override def templateBody () = {
26652672 skipBraces()
2666- (EmptyValDef , List (EmptyTree )))
2673+ (EmptyValDef , List (EmptyTree ))
26672674 }
26682675 }
26692676}
0 commit comments