@@ -38,14 +38,6 @@ object Parsers {
3838
3939 case class OpInfo (operand : Tree , operator : Ident , offset : Offset )
4040
41- class ParensCounters {
42- private var parCounts = new Array [Int ](lastParen - firstParen)
43-
44- def count (tok : Token ): Int = parCounts(tok - firstParen)
45- def change (tok : Token , delta : Int ): Unit = parCounts(tok - firstParen) += delta
46- def nonePositive : Boolean = parCounts forall (_ <= 0 )
47- }
48-
4941 enum Location (val inParens : Boolean , val inPattern : Boolean , val inArgs : Boolean ):
5042 case InParens extends Location (true , false , false )
5143 case InArgs extends Location (true , false , true )
@@ -174,8 +166,6 @@ object Parsers {
174166
175167 val in : Scanner = new Scanner (source)
176168
177- val openParens : ParensCounters = new ParensCounters
178-
179169 /** This is the general parse entry point.
180170 * Overridden by ScriptParser
181171 */
@@ -262,55 +252,14 @@ object Parsers {
262252 }
263253
264254 /** Skip on error to next safe point.
265- * Safe points are:
266- * - Closing braces, provided they match an opening brace before the error point.
267- * - Closing parens and brackets, provided they match an opening parent or bracket
268- * before the error point and there are no intervening other kinds of parens.
269- * - Semicolons and newlines, provided there are no intervening braces.
270- * - Definite statement starts on new lines, provided they are not more indented
271- * than the last known statement start before the error point.
272- */
273- protected def skip (): Unit = {
274- val skippedParens = new ParensCounters
275- while (true ) {
276- (in.token: @ switch) match {
277- case EOF =>
278- return
279- case SEMI | NEWLINE | NEWLINES =>
280- if (skippedParens.count(LBRACE ) == 0 ) return
281- case RBRACE =>
282- if (openParens.count(LBRACE ) > 0 && skippedParens.count(LBRACE ) == 0 )
283- return
284- skippedParens.change(LBRACE , - 1 )
285- case RPAREN =>
286- if (openParens.count(LPAREN ) > 0 && skippedParens.nonePositive)
287- return
288- skippedParens.change(LPAREN , - 1 )
289- case RBRACKET =>
290- if (openParens.count(LBRACKET ) > 0 && skippedParens.nonePositive)
291- return
292- skippedParens.change(LBRACKET , - 1 )
293- case OUTDENT =>
294- if (openParens.count(INDENT ) > 0 && skippedParens.count(INDENT ) == 0 )
295- return
296- skippedParens.change(INDENT , - 1 )
297- case LBRACE =>
298- skippedParens.change(LBRACE , + 1 )
299- case LPAREN =>
300- skippedParens.change(LPAREN , + 1 )
301- case LBRACKET =>
302- skippedParens.change(LBRACKET , + 1 )
303- case INDENT =>
304- skippedParens.change(INDENT , + 1 )
305- case _ =>
306- if (mustStartStat &&
307- in.isAfterLineEnd &&
308- isLeqIndented(in.offset, lastStatOffset max 0 ))
309- return
310- }
255+ */
256+ protected def skip (): Unit =
257+ val lastRegion = in.currentRegion
258+ def atStop =
259+ in.token == EOF
260+ || skipStopTokens.contains(in.token) && (in.currentRegion eq lastRegion)
261+ while ! atStop do
311262 in.nextToken()
312- }
313- }
314263
315264 def warning (msg : Message , sourcePos : SourcePosition ): Unit =
316265 report.warning(msg, sourcePos)
@@ -557,15 +506,9 @@ object Parsers {
557506
558507/* -------- COMBINATORS -------------------------------------------------------- */
559508
560- def enclosed [T ](tok : Token , body : => T ): T = {
509+ def enclosed [T ](tok : Token , body : => T ): T =
561510 accept(tok)
562- openParens.change(tok, 1 )
563- try body
564- finally {
565- accept(tok + 1 )
566- openParens.change(tok, - 1 )
567- }
568- }
511+ try body finally accept(tok + 1 )
569512
570513 def inParens [T ](body : => T ): T = enclosed(LPAREN , body)
571514 def inBraces [T ](body : => T ): T = enclosed(LBRACE , body)
@@ -1431,7 +1374,6 @@ object Parsers {
14311374 functionRest(Nil )
14321375 }
14331376 else {
1434- openParens.change(LPAREN , 1 )
14351377 imods = modifiers(funTypeArgMods)
14361378 val paramStart = in.offset
14371379 val ts = funArgType() match {
@@ -1443,7 +1385,6 @@ object Parsers {
14431385 case t =>
14441386 funArgTypesRest(t, funArgType)
14451387 }
1446- openParens.change(LPAREN , - 1 )
14471388 accept(RPAREN )
14481389 if isValParamList || in.token == ARROW || in.token == CTXARROW then
14491390 functionRest(ts)
@@ -2151,14 +2092,12 @@ object Parsers {
21512092 if in.token == RPAREN then
21522093 Nil
21532094 else
2154- openParens.change(LPAREN , 1 )
21552095 var mods1 = mods
21562096 if in.token == ERASED then mods1 = addModifier(mods1)
21572097 try
21582098 commaSeparated(() => binding(mods1))
21592099 finally
21602100 accept(RPAREN )
2161- openParens.change(LPAREN , - 1 )
21622101 else {
21632102 val start = in.offset
21642103 val name = bindingName()
@@ -2506,7 +2445,6 @@ object Parsers {
25062445 val enums =
25072446 if (leading == LBRACE || leading == LPAREN && followingIsEnclosedGenerators()) {
25082447 in.nextToken()
2509- openParens.change(leading, 1 )
25102448 val res =
25112449 if (leading == LBRACE || in.token == CASE )
25122450 enumerators()
@@ -2516,7 +2454,6 @@ object Parsers {
25162454 if (in.token == RPAREN || pats.length > 1 ) {
25172455 wrappedEnums = false
25182456 accept(RPAREN )
2519- openParens.change(LPAREN , - 1 )
25202457 atSpan(start) { makeTupleOrParens(pats) } // note: alternatives `|' need to be weeded out by typer.
25212458 }
25222459 else pats.head
@@ -2525,7 +2462,6 @@ object Parsers {
25252462 if (wrappedEnums) {
25262463 val closingOnNewLine = in.isAfterLineEnd
25272464 accept(leading + 1 )
2528- openParens.change(leading, - 1 )
25292465 def hasMultiLineEnum =
25302466 res.exists { t =>
25312467 val pos = t.sourcePos
0 commit comments