@@ -37,14 +37,6 @@ object Parsers {
3737
3838 case class OpInfo (operand : Tree , operator : Ident , offset : Offset )
3939
40- class ParensCounters {
41- private var parCounts = new Array [Int ](lastParen - firstParen)
42-
43- def count (tok : Token ): Int = parCounts(tok - firstParen)
44- def change (tok : Token , delta : Int ): Unit = parCounts(tok - firstParen) += delta
45- def nonePositive : Boolean = parCounts forall (_ <= 0 )
46- }
47-
4840 enum Location (val inParens : Boolean , val inPattern : Boolean , val inArgs : Boolean ):
4941 case InParens extends Location (true , false , false )
5042 case InArgs extends Location (true , false , true )
@@ -173,8 +165,6 @@ object Parsers {
173165
174166 val in : Scanner = new Scanner (source)
175167
176- val openParens : ParensCounters = new ParensCounters
177-
178168 /** This is the general parse entry point.
179169 * Overridden by ScriptParser
180170 */
@@ -261,55 +251,14 @@ object Parsers {
261251 }
262252
263253 /** Skip on error to next safe point.
264- * Safe points are:
265- * - Closing braces, provided they match an opening brace before the error point.
266- * - Closing parens and brackets, provided they match an opening parent or bracket
267- * before the error point and there are no intervening other kinds of parens.
268- * - Semicolons and newlines, provided there are no intervening braces.
269- * - Definite statement starts on new lines, provided they are not more indented
270- * than the last known statement start before the error point.
271- */
272- protected def skip (): Unit = {
273- val skippedParens = new ParensCounters
274- while (true ) {
275- (in.token: @ switch) match {
276- case EOF =>
277- return
278- case SEMI | NEWLINE | NEWLINES =>
279- if (skippedParens.count(LBRACE ) == 0 ) return
280- case RBRACE =>
281- if (openParens.count(LBRACE ) > 0 && skippedParens.count(LBRACE ) == 0 )
282- return
283- skippedParens.change(LBRACE , - 1 )
284- case RPAREN =>
285- if (openParens.count(LPAREN ) > 0 && skippedParens.nonePositive)
286- return
287- skippedParens.change(LPAREN , - 1 )
288- case RBRACKET =>
289- if (openParens.count(LBRACKET ) > 0 && skippedParens.nonePositive)
290- return
291- skippedParens.change(LBRACKET , - 1 )
292- case OUTDENT =>
293- if (openParens.count(INDENT ) > 0 && skippedParens.count(INDENT ) == 0 )
294- return
295- skippedParens.change(INDENT , - 1 )
296- case LBRACE =>
297- skippedParens.change(LBRACE , + 1 )
298- case LPAREN =>
299- skippedParens.change(LPAREN , + 1 )
300- case LBRACKET =>
301- skippedParens.change(LBRACKET , + 1 )
302- case INDENT =>
303- skippedParens.change(INDENT , + 1 )
304- case _ =>
305- if (mustStartStat &&
306- in.isAfterLineEnd &&
307- isLeqIndented(in.offset, lastStatOffset max 0 ))
308- return
309- }
254+ */
255+ protected def skip (): Unit =
256+ val lastRegion = in.currentRegion
257+ def atStop =
258+ in.token == EOF
259+ || skipStopTokens.contains(in.token) && (in.currentRegion eq lastRegion)
260+ while ! atStop do
310261 in.nextToken()
311- }
312- }
313262
314263 def warning (msg : Message , sourcePos : SourcePosition ): Unit =
315264 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)
@@ -1429,7 +1372,6 @@ object Parsers {
14291372 functionRest(Nil )
14301373 }
14311374 else {
1432- openParens.change(LPAREN , 1 )
14331375 imods = modifiers(funTypeArgMods)
14341376 val paramStart = in.offset
14351377 val ts = funArgType() match {
@@ -1441,7 +1383,6 @@ object Parsers {
14411383 case t =>
14421384 funArgTypesRest(t, funArgType)
14431385 }
1444- openParens.change(LPAREN , - 1 )
14451386 accept(RPAREN )
14461387 if isValParamList || in.token == ARROW || in.token == CTXARROW then
14471388 functionRest(ts)
@@ -2149,14 +2090,12 @@ object Parsers {
21492090 if in.token == RPAREN then
21502091 Nil
21512092 else
2152- openParens.change(LPAREN , 1 )
21532093 var mods1 = mods
21542094 if in.token == ERASED then mods1 = addModifier(mods1)
21552095 try
21562096 commaSeparated(() => binding(mods1))
21572097 finally
21582098 accept(RPAREN )
2159- openParens.change(LPAREN , - 1 )
21602099 else {
21612100 val start = in.offset
21622101 val name = bindingName()
@@ -2504,7 +2443,6 @@ object Parsers {
25042443 val enums =
25052444 if (leading == LBRACE || leading == LPAREN && followingIsEnclosedGenerators()) {
25062445 in.nextToken()
2507- openParens.change(leading, 1 )
25082446 val res =
25092447 if (leading == LBRACE || in.token == CASE )
25102448 enumerators()
@@ -2514,7 +2452,6 @@ object Parsers {
25142452 if (in.token == RPAREN || pats.length > 1 ) {
25152453 wrappedEnums = false
25162454 accept(RPAREN )
2517- openParens.change(LPAREN , - 1 )
25182455 atSpan(start) { makeTupleOrParens(pats) } // note: alternatives `|' need to be weeded out by typer.
25192456 }
25202457 else pats.head
@@ -2523,7 +2460,6 @@ object Parsers {
25232460 if (wrappedEnums) {
25242461 val closingOnNewLine = in.isAfterLineEnd
25252462 accept(leading + 1 )
2526- openParens.change(leading, - 1 )
25272463 def hasMultiLineEnum =
25282464 res.exists { t =>
25292465 val pos = t.sourcePos
0 commit comments