Skip to content

Migrate !currentToken.isStartOfLine to TokenSpec(allowStartOfLine: false) #1776

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 1 commit into from
Jun 14, 2023
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
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ extension Parser {
let (unexpectedBeforeDeinitKeyword, deinitKeyword) = self.eat(handle)
var unexpectedNameAndSignature: [RawSyntax?] = []
unexpectedNameAndSignature.append(self.consume(if: TokenSpec(.identifier, allowAtStartOfLine: false)).map(RawSyntax.init))
if self.at(.leftParen) && !self.currentToken.isAtStartOfLine {
if self.at(TokenSpec(.leftParen, allowAtStartOfLine: false)) {
unexpectedNameAndSignature.append(RawSyntax(parseFunctionSignature()))
}
let items = self.parseOptionalCodeBlock()
Expand Down Expand Up @@ -1374,7 +1374,7 @@ extension Parser {
value: value,
arena: self.arena
)
} else if self.at(.leftParen), !self.currentToken.isAtStartOfLine,
} else if self.at(TokenSpec(.leftParen, allowAtStartOfLine: false)),
let typeAnnotationUnwrapped = typeAnnotation
{
// If we have a '(' after the type in the annotation, the type annotation
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ extension Parser {

let beforePeriodWhitespace = previousNode?.raw.trailingTriviaByteLength ?? 0 > 0 || self.currentToken.leadingTriviaByteLength > 0
let afterPeriodWhitespace = self.currentToken.trailingTriviaByteLength > 0 || self.peek().leadingTriviaByteLength > 0
let afterContainsAnyNewline = self.peek().flags.contains(.isAtStartOfLine)
let afterContainsAnyNewline = self.peek().isAtStartOfLine

let period = self.consumeAnyToken()

Expand Down
24 changes: 10 additions & 14 deletions Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,13 @@ extension Parser {
continue
}

if !self.currentToken.isAtStartOfLine {
if self.at(.postfixQuestionMark) {
base = RawTypeSyntax(self.parseOptionalType(base))
continue
}
if self.at(.exclamationMark) {
base = RawTypeSyntax(self.parseImplicitlyUnwrappedOptionalType(base))
continue
}
if self.at(TokenSpec(.postfixQuestionMark, allowAtStartOfLine: false)) {
base = RawTypeSyntax(self.parseOptionalType(base))
continue
}
if self.at(TokenSpec(.exclamationMark, allowAtStartOfLine: false)) {
base = RawTypeSyntax(self.parseImplicitlyUnwrappedOptionalType(base))
continue
}

break
Expand Down Expand Up @@ -780,11 +778,9 @@ extension Parser.Lookahead {
return false
}

if !self.currentToken.isAtStartOfLine {
if self.at(.postfixQuestionMark) || self.at(.exclamationMark) {
self.consumeAnyToken()
continue
}
if self.at(TokenSpec(.postfixQuestionMark, allowAtStartOfLine: false)) || self.at(TokenSpec(.exclamationMark, allowAtStartOfLine: false)) {
self.consumeAnyToken()
continue
}

break
Expand Down