@@ -687,27 +687,74 @@ extension Parser.Lookahead {
687
687
return true
688
688
}
689
689
690
- mutating func skipTypeAttributeList( ) {
690
+ mutating func skipTypeAttributeList( ) -> Bool {
691
691
var specifierProgress = LoopProgressCondition ( )
692
692
while canHaveParameterSpecifier,
693
693
self . at ( anyIn: SimpleTypeSpecifierSyntax . SpecifierOptions. self) != nil
694
694
|| self . at ( . keyword( . nonisolated) , . keyword( . dependsOn) ) ,
695
695
self . hasProgressed ( & specifierProgress)
696
696
{
697
697
switch self . currentToken {
698
- case . keyword( . nonisolated) , . keyword( . dependsOn) :
698
+ case . keyword( . nonisolated) :
699
+ guard
700
+ self . withLookahead ( {
701
+ // Consume 'nonisolated'
702
+ $0. consumeAnyToken ( )
703
+
704
+ // The argument is missing but it still could be a valid modifier,
705
+ // i.e. `nonisolated` in an inheritance clause.
706
+ guard $0. at ( TokenSpec ( . leftParen, allowAtStartOfLine: false ) ) else {
707
+ return true
708
+ }
709
+
710
+ // Consume '('
711
+ $0. consumeAnyToken ( )
712
+
713
+ // nonisolated accepts a single modifier at the moment: 'nonsending'
714
+ // we need to check for that explicitly to avoid misinterpreting this
715
+ // keyword to be a modifier when it isn't i.e. `[nonisolated(42)]`
716
+ guard $0. consume ( if: TokenSpec ( . nonsending, allowAtStartOfLine: false ) ) != nil else {
717
+ return false
718
+ }
719
+
720
+ return $0. consume ( if: TokenSpec ( . rightParen, allowAtStartOfLine: false ) ) != nil
721
+ } )
722
+ else {
723
+ return false
724
+ }
725
+
699
726
self . consumeAnyToken ( )
700
727
701
- // The argument is missing but it still could be a valid modifier,
702
- // i.e. `nonisolated` in an inheritance clause.
703
728
guard self . at ( TokenSpec ( . leftParen, allowAtStartOfLine: false ) ) else {
704
729
continue
705
730
}
706
731
707
- if self . withLookahead ( { $0. atAttributeOrSpecifierArgument ( ) } ) {
708
- skipSingle ( )
732
+ self . skipSingle ( )
733
+
734
+ case . keyword( . dependsOn) :
735
+ guard
736
+ self . withLookahead ( {
737
+ // Consume 'dependsOn'
738
+ $0. consumeAnyToken ( )
739
+
740
+ if $0. currentToken. isAtStartOfLine {
741
+ return false
742
+ }
743
+
744
+ // `dependsOn` requires an argument list.
745
+ guard $0. atAttributeOrSpecifierArgument ( ) else {
746
+ return false
747
+ }
748
+
749
+ return true
750
+ } )
751
+ else {
752
+ return false
709
753
}
710
754
755
+ self . consumeAnyToken ( )
756
+ self . skipSingle ( )
757
+
711
758
default :
712
759
self . consumeAnyToken ( )
713
760
}
@@ -718,10 +765,14 @@ extension Parser.Lookahead {
718
765
self . consumeAnyToken ( )
719
766
self . skipTypeAttribute ( )
720
767
}
768
+
769
+ return true
721
770
}
722
771
723
772
mutating func canParseTypeScalar( ) -> Bool {
724
- self . skipTypeAttributeList ( )
773
+ guard self . skipTypeAttributeList ( ) else {
774
+ return false
775
+ }
725
776
726
777
guard self . canParseSimpleOrCompositionType ( ) else {
727
778
return false
0 commit comments