Skip to content

Skip newlines for weakBracketClose precedence level #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ enum TokenPrecedence: Comparable {
return precedence(lhs) < precedence(rhs)
}

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

init(_ lexeme: Lexer.Lexeme) {
Expand Down
16 changes: 4 additions & 12 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,10 @@ final class DeclarationTests: ParserTestCase {
) var a = 0
""",
diagnostics: [
DiagnosticSpec(message: "expected 'set)' to end modifier", fixIts: ["insert 'set)'"]),
// FIXME: It should print `+` as detail of text.
DiagnosticSpec(message: "unexpected code in variable"),
DiagnosticSpec(message: "expected 'set' in modifier", fixIts: ["remove '+'"])
],
fixedSource: """
private(set) +
private(
set
) var a = 0
"""
Expand Down Expand Up @@ -1469,19 +1467,13 @@ final class DeclarationTests: ParserTestCase {
message: "expected ':' in parameter",
fixIts: ["insert ':'"]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: "expected ')' to end parameter clause",
notes: [NoteSpec(message: "to match this opening '('")],
fixIts: ["insert ')'"]
),
DiagnosticSpec(
locationMarker: "3️⃣",
message: "extraneous code ': Int) {}' at top level"
message: "unexpected code ': Int' in parameter clause"
),
],
fixedSource: """
func foo(first second: third)
func foo(first second: third
: Int) {}
"""
)
Expand Down