Skip to content

Commit 616f2d0

Browse files
committed
Skip newlines for weakBracketClose precedence level
This slightly improves recovery.
1 parent c4529c1 commit 616f2d0

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ enum TokenPrecedence: Comparable {
100100
return precedence(lhs) < precedence(rhs)
101101
}
102102

103-
/// When expecting a token with `stmtKeyword` precedence or higher, newlines may be skipped to find that token.
103+
/// When expecting a token with `weakBracketClose` precedence or higher, newlines may be skipped to find that token.
104104
/// For lower precedence groups, we consider newlines the end of the lookahead scope.
105105
var shouldSkipOverNewlines: Bool {
106-
return self >= .stmtKeyword
106+
return self >= .weakBracketClose
107107
}
108108

109109
init(_ lexeme: Lexer.Lexeme) {

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,10 @@ final class DeclarationTests: ParserTestCase {
487487
) var a = 0
488488
""",
489489
diagnostics: [
490-
DiagnosticSpec(message: "expected 'set)' to end modifier", fixIts: ["insert 'set)'"]),
491-
// FIXME: It should print `+` as detail of text.
492-
DiagnosticSpec(message: "unexpected code in variable"),
490+
DiagnosticSpec(message: "expected 'set' in modifier", fixIts: ["remove '+'"])
493491
],
494492
fixedSource: """
495-
private(set) +
493+
private(
496494
set
497495
) var a = 0
498496
"""
@@ -1469,19 +1467,13 @@ final class DeclarationTests: ParserTestCase {
14691467
message: "expected ':' in parameter",
14701468
fixIts: ["insert ':'"]
14711469
),
1472-
DiagnosticSpec(
1473-
locationMarker: "2️⃣",
1474-
message: "expected ')' to end parameter clause",
1475-
notes: [NoteSpec(message: "to match this opening '('")],
1476-
fixIts: ["insert ')'"]
1477-
),
14781470
DiagnosticSpec(
14791471
locationMarker: "3️⃣",
1480-
message: "extraneous code ': Int) {}' at top level"
1472+
message: "unexpected code ': Int' in parameter clause"
14811473
),
14821474
],
14831475
fixedSource: """
1484-
func foo(first second: third)
1476+
func foo(first second: third
14851477
: Int) {}
14861478
"""
14871479
)

0 commit comments

Comments
 (0)