Skip to content

Commit aed8ede

Browse files
committed
minor changes
1 parent e7dc9a4 commit aed8ede

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Sources/SwiftParser/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ extension Parser {
193193
}
194194
keepGoing = self.consume(if: .comma)
195195
if keepGoing == nil, let andOperator = self.consumeIfContextualPunctuator("&&") {
196-
unexpectedBeforeKeepGoing = RawUnexpectedNodesSyntax([andOperator], arena: self.arena)
196+
unexpectedBeforeKeepGoing = RawUnexpectedNodesSyntax(combining: unexpectedBeforeKeepGoing, andOperator, arena: self.arena)
197197
keepGoing = missingToken(.comma)
198198
}
199199
elements.append(

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ import SwiftParser
1717
fileprivate func getTokens(between first: TokenSyntax, and second: TokenSyntax) -> [TokenSyntax] {
1818
var tokens: [TokenSyntax] = []
1919
var currentToken = first
20+
2021
while currentToken != second {
2122
tokens.append(currentToken)
22-
currentToken = currentToken.nextToken ?? second
23+
guard let nextToken = currentToken.nextToken(viewMode: .sourceAccurate) else {
24+
assertionFailure("second Token must occur after first Token")
25+
return tokens
26+
}
27+
currentToken = nextToken
2328
}
2429
tokens.append(second)
2530
return tokens

Tests/SwiftParserTest/Assertions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ func assertParse<S: SyntaxProtocol>(
556556
markerLocations["START"] = 0
557557

558558
let tree: S = parse(source)
559+
560+
print(tree.recursiveDescription)
559561

560562
// Round-trip
561563
assertStringsEqualWithDiff(

Tests/SwiftParserTest/translated/AvailabilityQueryUnavailabilityTests.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,28 @@ final class AvailabilityQueryUnavailabilityTests: XCTestCase {
441441
}
442442
""",
443443
diagnostics: [
444-
DiagnosticSpec(message: "#available cannot be used as an expression, did you mean to use '#unavailable'?", fixIts: ["replace '#available(*) == false' with '#unavailable(*)'"])
444+
DiagnosticSpec(message: "#available cannot be used as an expression, did you mean to use '#unavailable'?", fixIts: ["replace '#available(*) == false' with '#unavailable(*)'"]),
445445
]
446446
)
447447
}
448-
448+
449449
func testAvailabilityQueryUnavailability34b() {
450+
assertParse(
451+
"""
452+
// Diagnose wrong spellings of unavailability
453+
if #available(*) 1️⃣== false && 2️⃣true {
454+
}
455+
""",
456+
diagnostics: [
457+
DiagnosticSpec(locationMarker: "1️⃣", message: "unexpected code '== false &&' in 'if' statement"),
458+
DiagnosticSpec(locationMarker: "2️⃣", message: "expected ',' in 'if' statement", fixIts: ["insert ','"]),
459+
// TODO: Old parser expected error on line 2: #available cannot be used as an expression, did you mean to use '#unavailable'?, Fix-It replacements: 4 - 14 = '#unavailable', 18 - 27 = ''
460+
// TODO: Old parser expected error on line 2: expected ',' joining parts of a multi-clause condition, Fix-It replacements: 27 - 28 = ','
461+
]
462+
)
463+
}
464+
465+
func testAvailabilityQueryUnavailability34c() {
450466
assertParse(
451467
"""
452468
if !1️⃣#available(*) {

0 commit comments

Comments
 (0)