Skip to content
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

When tokenising, use semi-colons to hint error recovery #31528

Closed
nrc opened this issue Feb 10, 2016 · 2 comments
Closed

When tokenising, use semi-colons to hint error recovery #31528

nrc opened this issue Feb 10, 2016 · 2 comments
Labels
A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@nrc
Copy link
Member

nrc commented Feb 10, 2016

e.g.,

pub fn trace_option(option: Option<isize>) {
    option.map(|some| 42;
}

When we hit }, we know that the delimiters are mismatched, we currently close all the token trees to recover, but that then gives us a bunch of errors in parsing. We should rewind to the ; and treat that kind of like an EOF, closing the ( and then continuing to tokenise from the ;.

Annoyingly we can't do this eagerly since ; could always be expected. For parens though, this can only happen in macros, so I think for error recovery we can assume the ; terminates a token tree.

We could do better by tracking whether we are in macro context during tokenising.

@nrc nrc added the A-parser Area: The parsing of Rust source code to an AST label Feb 10, 2016
@oli-obk
Copy link
Contributor

oli-obk commented Feb 16, 2016

What about the semi-colon in array types and repeat expressions? Won't those complicate things?

@nrc
Copy link
Member Author

nrc commented Feb 16, 2016

We would only do this when we know we are outside {} and [] (using the token tree rules).

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 24, 2017
bors added a commit that referenced this issue Feb 7, 2019
Deduplicate mismatched delimiter errors

Delay unmatched delimiter errors until after the parser has run to deduplicate them when parsing and attempt recovering intelligently.

Second attempt at #54029, follow up to #53949. Fix #31528.
bors added a commit that referenced this issue Feb 8, 2019
Deduplicate mismatched delimiter errors

Delay unmatched delimiter errors until after the parser has run to deduplicate them when parsing and attempt recovering intelligently.

Second attempt at #54029, follow up to #53949. Fix #31528.
bors added a commit that referenced this issue Feb 9, 2019
Deduplicate mismatched delimiter errors

Delay unmatched delimiter errors until after the parser has run to deduplicate them when parsing and attempt recovering intelligently.

Second attempt at #54029, follow up to #53949. Fix #31528.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants