Skip to content

Commit 3323c02

Browse files
authored
Merge pull request #757 from CodaFi/leading-questions
2 parents 4a8743b + 6498941 commit 3323c02

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ extension Parser {
577577
return RawClassDeclSyntax(
578578
attributes: attrs.attributes,
579579
modifiers: attrs.modifiers,
580+
unexpectedBeforeClassKeyword,
580581
classKeyword: classKeyword,
581582
unexpectedBeforeName,
582583
identifier: name,
@@ -694,6 +695,7 @@ extension Parser {
694695
let members = self.parseMemberDeclList()
695696
return RawEnumDeclSyntax(
696697
attributes: attrs.attributes, modifiers: attrs.modifiers,
698+
unexpectedBeforeEnumKeyword,
697699
enumKeyword: enumKeyword,
698700
unexpectedBeforeName,
699701
identifier: name,
@@ -831,6 +833,7 @@ extension Parser {
831833
let members = self.parseMemberDeclList()
832834
return RawStructDeclSyntax(
833835
attributes: attrs.attributes, modifiers: attrs.modifiers,
836+
unexpectedBeforeStructKeyword,
834837
structKeyword: structKeyword,
835838
identifier: name,
836839
genericParameterClause: generics,
@@ -938,6 +941,7 @@ extension Parser {
938941

939942
return RawProtocolDeclSyntax(
940943
attributes: attrs.attributes, modifiers: attrs.modifiers,
944+
unexpectedBeforeProtocolKeyword,
941945
protocolKeyword: protocolKeyword,
942946
identifier: name,
943947
primaryAssociatedTypeClause: primaries,
@@ -1003,6 +1007,7 @@ extension Parser {
10031007

10041008
return RawAssociatedtypeDeclSyntax(
10051009
attributes: attrs.attributes, modifiers: attrs.modifiers,
1010+
unexpectedBeforeAssocKeyword,
10061011
associatedtypeKeyword: assocKeyword,
10071012
identifier: name,
10081013
inheritanceClause: inheritance,

Tests/SwiftParserTest/Declarations.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,55 @@ final class DeclarationTests: XCTestCase {
804804
}
805805
"""##)
806806
}
807+
808+
func testLeadingUnexpectedTokens() {
809+
AssertParse("#^DIAG_1^#}class C#^DIAG_2^#",
810+
diagnostics: [
811+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before class"),
812+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start class"),
813+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end class"),
814+
])
815+
AssertParse("#^DIAG_1^#}enum C#^DIAG_2^#",
816+
diagnostics: [
817+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before enum"),
818+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start enum"),
819+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end enum"),
820+
])
821+
AssertParse("#^DIAG_1^#}protocol C#^DIAG_2^#",
822+
diagnostics: [
823+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before protocol"),
824+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start protocol"),
825+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end protocol"),
826+
])
827+
AssertParse("#^DIAG_1^#}actor C#^DIAG_2^#",
828+
diagnostics: [
829+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before actor"),
830+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start actor"),
831+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end actor"),
832+
])
833+
AssertParse("#^DIAG_1^#}struct C#^DIAG_2^#",
834+
diagnostics: [
835+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before struct"),
836+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '{' to start struct"),
837+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}' to end struct"),
838+
])
839+
AssertParse("#^DIAG_1^#}func C#^DIAG_2^#",
840+
diagnostics: [
841+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before function"),
842+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
843+
])
844+
AssertParse("#^DIAG_1^#}init#^DIAG_2^#",
845+
diagnostics: [
846+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before initializer"),
847+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
848+
])
849+
AssertParse("#^DIAG_1^#}subscript#^DIAG_2^#",
850+
diagnostics: [
851+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '}' before subscript"),
852+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected argument list in function declaration"),
853+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '->' in return clause"),
854+
])
855+
}
807856
}
808857

809858
extension Parser.DeclAttributes {

0 commit comments

Comments
 (0)