@@ -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)
@@ -2638,24 +2655,22 @@ object Parsers {
26382655 }
26392656
26402657
2641- class OutlineParser (source : SourceFile )(implicit ctx : Context ) extends Parser (source) {
2658+ /** OutlineParser parses top-level declarations in `source` to find declared classes, ignoring their bodies (which
2659+ * must only have balanced braces). This is used to map class names to defining sources.
2660+ */
2661+ class OutlineParser (source : SourceFile )(implicit ctx : Context ) extends Parser (source) with OutlineParserCommon {
26422662
2643- def skipBraces [T ](body : T ): T = {
2644- accept(LBRACE )
2645- var openBraces = 1
2646- while (in.token != EOF && openBraces > 0 ) {
2647- if (in.token == XMLSTART ) xmlLiteral()
2648- else {
2649- if (in.token == LBRACE ) openBraces += 1
2650- else if (in.token == RBRACE ) openBraces -= 1
2651- in.nextToken()
2652- }
2653- }
2654- body
2655- }
2663+ def skipBracesHook (): Option [Tree ] =
2664+ if (in.token == XMLSTART ) Some (xmlLiteral()) else None
26562665
2657- override def blockExpr (): Tree = skipBraces(EmptyTree )
2666+ override def blockExpr (): Tree = {
2667+ skipBraces()
2668+ EmptyTree
2669+ }
26582670
2659- override def templateBody () = skipBraces((EmptyValDef , List (EmptyTree )))
2671+ override def templateBody () = {
2672+ skipBraces()
2673+ (EmptyValDef , List (EmptyTree ))
2674+ }
26602675 }
26612676}
0 commit comments