Skip to content

Reduce usage of currentToken #1909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Parser {
repeat {
let attribute = self.parseAttribute()
elements.append(attribute)
} while self.at(.atSign, .poundIf) && loopProgress.evaluate(currentToken)
} while self.at(.atSign, .poundIf) && self.hasProgressed(&loopProgress)
return RawAttributeListSyntax(elements: elements, arena: self.arena)
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ extension Parser {

var elements = [RawDifferentiabilityParamSyntax]()
var loopProgress = LoopProgressCondition()
while !self.at(.endOfFile, .rightParen) && loopProgress.evaluate(currentToken) {
while !self.at(.endOfFile, .rightParen) && self.hasProgressed(&loopProgress) {
guard let param = self.parseDifferentiabilityParameter() else {
break
}
Expand Down Expand Up @@ -594,7 +594,7 @@ extension Parser {
mutating func parseObjectiveCSelector() -> RawObjCSelectorSyntax {
var elements = [RawObjCSelectorPieceSyntax]()
var loopProgress = LoopProgressCondition()
while loopProgress.evaluate(currentToken) {
while self.hasProgressed(&loopProgress) {
// Empty selector piece.
if let colon = self.consume(if: .colon) {
elements.append(
Expand Down Expand Up @@ -676,7 +676,7 @@ extension Parser {
var elements = [RawSpecializeAttributeSpecListSyntax.Element]()
// Parse optional "exported" and "kind" labeled parameters.
var loopProgress = LoopProgressCondition()
while !self.at(.endOfFile, .rightParen, .keyword(.where)) && loopProgress.evaluate(currentToken) {
while !self.at(.endOfFile, .rightParen, .keyword(.where)) && self.hasProgressed(&loopProgress) {
switch self.at(anyIn: SpecializeParameter.self) {
case (.target, let handle)?:
let ident = self.eat(handle)
Expand Down Expand Up @@ -1023,7 +1023,7 @@ extension Parser {
let (unexpectedBeforeColon, colon) = self.expect(.colon)
let base: RawTokenSyntax
let args: RawDeclNameArgumentsSyntax?
if label.isMissing && colon.isMissing && self.currentToken.isAtStartOfLine {
if label.isMissing && colon.isMissing && self.atStartOfLine {
base = RawTokenSyntax(missing: .identifier, arena: self.arena)
args = nil
} else {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftParser/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && availabilityArgumentProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&availabilityArgumentProgress)
}

return RawAvailabilitySpecListSyntax(elements: elements, arena: self.arena)
Expand Down Expand Up @@ -99,7 +99,7 @@ extension Parser {
var elements = [RawAvailabilityArgumentSyntax]()
var keepGoing: RawTokenSyntax? = nil

var loopProgressCondition = LoopProgressCondition()
var loopProgress = LoopProgressCondition()
LOOP: repeat {
let entry: RawAvailabilityArgumentSyntax.Entry
switch self.at(anyIn: AvailabilityArgumentKind.self) {
Expand Down Expand Up @@ -176,7 +176,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgressCondition.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
return RawAvailabilitySpecListSyntax(elements: elements, arena: self.arena)
}

Expand Down Expand Up @@ -266,7 +266,7 @@ extension Parser {
unexpectedTokens.append(unexpectedVersion)
}
keepGoing = self.consume(if: .period)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
return RawUnexpectedNodesSyntax(unexpectedTokens, arena: self.arena)
}

Expand Down
30 changes: 15 additions & 15 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension TokenConsumer {

var hasAttribute = false
var attributeProgress = LoopProgressCondition()
while attributeProgress.evaluate(subparser.currentToken) && subparser.at(.atSign) {
while subparser.hasProgressed(&attributeProgress) && subparser.at(.atSign) {
hasAttribute = true
_ = subparser.consumeAttributeList()
}
Expand All @@ -71,7 +71,7 @@ extension TokenConsumer {
var modifierProgress = LoopProgressCondition()
while let (modifierKind, handle) = subparser.at(anyIn: DeclarationModifier.self),
modifierKind != .class,
modifierProgress.evaluate(subparser.currentToken)
subparser.hasProgressed(&modifierProgress)
{
hasModifier = true
subparser.eat(handle)
Expand Down Expand Up @@ -356,7 +356,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
return RawImportPathSyntax(elements: elements, arena: self.arena)
}
}
Expand Down Expand Up @@ -486,7 +486,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
}

let whereClause: RawGenericWhereClauseSyntax?
Expand Down Expand Up @@ -692,7 +692,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
}

return RawGenericWhereClauseSyntax(
Expand Down Expand Up @@ -758,8 +758,8 @@ extension Parser {
let (unexpectedBeforeLBrace, lbrace) = self.expect(.leftBrace)
do {
var loopProgress = LoopProgressCondition()
while !self.at(.endOfFile, .rightBrace) && loopProgress.evaluate(currentToken) {
let newItemAtStartOfLine = self.currentToken.isAtStartOfLine
while !self.at(.endOfFile, .rightBrace) && self.hasProgressed(&loopProgress) {
let newItemAtStartOfLine = self.atStartOfLine
guard let newElement = self.parseMemberDeclListItem() else {
break
}
Expand Down Expand Up @@ -858,7 +858,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
}

return RawEnumCaseDeclSyntax(
Expand Down Expand Up @@ -1341,7 +1341,7 @@ extension Parser {
value: initExpr,
arena: self.arena
)
} else if self.atStartOfExpression(), !self.at(.leftBrace), !self.currentToken.flags.contains(.isAtStartOfLine) {
} else if self.atStartOfExpression(), !self.at(.leftBrace), !self.atStartOfLine {
let missingEqual = RawTokenSyntax(missing: .equal, arena: self.arena)
let expr = self.parseExpression()
initializer = RawInitializerClauseSyntax(
Expand Down Expand Up @@ -1376,7 +1376,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && loopProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
}

return RawVariableDeclSyntax(
Expand Down Expand Up @@ -1521,7 +1521,7 @@ extension Parser {
var elements = [RawAccessorDeclSyntax]()
do {
var loopProgress = LoopProgressCondition()
while !self.at(.endOfFile, .rightBrace) && loopProgress.evaluate(currentToken) {
while !self.at(.endOfFile, .rightBrace) && self.hasProgressed(&loopProgress) {
guard let introducer = self.parseAccessorIntroducer() else {
// There can only be an implicit getter if no other accessors were
// seen before this one.
Expand Down Expand Up @@ -1741,7 +1741,7 @@ extension Parser {
while (identifiersAfterOperatorName.last ?? name).trailingTriviaByteLength == 0,
self.currentToken.leadingTriviaByteLength == 0,
!self.at(.colon, .leftBrace, .endOfFile),
loopProgress.evaluate(self.currentToken)
self.hasProgressed(&loopProgress)
{
identifiersAfterOperatorName.append(consumeAnyToken())
}
Expand Down Expand Up @@ -1888,7 +1888,7 @@ extension Parser {
var elements = [RawPrecedenceGroupAttributeListSyntax.Element]()
do {
var attributesProgress = LoopProgressCondition()
LOOP: while !self.at(.endOfFile, .rightBrace) && attributesProgress.evaluate(currentToken) {
LOOP: while !self.at(.endOfFile, .rightBrace) && self.hasProgressed(&attributesProgress) {
switch self.at(anyIn: LabelText.self) {
case (.associativity, let handle)?:
let associativity = self.eat(handle)
Expand Down Expand Up @@ -1952,7 +1952,7 @@ extension Parser {
arena: self.arena
)
)
} while keepGoing != nil && namesProgress.evaluate(currentToken)
} while keepGoing != nil && self.hasProgressed(&namesProgress)
}
elements.append(
.precedenceGroupRelation(
Expand Down Expand Up @@ -2050,7 +2050,7 @@ extension Parser {
}
var unexpectedBeforeMacro: RawUnexpectedNodesSyntax?
var macro: RawTokenSyntax
if !self.currentToken.isAtStartOfLine {
if !self.atStartOfLine {
(unexpectedBeforeMacro, macro) = self.expectIdentifier(allowKeywordsAsIdentifier: true)
if macro.leadingTriviaByteLength != 0 {
unexpectedBeforeMacro = RawUnexpectedNodesSyntax(combining: unexpectedBeforeMacro, macro, arena: self.arena)
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftParser/Directives.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension Parser {

// Proceed to parse #if continuation clauses (#elseif, #else, check #elif typo, #endif)
var loopProgress = LoopProgressCondition()
LOOP: while let (match, handle) = self.canRecoverTo(anyIn: IfConfigContinuationClauseStartKeyword.self), loopProgress.evaluate(self.currentToken) {
LOOP: while let (match, handle) = self.canRecoverTo(anyIn: IfConfigContinuationClauseStartKeyword.self), self.hasProgressed(&loopProgress) {
var unexpectedBeforePound: RawUnexpectedNodesSyntax?
var pound: RawTokenSyntax
let condition: RawExprSyntax?
Expand Down Expand Up @@ -207,9 +207,9 @@ extension Parser {
while !self.at(.endOfFile)
&& !self.at(.poundElse, .poundElseif, .poundEndif)
&& !self.atElifTypo()
&& elementsProgress.evaluate(currentToken)
&& self.hasProgressed(&elementsProgress)
{
let newItemAtStartOfLine = self.currentToken.isAtStartOfLine
let newItemAtStartOfLine = self.atStartOfLine
guard let element = parseElement(&self, elements.isEmpty), !element.isEmpty else {
break
}
Expand Down
Loading