Skip to content

Commit 075ba1a

Browse files
committed
Rename ExprFlavor cases
Rename - `basic` -> `stmtCondition` because this case is used primarily in statement conditions that need to disambiguate trailing closures from the statement’s body - `trailingClosure` -> `basic` because this is the base case that we use inside normal expression parsing Also add argument labels to `flavor` to match the `pattern` parameter that also has a label and make `parseExpression` parameters required so that each caller needs to make a conscious choice about the values and so it’s easier to search for where each of the flavors is being used.
1 parent cd4b488 commit 075ba1a

File tree

7 files changed

+88
-75
lines changed

7 files changed

+88
-75
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ extension Parser {
799799
// See if there's a raw value expression.
800800
let rawValue: RawInitializerClauseSyntax?
801801
if let eq = self.consume(if: .equal) {
802-
let value = self.parseExpression()
802+
let value = self.parseExpression(flavor: .basic, pattern: .none)
803803
rawValue = RawInitializerClauseSyntax(
804804
equal: eq,
805805
value: value,
@@ -1219,7 +1219,7 @@ extension Parser {
12191219
// Parse an initializer if present.
12201220
let initializer: RawInitializerClauseSyntax?
12211221
if let equal = self.consume(if: .equal) {
1222-
var value = self.parseExpression()
1222+
var value = self.parseExpression(flavor: .basic, pattern: .none)
12231223
if hasTryBeforeIntroducer && !value.is(RawTryExprSyntax.self) {
12241224
value = RawExprSyntax(
12251225
RawTryExprSyntax(
@@ -1250,7 +1250,7 @@ extension Parser {
12501250
arena: self.arena
12511251
)
12521252
),
1253-
.basic,
1253+
flavor: .basic,
12541254
pattern: .none
12551255
)
12561256
initializer = RawInitializerClauseSyntax(
@@ -1267,7 +1267,7 @@ extension Parser {
12671267
)
12681268
} else if self.atStartOfExpression(), !self.at(.leftBrace), !self.atStartOfLine {
12691269
let missingEqual = RawTokenSyntax(missing: .equal, arena: self.arena)
1270-
let expr = self.parseExpression()
1270+
let expr = self.parseExpression(flavor: .basic, pattern: .none)
12711271
initializer = RawInitializerClauseSyntax(
12721272
equal: missingEqual,
12731273
value: expr,
@@ -1848,7 +1848,7 @@ extension Parser {
18481848
// Initializer, if any.
18491849
let definition: RawInitializerClauseSyntax?
18501850
if let equal = self.consume(if: .equal) {
1851-
let expr = self.parseExpression()
1851+
let expr = self.parseExpression(flavor: .basic, pattern: .none)
18521852
definition = RawInitializerClauseSyntax(
18531853
equal: equal,
18541854
value: expr,
@@ -1932,10 +1932,10 @@ extension Parser {
19321932
let trailingClosure: RawClosureExprSyntax?
19331933
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax
19341934
if self.at(.leftBrace),
1935-
self.withLookahead({ $0.atValidTrailingClosure(.trailingClosure) })
1935+
self.withLookahead({ $0.atValidTrailingClosure(flavor: .basic) })
19361936
{
19371937
(trailingClosure, additionalTrailingClosures) =
1938-
self.parseTrailingClosures(.trailingClosure)
1938+
self.parseTrailingClosures(flavor: .basic)
19391939
} else {
19401940
trailingClosure = nil
19411941
additionalTrailingClosures = self.emptyCollection(RawMultipleTrailingClosureElementListSyntax.self)

Sources/SwiftParser/Directives.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension Parser {
7070

7171
// Parse #if
7272
let (unexpectedBeforePoundIf, poundIf) = self.expect(.poundIf)
73-
let condition = RawExprSyntax(self.parseSequenceExpression(.poundIfDirective))
73+
let condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
7474
let unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()
7575

7676
clauses.append(
@@ -95,14 +95,14 @@ extension Parser {
9595
switch match {
9696
case .poundElseif:
9797
(unexpectedBeforePound, pound) = self.eat(handle)
98-
condition = RawExprSyntax(self.parseSequenceExpression(.poundIfDirective))
98+
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
9999
unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()
100100
case .poundElse:
101101
(unexpectedBeforePound, pound) = self.eat(handle)
102102
if let ifToken = self.consume(if: .init(.if, allowAtStartOfLine: false)) {
103103
unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, ifToken, arena: self.arena)
104104
pound = self.missingToken(.poundElseif)
105-
condition = RawExprSyntax(self.parseSequenceExpression(.poundIfDirective))
105+
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
106106
} else {
107107
condition = nil
108108
}
@@ -115,7 +115,7 @@ extension Parser {
115115
}
116116
unexpectedBeforePound = RawUnexpectedNodesSyntax(combining: unexpectedBeforePound, pound, elif, arena: self.arena)
117117
pound = self.missingToken(.poundElseif)
118-
condition = RawExprSyntax(self.parseSequenceExpression(.poundIfDirective))
118+
condition = RawExprSyntax(self.parseSequenceExpression(flavor: .poundIfDirective))
119119
unexpectedBetweenConditionAndElements = self.consumeRemainingTokenOnLine()
120120
} else {
121121
break LOOP

0 commit comments

Comments
 (0)