@@ -83,8 +83,9 @@ extension TokenConsumer {
83
83
/// - `colonColonToken`: The `::` indicating this module selector. Always `.colonColon`, always present.
84
84
/// - `extra`: Tokens for additional trailing module selectors. There is no situation in which two module selectors
85
85
/// can be validly chained.
86
+ /// - `skipQualifiedName`: True if the next token should be interpreted as a different statement.
86
87
mutating func consumeModuleSelectorTokensIfPresent( ) -> (
87
- moduleNameOrUnexpected: Token , colonColonToken: Token , extra: [ Token ]
88
+ moduleNameOrUnexpected: Token , colonColonToken: Token , extra: [ Token ] , skipQualifiedName : Bool
88
89
) ? {
89
90
guard self . isAtModuleSelector ( ) else {
90
91
return nil
@@ -111,15 +112,21 @@ extension TokenConsumer {
111
112
}
112
113
extra. append ( self . eat ( . colonColon) )
113
114
}
114
- return ( moduleName, colonColonToken, extra)
115
+
116
+ let afterContainsAnyNewline = self . atStartOfLine
117
+
118
+ return ( moduleName, colonColonToken, extra, afterContainsAnyNewline)
115
119
}
116
120
}
117
121
118
122
extension Parser {
119
123
/// 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 )
123
130
}
124
131
125
132
let leadingUnexpected : [ RawSyntax ]
@@ -136,12 +143,15 @@ extension Parser {
136
143
137
144
trailingUnexpected = extra. map { RawSyntax ( $0) }
138
145
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
145
155
)
146
156
}
147
157
}
@@ -169,29 +179,8 @@ extension Parser {
169
179
}
170
180
171
181
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)
195
184
196
185
// Parse an argument list, if the flags allow it and it's present.
197
186
let args = self . parseArgLabelList ( flags)
@@ -203,6 +192,35 @@ extension Parser {
203
192
)
204
193
}
205
194
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
+
206
224
mutating func parseArgLabelList( _ flags: DeclNameOptions ) -> RawDeclNameArgumentsSyntax ? {
207
225
guard flags. contains ( . compoundNames) else {
208
226
return nil
@@ -319,8 +337,8 @@ extension Parser {
319
337
var keepGoing = self . consume ( if: . period)
320
338
var loopProgress = LoopProgressCondition ( )
321
339
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 )
324
342
let generics : RawGenericArgumentClauseSyntax ?
325
343
if self . at ( prefix: " < " ) {
326
344
generics = self . parseGenericArguments ( )
@@ -338,7 +356,7 @@ extension Parser {
338
356
)
339
357
)
340
358
341
- guard hasAnotherMember ( ) else {
359
+ guard !skipQualifiedName && hasAnotherMember ( ) else {
342
360
break
343
361
}
344
362
0 commit comments