Skip to content

Commit 5d05ddf

Browse files
committed
Remove "after <previous token>" clause from missing node diagnostics
1 parent 8a4fa32 commit 5d05ddf

File tree

5 files changed

+25
-32
lines changed

5 files changed

+25
-32
lines changed

Sources/SwiftParser/Diagnostics/MissingNodesError.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ public struct MissingNodesError: ParserError {
128128
}
129129
}
130130

131-
// The after clause only provides value if the first missing node is not a token.
132-
// TODO: Revisit whether we want to have this clause at all.
133-
if !firstMissingNode.is(TokenSyntax.self) {
134-
if let previousToken = firstMissingNode.previousToken(viewMode: .fixedUp), previousToken.presence == .present {
135-
return "after '\(previousToken.text)'"
136-
}
137-
}
138131
return nil
139132
}
140133

Tests/SwiftParserTest/Declarations.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ final class DeclarationTests: XCTestCase {
702702
}
703703
""",
704704
diagnostics: [
705-
DiagnosticSpec(locationMarker: "EXPECTED_DECL", message: "Expected declaration after '{' in struct"),
705+
DiagnosticSpec(locationMarker: "EXPECTED_DECL", message: "Expected declaration in struct"),
706706
DiagnosticSpec(locationMarker: "UNEXPECTED_TEXT", message: #"Unexpected text '/ ###line 25 "line-directive.swift"' in struct"#)
707707
]
708708
)
@@ -893,8 +893,8 @@ final class DeclarationTests: XCTestCase {
893893
""",
894894
diagnostics: [
895895
DiagnosticSpec(locationMarker: "OPENING_BRACE", message: "Expected '{' in struct"),
896-
DiagnosticSpec(locationMarker: "AFTER_POUND_IF", message: "Expected condition after '#if' in conditional compilation clause"),
897-
DiagnosticSpec(locationMarker: "END", message: "Expected name after '@' in attribute"),
896+
DiagnosticSpec(locationMarker: "AFTER_POUND_IF", message: "Expected condition in conditional compilation clause"),
897+
DiagnosticSpec(locationMarker: "END", message: "Expected name in attribute"),
898898
DiagnosticSpec(locationMarker: "END", message: "Expected declaration after attribute in conditional compilation clause"),
899899
DiagnosticSpec(locationMarker: "END", message: "Expected '#endif' in conditional compilation block"),
900900
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end struct")
@@ -1055,7 +1055,7 @@ final class DeclarationTests: XCTestCase {
10551055
struct U<@#^DIAG^#
10561056
""",
10571057
diagnostics: [
1058-
DiagnosticSpec(message: "Expected name after '@' in attribute"),
1058+
DiagnosticSpec(message: "Expected name in attribute"),
10591059
DiagnosticSpec(message: "Expected identifier in generic parameter"),
10601060
DiagnosticSpec(message: "Expected '>' to end generic parameter clause"),
10611061
DiagnosticSpec(message: "Expected member block in struct"),

Tests/SwiftParserTest/Expressions.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ final class ExpressionTests: XCTestCase {
77
AssertParse(
88
"let a =#^DIAG^#",
99
diagnostics: [
10-
DiagnosticSpec(message: "Expected expression after '=' in variable")
10+
DiagnosticSpec(message: "Expected expression in variable")
1111
]
1212
)
1313

1414
AssertParse("a ? b : c ? d : e")
1515
AssertParse(
1616
"a ? b :#^DIAG^#",
1717
diagnostics: [
18-
DiagnosticSpec(message: "Expected expression after ':'")
18+
DiagnosticSpec(message: "Expected expression")
1919
]
2020
)
2121
}
@@ -102,7 +102,7 @@ final class ExpressionTests: XCTestCase {
102102
c[#^DIAG^#
103103
"""#,
104104
diagnostics: [
105-
DiagnosticSpec(message: "Expected value after '[' in subscript"),
105+
DiagnosticSpec(message: "Expected value in subscript"),
106106
DiagnosticSpec(message: "Expected ']' to end subscript"),
107107
]
108108
)
@@ -173,7 +173,7 @@ final class ExpressionTests: XCTestCase {
173173
,#^END_ARRAY^#
174174
""",
175175
diagnostics: [
176-
DiagnosticSpec(locationMarker: "EXPECTED_EXPR", message: "Expected value after '[' in array element"),
176+
DiagnosticSpec(locationMarker: "EXPECTED_EXPR", message: "Expected value in array element"),
177177
DiagnosticSpec(locationMarker: "END_ARRAY", message: "Expected ']' to end array"),
178178
]
179179
)
@@ -183,7 +183,7 @@ final class ExpressionTests: XCTestCase {
183183
([1:#^DIAG^#)
184184
""",
185185
diagnostics: [
186-
DiagnosticSpec(message: "Expected value after ':' in dictionary element"),
186+
DiagnosticSpec(message: "Expected value in dictionary element"),
187187
DiagnosticSpec(message: "Expected ']' to end dictionary"),
188188
]
189189
)
@@ -401,8 +401,8 @@ final class ExpressionTests: XCTestCase {
401401
\#^AFTER_SLASH^#\(#^AFTER_PAREN^#
402402
"""##,
403403
diagnostics: [
404-
DiagnosticSpec(locationMarker: "AFTER_SLASH", message: #"Expected root and expression after '\' in key path"#),
405-
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected value after '(' in tuple"),
404+
DiagnosticSpec(locationMarker: "AFTER_SLASH", message: #"Expected root and expression in key path"#),
405+
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected value in tuple"),
406406
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected ')' to end tuple"),
407407
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected expression in key path"),
408408
]
@@ -467,8 +467,8 @@ final class ExpressionTests: XCTestCase {
467467
print "\(i)\"\n#^END^#
468468
"""#,
469469
diagnostics: [
470-
DiagnosticSpec(locationMarker: "KEY_PATH_1", message: "Expected expression after 'n' in key path"),
471-
DiagnosticSpec(locationMarker: "KEY_PATH_2", message: "Expected expression after 'n' in key path"),
470+
DiagnosticSpec(locationMarker: "KEY_PATH_1", message: "Expected expression in key path"),
471+
DiagnosticSpec(locationMarker: "KEY_PATH_2", message: "Expected expression in key path"),
472472
DiagnosticSpec(locationMarker: "END", message: #"Expected '"' to end string literal"#),
473473
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end 'if' statement"),
474474
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end function"),
@@ -479,7 +479,7 @@ final class ExpressionTests: XCTestCase {
479479
diagnostics: [
480480
DiagnosticSpec(message: "Expected identifier in '#keyPath' expression"),
481481
DiagnosticSpec(message: "Expected ')' to end '#keyPath' expression"),
482-
DiagnosticSpec(locationMarker: "MISSING_VALUE", message: "Expected value after ':' in function call"),
482+
DiagnosticSpec(locationMarker: "MISSING_VALUE", message: "Expected value in function call"),
483483
])
484484
}
485485

@@ -488,7 +488,7 @@ final class ExpressionTests: XCTestCase {
488488
"[(Int) -> #^DIAG^#throws Int]()",
489489
diagnostics: [
490490
// FIXME: We should suggest to move 'throws' in front of '->'
491-
DiagnosticSpec(message: "Expected expression after '->' in array element"),
491+
DiagnosticSpec(message: "Expected expression in array element"),
492492
DiagnosticSpec(message: "Unexpected text 'throws Int' in array"),
493493
]
494494
)
@@ -510,7 +510,7 @@ final class ExpressionTests: XCTestCase {
510510
}
511511
""",
512512
diagnostics: [
513-
DiagnosticSpec(message: "Expected expression after ':' in 'do' statement")
513+
DiagnosticSpec(message: "Expected expression in 'do' statement")
514514
]
515515
)
516516
}
@@ -521,10 +521,10 @@ final class ExpressionTests: XCTestCase {
521521
let #^VAR_NAME^#:(#^DIAG_1^#..)->#^END^#
522522
""",
523523
diagnostics: [
524-
DiagnosticSpec(locationMarker: "VAR_NAME", message: "Expected pattern after 'let' in variable"),
525-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected type after '(' in function type"),
524+
DiagnosticSpec(locationMarker: "VAR_NAME", message: "Expected pattern in variable"),
525+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected type in function type"),
526526
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '..' in function type"),
527-
DiagnosticSpec(locationMarker: "END", message: "Expected type after '->' in function type"),
527+
DiagnosticSpec(locationMarker: "END", message: "Expected type in function type"),
528528
]
529529
)
530530
}
@@ -536,7 +536,7 @@ final class ExpressionTests: XCTestCase {
536536
substructure: Syntax(TokenSyntax.contextualKeyword("async")),
537537
substructureAfterMarker: "ASYNC",
538538
diagnostics: [
539-
DiagnosticSpec(locationMarker: "END", message: "Expected expression after '->'")
539+
DiagnosticSpec(locationMarker: "END", message: "Expected expression")
540540
]
541541
)
542542
}

Tests/SwiftParserTest/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class StatementTests: XCTestCase {
4545
}
4646
""",
4747
diagnostics: [
48-
DiagnosticSpec(message: "Expected expression after 'case' in pattern"),
48+
DiagnosticSpec(message: "Expected expression in pattern"),
4949
DiagnosticSpec(message: "Expected '=' and expression in pattern matching"),
5050
DiagnosticSpec(message: "Unexpected text '* ! = x' in 'if' statement"),
5151
]

Tests/SwiftParserTest/Types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ final class TypeTests: XCTestCase {
3131

3232
func testFunctionTypes() throws {
3333
AssertParse("t as(#^DIAG^#..)->#^END^#", diagnostics: [
34-
DiagnosticSpec(message: "Expected type after '(' in function type"),
34+
DiagnosticSpec(message: "Expected type in function type"),
3535
DiagnosticSpec(message: "Unexpected text '..' in function type"),
36-
DiagnosticSpec(locationMarker: "END", message: "Expected type after '->' in function type"),
36+
DiagnosticSpec(locationMarker: "END", message: "Expected type in function type"),
3737
])
3838
}
3939

@@ -95,8 +95,8 @@ final class TypeTests: XCTestCase {
9595
"""#,
9696
diagnostics: [
9797
// FIXME: This should be a valid parse
98-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected expression after 'i' in key path"),
99-
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected expression after 'i' in key path"),
98+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected expression in key path"),
99+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected expression in key path"),
100100
]
101101
)
102102
}

0 commit comments

Comments
 (0)