@@ -83,8 +83,9 @@ extension TokenConsumer {
8383 /// - `colonColonToken`: The `::` indicating this module selector. Always `.colonColon`, always present.
8484 /// - `extra`: Tokens for additional trailing module selectors. There is no situation in which two module selectors
8585 /// can be validly chained.
86+ /// - `skipQualifiedName`: True if the next token should be interpreted as a different statement.
8687 mutating func consumeModuleSelectorTokensIfPresent( ) -> (
87- moduleNameOrUnexpected: Token , colonColonToken: Token , extra: [ Token ]
88+ moduleNameOrUnexpected: Token , colonColonToken: Token , extra: [ Token ] , skipQualifiedName : Bool
8889 ) ? {
8990 guard self . isAtModuleSelector ( ) else {
9091 return nil
@@ -111,15 +112,21 @@ extension TokenConsumer {
111112 }
112113 extra. append ( self . eat ( . colonColon) )
113114 }
114- return ( moduleName, colonColonToken, extra)
115+
116+ let afterContainsAnyNewline = self . atStartOfLine
117+
118+ return ( moduleName, colonColonToken, extra, afterContainsAnyNewline)
115119 }
116120}
117121
118122extension Parser {
119123 /// Parses one or more module selectors, if present.
120- mutating func parseModuleSelectorIfPresent( ) -> RawModuleSelectorSyntax ? {
121- guard let ( moduleNameOrUnexpected, colonColon, extra) = consumeModuleSelectorTokensIfPresent ( ) else {
122- return nil
124+ mutating func parseModuleSelectorIfPresent( ) -> ( moduleSelector: RawModuleSelectorSyntax ? , skipQualifiedName: Bool ) {
125+ guard
126+ let ( moduleNameOrUnexpected, colonColon, extra, skipQualifiedName) =
127+ consumeModuleSelectorTokensIfPresent ( )
128+ else {
129+ return ( nil , false )
123130 }
124131
125132 let leadingUnexpected : [ RawSyntax ]
@@ -136,12 +143,15 @@ extension Parser {
136143
137144 trailingUnexpected = extra. map { RawSyntax ( $0) }
138145
139- return RawModuleSelectorSyntax (
140- RawUnexpectedNodesSyntax ( leadingUnexpected, arena: arena) ,
141- moduleName: moduleName,
142- colonColon: colonColon,
143- RawUnexpectedNodesSyntax ( trailingUnexpected, arena: arena) ,
144- arena: arena
146+ return (
147+ moduleSelector: RawModuleSelectorSyntax (
148+ RawUnexpectedNodesSyntax ( leadingUnexpected, arena: arena) ,
149+ moduleName: moduleName,
150+ colonColon: colonColon,
151+ RawUnexpectedNodesSyntax ( trailingUnexpected, arena: arena) ,
152+ arena: arena
153+ ) ,
154+ skipQualifiedName: skipQualifiedName
145155 )
146156 }
147157}
@@ -169,29 +179,8 @@ extension Parser {
169179 }
170180
171181 mutating func parseDeclReferenceExpr( _ flags: DeclNameOptions = [ ] ) -> RawDeclReferenceExprSyntax {
172- // Consume a module selector if present.
173- let moduleSelector = self . parseModuleSelectorIfPresent ( )
174-
175- // If a module selector is found, we parse the name after it according to SE-0071 rules.
176- let allowKeywords = flags. contains ( . keywords) || moduleSelector != nil
177-
178- // Consume the base name.
179- let base : RawTokenSyntax
180- if let identOrSelf = self . consume ( if: . identifier, . keyword( . self ) , . keyword( . Self) )
181- ?? self . consume ( if: . keyword( . `init`) )
182- {
183- base = identOrSelf
184- } else if flags. contains ( . operators) , let ( _, _) = self . at ( anyIn: Operator . self) {
185- base = self . consumeAnyToken ( remapping: . binaryOperator)
186- } else if flags. contains ( . keywordsUsingSpecialNames) ,
187- let special = self . consume ( if: . keyword( . `deinit`) , . keyword( . `subscript`) )
188- {
189- base = special
190- } else if allowKeywords && self . currentToken. isLexerClassifiedKeyword {
191- base = self . consumeAnyToken ( remapping: . identifier)
192- } else {
193- base = missingToken ( . identifier)
194- }
182+ // Consume the module selector, if present, and base name.
183+ let ( moduleSelector, base) = self . parseDeclReferenceBase ( flags)
195184
196185 // Parse an argument list, if the flags allow it and it's present.
197186 let args = self . parseArgLabelList ( flags)
@@ -203,6 +192,35 @@ extension Parser {
203192 )
204193 }
205194
195+ private mutating func parseDeclReferenceBase(
196+ _ flags: DeclNameOptions
197+ ) -> ( moduleSelector: RawModuleSelectorSyntax ? , base: RawTokenSyntax ) {
198+ // Consume a module selector if present.
199+ let ( moduleSelector, skipQualifiedName) = self . parseModuleSelectorIfPresent ( )
200+
201+ // Consume the base name.
202+ if !skipQualifiedName {
203+ if let identOrInit = self . consume ( if: . identifier, . keyword( . `init`) ) {
204+ return ( moduleSelector, identOrInit)
205+ }
206+ if moduleSelector == nil , let selfOrSelf = self . consume ( if: . keyword( . `self`) , . keyword( . `Self`) ) {
207+ return ( moduleSelector, selfOrSelf)
208+ }
209+ if flags. contains ( . operators) , let ( _, _) = self . at ( anyIn: Operator . self) {
210+ return ( moduleSelector, self . consumeAnyToken ( remapping: . binaryOperator) )
211+ }
212+ if flags. contains ( . keywordsUsingSpecialNames) ,
213+ let special = self . consume ( if: . keyword( . `deinit`) , . keyword( . `subscript`) )
214+ {
215+ return ( moduleSelector, special)
216+ }
217+ if ( flags. contains ( . keywords) || moduleSelector != nil ) && self . currentToken. isLexerClassifiedKeyword {
218+ return ( moduleSelector, self . consumeAnyToken ( remapping: . identifier) )
219+ }
220+ }
221+ return ( moduleSelector, missingToken ( . identifier) )
222+ }
223+
206224 mutating func parseArgLabelList( _ flags: DeclNameOptions ) -> RawDeclNameArgumentsSyntax ? {
207225 guard flags. contains ( . compoundNames) else {
208226 return nil
@@ -319,8 +337,8 @@ extension Parser {
319337 var keepGoing = self . consume ( if: . period)
320338 var loopProgress = LoopProgressCondition ( )
321339 while keepGoing != nil && self . hasProgressed ( & loopProgress) {
322- let memberModuleSelector = self . parseModuleSelectorIfPresent ( )
323- let name = self . parseMemberTypeName ( )
340+ let ( memberModuleSelector, skipQualifiedName ) = self . parseModuleSelectorIfPresent ( )
341+ let name = self . parseMemberTypeName ( moduleSelector : memberModuleSelector , skipName : skipQualifiedName )
324342 let generics : RawGenericArgumentClauseSyntax ?
325343 if self . at ( prefix: " < " ) {
326344 generics = self . parseGenericArguments ( )
@@ -338,7 +356,7 @@ extension Parser {
338356 )
339357 )
340358
341- guard hasAnotherMember ( ) else {
359+ guard !skipQualifiedName && hasAnotherMember ( ) else {
342360 break
343361 }
344362
0 commit comments