Skip to content

Commit 4527338

Browse files
committed
Add precondition that the prefix of consumePrefix matches tokenKind.defaultText
1 parent be1fac0 commit 4527338

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Sources/SwiftParser/Lookahead.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ extension Parser.Lookahead {
117117
///
118118
/// <TOKEN> ... -> consumePrefix(<TOK>) -> [ <TOK> ] <EN> ...
119119
mutating func consumePrefix(_ prefix: SyntaxText, as tokenKind: RawTokenKind) {
120+
precondition(
121+
tokenKind.defaultText == nil || prefix == tokenKind.defaultText!,
122+
"If tokenKind has a defaultText, the prefix needs to match it"
123+
)
120124
let tokenText = self.currentToken.tokenText
121125

122126
if tokenText == prefix {

Sources/SwiftParser/Parser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ extension Parser {
605605
_ prefix: SyntaxText,
606606
as tokenKind: RawTokenKind
607607
) -> RawTokenSyntax {
608+
precondition(
609+
tokenKind.defaultText == nil || prefix == tokenKind.defaultText!,
610+
"If tokenKind has a defaultText, the prefix needs to match it"
611+
)
608612
let current = self.currentToken
609613
// Current token can be either one-character token we want to consume...
610614
let tokenText = current.tokenText

0 commit comments

Comments
 (0)