Skip to content

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

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 21, 2022

I believe that the remaining diagnostics need to be diagnosed in the lexer.

@ahoppen ahoppen requested a review from bnbarham October 21, 2022 10:51
@ahoppen ahoppen force-pushed the ahoppen/dollar-recovery branch from 9abddc8 to a0b5580 Compare October 21, 2022 10:52
@ahoppen
Copy link
Member Author

ahoppen commented Oct 21, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit a61c91e into swiftlang:main Oct 21, 2022
@ahoppen ahoppen deleted the ahoppen/dollar-recovery branch October 21, 2022 15:14
let unexpectedBeforeLabel: RawUnexpectedNodesSyntax?
let label: RawTokenSyntax?
let colon: RawTokenSyntax?
if let labelAndColon = self.consume(if: { $0.canBeArgumentLabel() }, followedBy: { $0.tokenKind == .colon }) {
Copy link
Contributor

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

if currentToken.canBeArgumentLabel(allowDollarIdentifier: true) && peek().tokenKind == .colon {
  (unexpectedBeforeLabel, label) = parseArgumentLabel()
  colon = consumeAnyToken()
}

Or maybe not 🤷.

@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The 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 [RawSyntax] any calls that return unexpected + make all the unexpected parameters [RawSyntax] instead? That would both avoid creating unexpected nodes that aren't removed + avoid looking into them to grab elements.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 RawUnexpectedNodesSyntax to RawSyntax (incidentally that would also prevent us from using all the convenience initializer on RawUnexpectedNodesSyntax we currently have (e.g. the one taking [RawSyntax?]). I put together #1005. I’m not entirely sure whether I like the change yet because it does add as bit of complexity on the declaration side, but the call side is rather nice. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commented in that PR. Personally I'd find having all [RawSyntax] more convenient than the [RawSyntax?] convenience initializer. Though I haven't actually checked how many places that's being used, so maybe that wouldn't be the case. Anyway, that PR is better than the status quo so I'd be fine with merging that in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants