Skip to content

Commit 638a0f0

Browse files
committed
Rename Parser.Lookahead functions from is* to at*
1 parent af18ea4 commit 638a0f0

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

Sources/SwiftParser/Attributes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ extension Parser {
176176
case .required:
177177
shouldParseArgument = true
178178
case .customAttribute:
179-
shouldParseArgument = self.withLookahead { $0.isCustomAttributeArgument() } && self.at(TokenSpec(.leftParen, allowAtStartOfLine: false))
179+
shouldParseArgument = self.withLookahead { $0.atCustomAttributeArgument() } && self.at(TokenSpec(.leftParen, allowAtStartOfLine: false))
180180
case .optional:
181181
shouldParseArgument = self.at(.leftParen)
182182
}
@@ -1140,7 +1140,7 @@ extension Parser {
11401140
// MARK: Lookahead
11411141

11421142
extension Parser.Lookahead {
1143-
mutating func isCustomAttributeArgument() -> Bool {
1143+
mutating func atCustomAttributeArgument() -> Bool {
11441144
var lookahead = self.lookahead()
11451145
lookahead.skipSingle()
11461146

@@ -1173,7 +1173,7 @@ extension Parser.Lookahead {
11731173
return false
11741174
}
11751175

1176-
if self.at(TokenSpec(.leftParen, allowAtStartOfLine: false)) && self.withLookahead({ $0.isCustomAttributeArgument() }) {
1176+
if self.at(TokenSpec(.leftParen, allowAtStartOfLine: false)) && self.withLookahead({ $0.atCustomAttributeArgument() }) {
11771177
self.skipSingle()
11781178
}
11791179

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ extension Parser {
19191919
let trailingClosure: RawClosureExprSyntax?
19201920
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax?
19211921
if self.at(.leftBrace),
1922-
self.withLookahead({ $0.isValidTrailingClosure(.trailingClosure) })
1922+
self.withLookahead({ $0.atValidTrailingClosure(.trailingClosure) })
19231923
{
19241924
(trailingClosure, additionalTrailingClosures) =
19251925
self.parseTrailingClosures(.trailingClosure)

Sources/SwiftParser/Expressions.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ extension Parser {
734734
// If we can parse trailing closures, do so.
735735
let trailingClosure: RawClosureExprSyntax?
736736
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax?
737-
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.isValidTrailingClosure(flavor) }) {
737+
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.atValidTrailingClosure(flavor) }) {
738738
(trailingClosure, additionalTrailingClosures) = self.parseTrailingClosures(flavor)
739739
} else {
740740
trailingClosure = nil
@@ -770,7 +770,7 @@ extension Parser {
770770
// If we can parse trailing closures, do so.
771771
let trailingClosure: RawClosureExprSyntax?
772772
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax?
773-
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.isValidTrailingClosure(flavor) }) {
773+
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.atValidTrailingClosure(flavor) }) {
774774
(trailingClosure, additionalTrailingClosures) = self.parseTrailingClosures(flavor)
775775
} else {
776776
trailingClosure = nil
@@ -793,7 +793,7 @@ extension Parser {
793793
}
794794

795795
// Check for a trailing closure, if allowed.
796-
if self.at(.leftBrace) && self.withLookahead({ $0.isValidTrailingClosure(flavor) }) {
796+
if self.at(.leftBrace) && self.withLookahead({ $0.atValidTrailingClosure(flavor) }) {
797797
// FIXME: if Result has a trailing closure, break out.
798798
// Add dummy blank argument list to the call expression syntax.
799799
let list = RawLabeledExprListSyntax(elements: [], arena: self.arena)
@@ -1321,7 +1321,7 @@ extension Parser {
13211321
// Parse the optional trailing closures.
13221322
let trailingClosure: RawClosureExprSyntax?
13231323
let additionalTrailingClosures: RawMultipleTrailingClosureElementListSyntax?
1324-
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.isValidTrailingClosure(flavor) }) {
1324+
if case .trailingClosure = flavor, self.at(.leftBrace), self.withLookahead({ $0.atValidTrailingClosure(flavor) }) {
13251325
(trailingClosure, additionalTrailingClosures) = self.parseTrailingClosures(flavor)
13261326
} else {
13271327
trailingClosure = nil
@@ -1915,7 +1915,7 @@ extension Parser {
19151915
// Parse labeled trailing closures.
19161916
var elements = [RawMultipleTrailingClosureElementSyntax]()
19171917
var loopProgress = LoopProgressCondition()
1918-
while self.withLookahead({ $0.isStartOfLabelledTrailingClosure() }) && self.hasProgressed(&loopProgress) {
1918+
while self.withLookahead({ $0.atStartOfLabelledTrailingClosure() }) && self.hasProgressed(&loopProgress) {
19191919
let (unexpectedBeforeLabel, label) = self.parseArgumentLabel()
19201920
let (unexpectedBeforeColon, colon) = self.expect(.colon)
19211921
let closure = self.parseClosureExpression()
@@ -1937,7 +1937,7 @@ extension Parser {
19371937
}
19381938

19391939
extension Parser.Lookahead {
1940-
mutating func isStartOfLabelledTrailingClosure() -> Bool {
1940+
mutating func atStartOfLabelledTrailingClosure() -> Bool {
19411941
// Fast path: the next two tokens must be a label and a colon.
19421942
// But 'default:' is ambiguous with switch cases and we disallow it
19431943
// (unless escaped) even outside of switches.
@@ -1967,12 +1967,12 @@ extension Parser.Lookahead {
19671967
/// where the parser requires an expr-basic (which does not allow them). We
19681968
/// handle this by doing some lookahead in common situations. And later, Sema
19691969
/// will emit a diagnostic with a fixit to add wrapping parens.
1970-
mutating func isValidTrailingClosure(_ flavor: Parser.ExprFlavor) -> Bool {
1970+
mutating func atValidTrailingClosure(_ flavor: Parser.ExprFlavor) -> Bool {
19711971
precondition(self.at(.leftBrace), "Couldn't be a trailing closure")
19721972

19731973
// If this is the start of a get/set accessor, then it isn't a trailing
19741974
// closure.
1975-
guard !self.withLookahead({ $0.isStartOfGetSetAccessor() }) else {
1975+
guard !self.withLookahead({ $0.atStartOfGetSetAccessor() }) else {
19761976
return false
19771977
}
19781978

@@ -2149,7 +2149,7 @@ extension Parser {
21492149
while !self.at(.endOfFile, .rightBrace) && !self.at(.poundEndif, .poundElseif, .poundElse)
21502150
&& self.hasProgressed(&elementsProgress)
21512151
{
2152-
if self.withLookahead({ $0.isAtStartOfSwitchCase(allowRecovery: false) }) {
2152+
if self.withLookahead({ $0.atStartOfSwitchCase(allowRecovery: false) }) {
21532153
elements.append(.switchCase(self.parseSwitchCase()))
21542154
} else if self.canRecoverTo(.poundIf) != nil {
21552155
// '#if' in 'case' position can enclose zero or more 'case' or 'default'
@@ -2206,7 +2206,7 @@ extension Parser {
22062206
)
22072207
)
22082208
)
2209-
} else if self.withLookahead({ $0.isAtStartOfSwitchCase(allowRecovery: true) }) {
2209+
} else if self.withLookahead({ $0.atStartOfSwitchCase(allowRecovery: true) }) {
22102210
elements.append(.switchCase(self.parseSwitchCase()))
22112211
} else {
22122212
break
@@ -2217,7 +2217,7 @@ extension Parser {
22172217

22182218
mutating func parseSwitchCaseBody() -> RawCodeBlockItemListSyntax {
22192219
parseCodeBlockItemList(until: {
2220-
$0.at(.rightBrace) || $0.at(.poundEndif, .poundElseif, .poundElse) || $0.withLookahead({ $0.isStartOfConditionalSwitchCases() })
2220+
$0.at(.rightBrace) || $0.at(.poundEndif, .poundElseif, .poundElse) || $0.withLookahead({ $0.atStartOfConditionalSwitchCases() })
22212221
})
22222222
}
22232223

Sources/SwiftParser/Lookahead.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ extension Parser.Lookahead {
246246
// MARK: Lookahead
247247

248248
extension Parser.Lookahead {
249-
mutating func isStartOfGetSetAccessor() -> Bool {
249+
mutating func atStartOfGetSetAccessor() -> Bool {
250250
precondition(self.at(.leftBrace), "not checking a brace?")
251251

252252
// The only case this can happen is if the accessor label is immediately after

Sources/SwiftParser/Statements.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension TokenConsumer {
2525
// misplaced attributes.
2626
_ = lookahead.consumeAttributeList()
2727
}
28-
return lookahead.isStartOfStatement(allowRecovery: allowRecovery)
28+
return lookahead.atStartOfStatement(allowRecovery: allowRecovery)
2929
}
3030
}
3131

@@ -808,7 +808,7 @@ extension Parser.Lookahead {
808808
///
809809
/// - Note: This function must be kept in sync with `parseStatement()`.
810810
/// - Seealso: ``Parser/parseStatement()``
811-
mutating func isStartOfStatement(allowRecovery: Bool = false) -> Bool {
811+
mutating func atStartOfStatement(allowRecovery: Bool = false) -> Bool {
812812
if (self.at(anyIn: SwitchCaseStart.self) != nil || self.at(.atSign)) && withLookahead({ $0.atStartOfSwitchCaseItem() }) {
813813
// We consider SwitchCaseItems statements so we don't parse the start of a new case item as trailing parts of an expression.
814814
return true
@@ -884,7 +884,7 @@ extension Parser.Lookahead {
884884

885885
/// Returns whether the parser's current position is the start of a switch case,
886886
/// given that we're in the middle of a switch already.
887-
mutating func isAtStartOfSwitchCase(allowRecovery: Bool = false) -> Bool {
887+
mutating func atStartOfSwitchCase(allowRecovery: Bool = false) -> Bool {
888888
// Check for and consume attributes. The only valid attribute is `@unknown`
889889
// but that's a semantic restriction.
890890
var lookahead = self.lookahead()
@@ -916,9 +916,9 @@ extension Parser.Lookahead {
916916
}
917917
}
918918

919-
mutating func isStartOfConditionalSwitchCases() -> Bool {
919+
mutating func atStartOfConditionalSwitchCases() -> Bool {
920920
guard self.at(.poundIf) else {
921-
return self.isAtStartOfSwitchCase()
921+
return self.atStartOfSwitchCase()
922922
}
923923

924924
var lookahead = self.lookahead()
@@ -928,6 +928,6 @@ extension Parser.Lookahead {
928928
// just find the end of the line
929929
lookahead.skipUntilEndOfLine()
930930
} while lookahead.at(.poundIf, .poundElseif, .poundElse) && lookahead.hasProgressed(&loopProgress)
931-
return lookahead.isAtStartOfSwitchCase()
931+
return lookahead.atStartOfSwitchCase()
932932
}
933933
}

Sources/SwiftParser/Types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension Parser {
4545
mutating func parseTypeScalar(misplacedSpecifiers: [RawTokenSyntax] = []) -> RawTypeSyntax {
4646
let (specifier, unexpectedBeforeAttrList, attrList) = self.parseTypeAttributeList(misplacedSpecifiers: misplacedSpecifiers)
4747
var base = RawTypeSyntax(self.parseSimpleOrCompositionType())
48-
if self.withLookahead({ $0.isAtFunctionTypeArrow() }) {
48+
if self.withLookahead({ $0.atFunctionTypeArrow() }) {
4949
var effectSpecifiers = self.parseTypeEffectSpecifiers()
5050
let returnClause = self.parseFunctionReturnClause(effectSpecifiers: &effectSpecifiers, allowNamedOpaqueResultType: false)
5151

@@ -623,7 +623,7 @@ extension Parser.Lookahead {
623623
return false
624624
}
625625

626-
if self.isAtFunctionTypeArrow() {
626+
if self.atFunctionTypeArrow() {
627627
// Handle type-function if we have an '->' with optional
628628
// 'async' and/or 'throws'.
629629
var loopProgress = LoopProgressCondition()
@@ -781,7 +781,7 @@ extension Parser.Lookahead {
781781
return self.consume(if: .rightParen) != nil
782782
}
783783

784-
mutating func isAtFunctionTypeArrow() -> Bool {
784+
mutating func atFunctionTypeArrow() -> Bool {
785785
if self.at(.arrow) {
786786
return true
787787
}
@@ -795,7 +795,7 @@ extension Parser.Lookahead {
795795
var backtrack = self.lookahead()
796796
backtrack.consumeAnyToken()
797797
backtrack.consumeAnyToken()
798-
return backtrack.isAtFunctionTypeArrow()
798+
return backtrack.atFunctionTypeArrow()
799799
}
800800

801801
return false

0 commit comments

Comments
 (0)