@@ -1519,33 +1519,37 @@ extension Parser {
1519
1519
struct AccessorIntroducer {
1520
1520
var attributes : RawAttributeListSyntax ?
1521
1521
var modifier : RawDeclModifierSyntax ?
1522
- var introducer : ( AccessorKind , RawTokenSyntax ) ?
1522
+ var kind : AccessorKind
1523
+ var token : RawTokenSyntax
1523
1524
}
1524
1525
1525
- mutating func parseAccessorIntroducer( ) -> AccessorIntroducer {
1526
+ mutating func parseAccessorIntroducer( ) -> AccessorIntroducer ? {
1527
+ // Check there is an identifier before consuming
1528
+ var look = self . lookahead ( )
1529
+ let _ = look. consumeAttributeList ( )
1530
+ let hasModifier = look. consume ( ifAny: [ ] , contextualKeywords: [ " mutating " , " nonmutating " , " __consuming " ] ) != nil
1531
+ guard let ( kind, handle) = look. at ( anyIn: AccessorKind . self) else {
1532
+ return nil
1533
+ }
1534
+
1526
1535
let attrs = self . parseAttributeList ( )
1527
1536
1528
1537
// Parse the contextual keywords for 'mutating' and 'nonmutating' before
1529
1538
// get and set.
1530
1539
let modifier : RawDeclModifierSyntax ?
1531
- if let name = self . consume ( ifAny : [ ] , contextualKeywords : [ " mutating " , " nonmutating " , " __consuming " ] ) {
1540
+ if hasModifier {
1532
1541
modifier = RawDeclModifierSyntax (
1533
- name: name ,
1542
+ name: self . consumeAnyToken ( ) ,
1534
1543
detail: nil ,
1535
1544
arena: self . arena
1536
1545
)
1537
1546
} else {
1538
1547
modifier = nil
1539
1548
}
1540
1549
1541
- guard let ( kind, handle) = self . at ( anyIn: AccessorKind . self) else {
1542
- return AccessorIntroducer (
1543
- attributes: attrs, modifier: modifier, introducer: nil )
1544
- }
1545
-
1546
1550
let introducer = self . eat ( handle)
1547
1551
return AccessorIntroducer (
1548
- attributes: attrs, modifier: modifier, introducer : ( kind, introducer) )
1552
+ attributes: attrs, modifier: modifier, kind : kind, token : introducer)
1549
1553
}
1550
1554
1551
1555
@_spi ( RawSyntax)
@@ -1612,8 +1616,7 @@ extension Parser {
1612
1616
do {
1613
1617
var loopProgress = LoopProgressCondition ( )
1614
1618
while !self . at ( any: [ . eof, . rightBrace] ) && loopProgress. evaluate ( currentToken) {
1615
- let introducer = self . parseAccessorIntroducer ( )
1616
- guard let ( kind, kindToken) = introducer. introducer else {
1619
+ guard let introducer = self . parseAccessorIntroducer ( ) else {
1617
1620
// There can only be an implicit getter if no other accessors were
1618
1621
// seen before this one.
1619
1622
guard elements. isEmpty else {
@@ -1649,7 +1652,7 @@ extension Parser {
1649
1652
//
1650
1653
// set-name ::= '(' identifier ')'
1651
1654
let parameter : RawAccessorParameterSyntax ?
1652
- if [ AccessorKind . set, . willSet, . didSet ] . contains ( kind) , let lparen = self . consume ( if: . leftParen) {
1655
+ if [ AccessorKind . set, . willSet, . didSet ] . contains ( introducer . kind) , let lparen = self . consume ( if: . leftParen) {
1653
1656
let ( unexpectedBeforeName, name) = self . expectIdentifier ( )
1654
1657
let ( unexpectedBeforeRParen, rparen) = self . expect ( . rightParen)
1655
1658
parameter = RawAccessorParameterSyntax (
@@ -1681,7 +1684,7 @@ extension Parser {
1681
1684
elements. append ( RawAccessorDeclSyntax (
1682
1685
attributes: introducer. attributes,
1683
1686
modifier: introducer. modifier,
1684
- accessorKind: kindToken ,
1687
+ accessorKind: introducer . token ,
1685
1688
parameter: parameter,
1686
1689
asyncKeyword: asyncKeyword,
1687
1690
throwsKeyword: throwsKeyword,
0 commit comments