Skip to content

Commit 861333c

Browse files
authored
Merge pull request #1996 from natikgadzhi/swift-parser-is-at
Renamed isAt* funcs to at* in Parser and Parser.Lookahead
2 parents f4dd574 + b76bdbd commit 861333c

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ extension Parser {
354354
/// `copy` etc. are only contextually a keyword if they are followed by an
355355
/// identifier or keyword on the same line. We do this to ensure that we do
356356
/// not break any copy functions defined by users.
357-
private mutating func isContextualExpressionModifier() -> Bool {
357+
private mutating func atContextualExpressionModifier() -> Bool {
358358
return self.peek(
359359
isAt: TokenSpec(.identifier, allowAtStartOfLine: false),
360360
TokenSpec(.dollarIdentifier, allowAtStartOfLine: false),
@@ -444,7 +444,7 @@ extension Parser {
444444
)
445445

446446
case (.copy, let handle)?:
447-
if !isContextualExpressionModifier() {
447+
if !atContextualExpressionModifier() {
448448
break EXPR_PREFIX
449449
}
450450

@@ -463,7 +463,7 @@ extension Parser {
463463
)
464464

465465
case (.consume, let handle)?:
466-
if !isContextualExpressionModifier() {
466+
if !atContextualExpressionModifier() {
467467
break EXPR_PREFIX
468468
}
469469

@@ -486,7 +486,7 @@ extension Parser {
486486
return RawExprSyntax(parsePackExpansionExpr(repeatHandle: handle, flavor, pattern: pattern))
487487

488488
case (.each, let handle)?:
489-
if !isContextualExpressionModifier() {
489+
if !atContextualExpressionModifier() {
490490
break EXPR_PREFIX
491491
}
492492

@@ -501,7 +501,7 @@ extension Parser {
501501
)
502502

503503
case (.any, _)?:
504-
if !isContextualExpressionModifier() {
504+
if !atContextualExpressionModifier() {
505505
break EXPR_PREFIX
506506
}
507507

@@ -874,7 +874,7 @@ extension Parser {
874874
}
875875
} while lookahead.at(.poundIf) && lookahead.hasProgressed(&loopProgress)
876876

877-
guard lookahead.isAtStartOfPostfixExprSuffix() else {
877+
guard lookahead.atStartOfPostfixExprSuffix() else {
878878
break
879879
}
880880
}
@@ -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

@@ -2487,7 +2487,7 @@ extension Parser.Lookahead {
24872487
extension Parser.Lookahead {
24882488
// Helper function to see if we can parse member reference like suffixes
24892489
// inside '#if'.
2490-
fileprivate mutating func isAtStartOfPostfixExprSuffix() -> Bool {
2490+
fileprivate mutating func atStartOfPostfixExprSuffix() -> Bool {
24912491
guard self.at(.period) else {
24922492
return false
24932493
}

Sources/SwiftParser/Nominals.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ extension Parser {
240240
}
241241

242242
let inheritance: RawInheritanceClauseSyntax?
243-
if self.at(.colon) || self.isAtPythonStyleInheritanceClause() {
243+
if self.at(.colon) || self.atPythonStyleInheritanceClause() {
244244
inheritance = self.parseInheritance()
245245
} else {
246246
inheritance = nil
@@ -363,7 +363,7 @@ extension Parser {
363363
}
364364

365365
extension Parser {
366-
private mutating func isAtPythonStyleInheritanceClause() -> Bool {
366+
private mutating func atPythonStyleInheritanceClause() -> Bool {
367367
guard self.at(.leftParen) else { return false }
368368
return self.withLookahead {
369369
$0.consume(if: .leftParen)

Sources/SwiftParser/Parser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@
8888
/// operates on a copy of the lexical stream, no input tokens are lost..
8989
public struct Parser {
9090
var arena: ParsingSyntaxArena
91+
9192
/// A view of the sequence of lexemes in the input.
9293
var lexemes: Lexer.LexemeSequence
94+
9395
/// The current token that should be consumed next.
9496
///
9597
/// If the end of the source file is reached, this is `.endOfFile`.

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)