Skip to content

Commit f7c4cfe

Browse files
committed
Check trivia for # and elif identifier
1 parent a92e8e0 commit f7c4cfe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/SwiftParser/Directives.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ extension Parser {
113113
var poundIf: Parser.Token
114114
let condition: RawExprSyntax?
115115
var atElifTypo: Bool {
116-
guard self.at(.pound) else {
116+
guard self.at(TokenSpec(.pound)), self.currentToken.trailingTriviaText.isEmpty else {
117117
return false
118118
}
119119
let identifierSpec = TokenSpec(.identifier, allowAtStartOfLine: false)
120120
var lookahead = self.lookahead()
121121
lookahead.consumeAnyToken()
122-
guard lookahead.at(identifierSpec), lookahead.currentToken.tokenText == "elif" else {
122+
guard lookahead.at(identifierSpec), lookahead.currentToken.tokenText == "elif", lookahead.currentToken.leadingTriviaText.isEmpty else {
123123
return false
124124
}
125125
lookahead.consumeAnyToken()
@@ -128,7 +128,7 @@ extension Parser {
128128

129129
if atElifTypo {
130130
(unexpectedBeforePoundIf, poundIf) = self.eat(poundIfHandle)
131-
guard let identifier = self.consume(if: TokenSpec(.identifier, allowAtStartOfLine: false)) else {
131+
guard self.currentToken.leadingTriviaText.isEmpty, let identifier = self.consume(if: TokenSpec(.identifier, allowAtStartOfLine: false)) else {
132132
preconditionFailure("The current token should be an identifier, guaranteed by the previous if statement")
133133
}
134134
unexpectedBeforePoundIf = RawUnexpectedNodesSyntax(combining: unexpectedBeforePoundIf, poundIf, identifier, arena: self.arena)

0 commit comments

Comments
 (0)