-
Notifications
You must be signed in to change notification settings - Fork 441
Improve recovery of dollar identifiers #998
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,7 +398,9 @@ extension Parser { | |
var keepGoing = true | ||
var loopProgress = LoopProgressCondition() | ||
while !self.at(any: [.eof, .rightParen]) && keepGoing && loopProgress.evaluate(currentToken) { | ||
let unexpectedBeforeFirst: RawUnexpectedNodesSyntax? | ||
let first: RawTokenSyntax? | ||
let unexpectedBeforeSecond: RawUnexpectedNodesSyntax? | ||
let second: RawTokenSyntax? | ||
let unexpectedBeforeColon: RawUnexpectedNodesSyntax? | ||
let colon: RawTokenSyntax? | ||
|
@@ -407,21 +409,25 @@ extension Parser { | |
while let specifier = self.consume(ifAnyIn: TypeSpecifier.self) { | ||
misplacedSpecifiers.append(specifier) | ||
} | ||
first = self.parseArgumentLabel() | ||
(unexpectedBeforeFirst, first) = self.parseArgumentLabel() | ||
if let parsedColon = self.consume(if: .colon) { | ||
unexpectedBeforeSecond = nil | ||
second = nil | ||
unexpectedBeforeColon = nil | ||
colon = parsedColon | ||
} else if self.currentToken.canBeArgumentLabel && self.peek().tokenKind == .colon { | ||
second = self.parseArgumentLabel() | ||
} else if self.currentToken.canBeArgumentLabel(allowDollarIdentifier: true) && self.peek().tokenKind == .colon { | ||
(unexpectedBeforeSecond, second) = self.parseArgumentLabel() | ||
(unexpectedBeforeColon, colon) = self.expect(.colon) | ||
} else { | ||
unexpectedBeforeSecond = nil | ||
second = nil | ||
unexpectedBeforeColon = nil | ||
colon = RawTokenSyntax(missing: .colon, arena: self.arena) | ||
} | ||
} else { | ||
unexpectedBeforeFirst = nil | ||
first = nil | ||
unexpectedBeforeSecond = nil | ||
second = nil | ||
unexpectedBeforeColon = nil | ||
colon = nil | ||
|
@@ -459,8 +465,9 @@ extension Parser { | |
keepGoing = trailingComma != nil | ||
elements.append(RawTupleTypeElementSyntax( | ||
inOut: nil, | ||
RawUnexpectedNodesSyntax(misplacedSpecifiers, arena: self.arena), | ||
RawUnexpectedNodesSyntax(misplacedSpecifiers.map(RawSyntax.init) + (unexpectedBeforeFirst?.elements ?? []), arena: self.arena), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a bunch of places we're doing things like this now. Couldn't we just return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think I like the idea of changing the parameters of all raw nodes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've commented in that PR. Personally I'd find having all |
||
name: first, | ||
unexpectedBeforeSecond, | ||
secondName: second, | ||
unexpectedBeforeColon, | ||
colon: colon, | ||
|
@@ -626,7 +633,7 @@ extension Parser.Lookahead { | |
// by a type annotation. | ||
if self.startsParameterName(isClosure: false, allowMisplacedSpecifierRecovery: false) { | ||
self.consumeAnyToken() | ||
if self.currentToken.canBeArgumentLabel { | ||
if self.currentToken.canBeArgumentLabel() { | ||
self.consumeAnyToken() | ||
guard self.at(.colon) else { | ||
return false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it would be cleaner to just do
Or maybe not 🤷.