Skip to content

Commit 720da6e

Browse files
authored
Merge pull request #858 from CodaFi/captcha
Lookahead Through Balanced Brackets In Closure Capture Lists
2 parents 6068fc4 + 4025e68 commit 720da6e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,11 +2231,7 @@ extension Parser.Lookahead {
22312231

22322232
// Skip by a closure capture list if present.
22332233
if lookahead.consume(if: .leftSquareBracket) != nil {
2234-
var captureListProgress = LoopProgressCondition()
2235-
while !lookahead.at(any: [.eof, .rightSquareBracket]) && captureListProgress.evaluate(lookahead.currentToken) {
2236-
lookahead.consumeAnyToken()
2237-
}
2238-
2234+
lookahead.skipUntil(.rightSquareBracket, .rightSquareBracket)
22392235
if lookahead.consume(if: .rightSquareBracket) == nil {
22402236
return false
22412237
}

Tests/SwiftParserTest/Expressions.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,21 @@ final class ExpressionTests: XCTestCase {
593593
substructureAfterMarker: "PLUS"
594594
)
595595
}
596+
597+
func testBogusCaptureLists() {
598+
// N.B. This test ensures that capture list lookahead doesn't try to pair
599+
// the opening square bracket from the array literal with the closing
600+
// square bracket from the capture list.
601+
AssertParse(
602+
"""
603+
{
604+
[
605+
AboutItem(title: TextContent.legalAndMore, accessoryType: .disclosureIndicator, action: { [weak self] context in
606+
self?.tracker.buttonPressed(.legal)
607+
context.showSubmenu(title: TextContent.legalAndMore, configuration: LegalAndMoreSubmenuConfiguration())
608+
}),
609+
]
610+
}()
611+
""")
612+
}
596613
}

0 commit comments

Comments
 (0)