Skip to content

Commit bf21bd2

Browse files
committed
[NFC] Tighten checking for PBD introducers
Treating introducers as keywords is now always conditional on whether `shouldParsePatternBinding(introducer:)` returns `true`. That method has also been modified to correctly handle an edge case with wildcard patterns.
1 parent 632d0b9 commit bf21bd2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ extension TokenConsumer {
140140

141141
// Otherwise, parse it as an expression.
142142
return false
143+
case .rhs(let introducer):
144+
return subparser.shouldParsePatternBinding(introducer: introducer)
143145
case .some(_):
144146
// All other decl start keywords unconditionally start a decl.
145147
return true

Sources/SwiftParser/Patterns.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ extension Parser.Lookahead {
272272
// than likely need to be made contextual as well before finalizing their
273273
// grammar.
274274
case ._borrowing, .borrowing:
275-
return peek(isAt: TokenSpec(.identifier, allowAtStartOfLine: false))
275+
return peek(
276+
isAt: TokenSpec(.identifier, allowAtStartOfLine: false),
277+
TokenSpec(.wildcard, allowAtStartOfLine: false)
278+
)
276279
default:
277280
// Other keywords can be parsed unconditionally.
278281
return true

0 commit comments

Comments
 (0)