Skip to content

Commit 8d40a59

Browse files
committed
Make parseDeclNameRef return a RawDeclReferenceExprSyntax
1 parent 4846699 commit 8d40a59

File tree

3 files changed

+26
-67
lines changed

3 files changed

+26
-67
lines changed

Sources/SwiftParser/Attributes.swift

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,7 @@ extension Parser {
681681
case (.target, let handle)?:
682682
let ident = self.eat(handle)
683683
let (unexpectedBeforeColon, colon) = self.expect(.colon)
684-
let (targetFunction, args) = self.parseDeclNameRef([.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators])
685-
let declName = RawDeclReferenceExprSyntax(
686-
baseName: targetFunction,
687-
argumentNames: args,
688-
arena: self.arena
689-
)
684+
let declName = self.parseDeclReferenceExpr([.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators])
690685
let comma = self.consume(if: .comma)
691686
elements.append(
692687
.specializeTargetFunctionArgument(
@@ -823,15 +818,10 @@ extension Parser {
823818
mutating func parseImplementsAttributeArguments() -> RawImplementsAttributeArgumentsSyntax {
824819
let type = self.parseType()
825820
let (unexpectedBeforeComma, comma) = self.expect(.comma)
826-
let (name, args) = self.parseDeclNameRef([
821+
let declName = self.parseDeclReferenceExpr([
827822
.zeroArgCompoundNames,
828823
.operators,
829824
])
830-
let declName = RawDeclReferenceExprSyntax(
831-
baseName: name,
832-
argumentNames: args,
833-
arena: self.arena
834-
)
835825
return RawImplementsAttributeArgumentsSyntax(
836826
type: type,
837827
unexpectedBeforeComma,
@@ -1025,27 +1015,24 @@ extension Parser {
10251015
mutating func parseDynamicReplacementAttributeArguments() -> RawDynamicReplacementAttributeArgumentsSyntax {
10261016
let (unexpectedBeforeLabel, label) = self.expect(.keyword(.for))
10271017
let (unexpectedBeforeColon, colon) = self.expect(.colon)
1028-
let baseName: RawTokenSyntax
1029-
let argumentNames: RawDeclNameArgumentsSyntax?
1018+
let declName: RawDeclReferenceExprSyntax
10301019
if label.isMissing && colon.isMissing && self.atStartOfLine {
1031-
baseName = RawTokenSyntax(missing: .identifier, arena: self.arena)
1032-
argumentNames = nil
1020+
declName = RawDeclReferenceExprSyntax(
1021+
baseName: RawTokenSyntax(missing: .identifier, arena: self.arena),
1022+
argumentNames: nil,
1023+
arena: self.arena
1024+
)
10331025
} else {
1034-
(baseName, argumentNames) = self.parseDeclNameRef([
1026+
declName = self.parseDeclReferenceExpr([
10351027
.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators,
10361028
])
10371029
}
1038-
let method = RawDeclReferenceExprSyntax(
1039-
baseName: baseName,
1040-
argumentNames: argumentNames,
1041-
arena: self.arena
1042-
)
10431030
return RawDynamicReplacementAttributeArgumentsSyntax(
10441031
unexpectedBeforeLabel,
10451032
forLabel: label,
10461033
unexpectedBeforeColon,
10471034
colon: colon,
1048-
declName: method,
1035+
declName: declName,
10491036
arena: self.arena
10501037
)
10511038
}

Sources/SwiftParser/Expressions.swift

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,7 @@ extension Parser {
621621
)
622622
} else {
623623
// Handle an arbitrary declaration name.
624-
let (name, declNameArgs) = self.parseDeclNameRef([.keywords, .compoundNames])
625-
declName = RawDeclReferenceExprSyntax(
626-
baseName: name,
627-
argumentNames: declNameArgs,
628-
arena: self.arena
629-
)
624+
declName = self.parseDeclReferenceExpr([.keywords, .compoundNames])
630625
}
631626

632627
// Parse the generic arguments, if any.
@@ -1207,12 +1202,7 @@ extension Parser {
12071202
)
12081203
}
12091204

1210-
let (name, args) = self.parseDeclNameRef([.keywords, .compoundNames])
1211-
let declName = RawDeclReferenceExprSyntax(
1212-
baseName: name,
1213-
argumentNames: args,
1214-
arena: self.arena
1215-
)
1205+
let declName = self.parseDeclReferenceExpr([.keywords, .compoundNames])
12161206
return RawExprSyntax(
12171207
RawMemberAccessExprSyntax(
12181208
base: nil,
@@ -1256,34 +1246,23 @@ extension Parser {
12561246
extension Parser {
12571247
/// Parse an identifier as an expression.
12581248
mutating func parseIdentifierExpression() -> RawExprSyntax {
1259-
let (baseName, argumentNames) = self.parseDeclNameRef(.compoundNames)
1249+
let declName = self.parseDeclReferenceExpr(.compoundNames)
12601250
guard self.withLookahead({ $0.canParseAsGenericArgumentList() }) else {
1261-
if baseName.tokenText.isEditorPlaceholder && argumentNames == nil {
1251+
if declName.baseName.tokenText.isEditorPlaceholder && declName.argumentNames == nil {
12621252
return RawExprSyntax(
12631253
RawEditorPlaceholderExprSyntax(
1264-
placeholder: baseName,
1254+
placeholder: declName.baseName,
12651255
arena: self.arena
12661256
)
12671257
)
12681258
}
1269-
return RawExprSyntax(
1270-
RawDeclReferenceExprSyntax(
1271-
baseName: baseName,
1272-
argumentNames: argumentNames,
1273-
arena: self.arena
1274-
)
1275-
)
1259+
return RawExprSyntax(declName)
12761260
}
12771261

1278-
let identifier = RawDeclReferenceExprSyntax(
1279-
baseName: baseName,
1280-
argumentNames: argumentNames,
1281-
arena: self.arena
1282-
)
12831262
let generics = self.parseGenericArguments()
12841263
return RawExprSyntax(
12851264
RawGenericSpecializationExprSyntax(
1286-
expression: RawExprSyntax(identifier),
1265+
expression: RawExprSyntax(declName),
12871266
genericArgumentClause: generics,
12881267
arena: self.arena
12891268
)
@@ -1907,14 +1886,7 @@ extension Parser {
19071886
// follows a proper subexpression.
19081887
let expr: RawExprSyntax
19091888
if self.at(.binaryOperator) && self.peek(isAt: .comma, .rightParen, .rightSquare) {
1910-
let (baseName, argumentNames) = self.parseDeclNameRef(.operators)
1911-
expr = RawExprSyntax(
1912-
RawDeclReferenceExprSyntax(
1913-
baseName: baseName,
1914-
argumentNames: argumentNames,
1915-
arena: self.arena
1916-
)
1917-
)
1889+
expr = RawExprSyntax(self.parseDeclReferenceExpr(.operators))
19181890
} else {
19191891
expr = self.parseExpression(pattern: pattern)
19201892
}

Sources/SwiftParser/Names.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extension Parser {
6363
static let zeroArgCompoundNames: Self = [.compoundNames, Self(rawValue: 1 << 5)]
6464
}
6565

66-
mutating func parseDeclNameRef(_ flags: DeclNameOptions = []) -> (baseName: RawTokenSyntax, argumentNames: RawDeclNameArgumentsSyntax?) {
66+
mutating func parseDeclReferenceExpr(_ flags: DeclNameOptions = []) -> RawDeclReferenceExprSyntax {
6767
// Consume the base name.
6868
let base: RawTokenSyntax
6969
if let identOrSelf = self.consume(if: .identifier, .keyword(.self), .keyword(.Self)) ?? self.consume(if: .keyword(.`init`)) {
@@ -78,7 +78,11 @@ extension Parser {
7878

7979
// Parse an argument list, if the flags allow it and it's present.
8080
let args = self.parseArgLabelList(flags)
81-
return (base, args)
81+
return RawDeclReferenceExprSyntax(
82+
baseName: base,
83+
argumentNames: args,
84+
arena: self.arena
85+
)
8286
}
8387

8488
mutating func parseArgLabelList(_ flags: DeclNameOptions) -> RawDeclNameArgumentsSyntax? {
@@ -152,19 +156,15 @@ extension Parser {
152156
period = nil
153157
}
154158

155-
let (name, args) = self.parseDeclNameRef([
159+
let declName = self.parseDeclReferenceExpr([
156160
.zeroArgCompoundNames,
157161
.keywordsUsingSpecialNames,
158162
.operators,
159163
])
160164
return RawQualifiedDeclNameSyntax(
161165
baseType: type,
162166
period: period,
163-
declName: RawDeclReferenceExprSyntax(
164-
baseName: name,
165-
argumentNames: args,
166-
arena: self.arena
167-
),
167+
declName: declName,
168168
arena: self.arena
169169
)
170170
}

0 commit comments

Comments
 (0)