@@ -1668,12 +1668,18 @@ extension Parser {
1668
1668
arena: self . arena) )
1669
1669
} while keepGoing != nil && loopProgress. evaluate ( currentToken)
1670
1670
}
1671
+ // We were promised a right square bracket, so we're going to get it.
1672
+ var unexpectedNodes = [ RawSyntax] ( )
1673
+ while !self . at ( . eof) && !self . at ( . rightSquareBracket) && !self . at ( . inKeyword) {
1674
+ unexpectedNodes. append ( RawSyntax ( self . consumeAnyToken ( ) ) )
1675
+ }
1671
1676
let ( unexpectedBeforeRSquare, rsquare) = self . expect ( . rightSquareBracket)
1677
+ unexpectedNodes. append ( contentsOf: unexpectedBeforeRSquare? . elements ?? [ ] )
1672
1678
1673
1679
captures = RawClosureCaptureSignatureSyntax (
1674
1680
leftSquare: lsquare,
1675
1681
items: elements. isEmpty ? nil : RawClosureCaptureItemListSyntax ( elements: elements, arena: self . arena) ,
1676
- unexpectedBeforeRSquare ,
1682
+ unexpectedNodes . isEmpty ? nil : RawUnexpectedNodesSyntax ( elements : unexpectedNodes , arena : self . arena ) ,
1677
1683
rightSquare: rsquare, arena: self . arena)
1678
1684
} else {
1679
1685
captures = nil
@@ -1694,15 +1700,17 @@ extension Parser {
1694
1700
// Parse identifier (',' identifier)*
1695
1701
var keepGoing : RawTokenSyntax ? = nil
1696
1702
repeat {
1703
+ let unexpected : RawUnexpectedNodesSyntax ?
1697
1704
let name : RawTokenSyntax
1698
1705
if self . currentToken. isIdentifier {
1706
+ unexpected = nil
1699
1707
name = self . consumeIdentifier ( )
1700
1708
} else {
1701
- name = self . eat ( . wildcardKeyword)
1709
+ ( unexpected , name) = self . expect ( . wildcardKeyword)
1702
1710
}
1703
1711
keepGoing = consume ( if: . comma)
1704
1712
params. append ( RawClosureParamSyntax (
1705
- name: name, trailingComma: keepGoing, arena: self . arena) )
1713
+ unexpected , name: name, trailingComma: keepGoing, arena: self . arena) )
1706
1714
} while keepGoing != nil && loopProgress. evaluate ( currentToken)
1707
1715
}
1708
1716
@@ -1751,10 +1759,14 @@ extension Parser {
1751
1759
specifiers. append ( self . consumeIdentifier ( ) )
1752
1760
if let lparen = self . consume ( if: . leftParen) {
1753
1761
specifiers. append ( lparen)
1754
- specifiers. append ( self . expectWithoutLookahead ( . identifier, " unsafe " ) )
1762
+ if self . currentToken. tokenText == " safe " {
1763
+ specifiers. append ( self . expectWithoutLookahead ( . identifier, " safe " ) )
1764
+ } else {
1765
+ specifiers. append ( self . expectWithoutLookahead ( . identifier, " unsafe " ) )
1766
+ }
1755
1767
specifiers. append ( self . expectWithoutLookahead ( . rightParen) )
1756
1768
}
1757
- } else if ( self . currentToken. isIdentifier || self . at ( . selfKeyword) ) {
1769
+ } else if self . currentToken. isIdentifier || self . at ( . selfKeyword) {
1758
1770
let next = self . peek ( )
1759
1771
// "x = 42", "x," and "x]" are all strong captures of x.
1760
1772
guard next. tokenKind == . equal || next. tokenKind == . comma
@@ -1991,7 +2003,6 @@ extension Parser.Lookahead {
1991
2003
mutating func consumeEffectsSpecifiers( ) {
1992
2004
var loopProgress = LoopProgressCondition ( )
1993
2005
while self . currentToken. isEffectsSpecifier
1994
- && !self . currentToken. isAtStartOfLine
1995
2006
&& loopProgress. evaluate ( currentToken) {
1996
2007
self . consumeAnyToken ( )
1997
2008
}
0 commit comments