Skip to content

internal: Improve parser recovery for delimited lists #14128

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 6 commits into from
Feb 14, 2023

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Feb 11, 2023

Closes #11188, #10410, #10173

Should probably be merged after the stable release as this might get the parser stuck if I missed something

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 11, 2023
@Veykril Veykril changed the title fix: Fix path segment recovery eating closing parentheses internal: Improve parser recovery a bunch Feb 11, 2023
@Veykril Veykril marked this pull request as draft February 11, 2023 19:22
@Veykril Veykril changed the title internal: Improve parser recovery a bunch internal: Improve parser recovery for argument lists a bunch Feb 11, 2023
@Veykril Veykril changed the title internal: Improve parser recovery for argument lists a bunch internal: Improve parser recovery for argument lists Feb 12, 2023
@Veykril Veykril marked this pull request as ready for review February 13, 2023 10:06
@Veykril Veykril force-pushed the parser branch 2 times, most recently from 58db469 to 66ca869 Compare February 13, 2023 15:15
@Veykril Veykril changed the title internal: Improve parser recovery for argument lists internal: Improve parser recovery for delimited lists Feb 13, 2023
@Veykril Veykril force-pushed the parser branch 2 times, most recently from 1a0f006 to bb5a5e7 Compare February 13, 2023 15:48
}
if !p.at(delim) {
if p.at_ts(first_set) {
p.error(format!("expected {:?}", delim));
Copy link
Contributor

Choose a reason for hiding this comment

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

[...] as this might get the parser stuck if I missed something

This is related to this right? Just a random unfinished thought: The recovery here is basically unbounded right? Does it make sense to bound it to some hardcoded recovery limit?

Copy link
Member Author

Choose a reason for hiding this comment

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

It assumes that the parser function consumes at least one token if it returns true, if it doesn't then this will lock up. All use sites should work this way though (will add a comment for that behavior)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I thought so :) However, my question was somewhat unrelated to that 😅. I was just wondering whether we shouldn't recover indefinitely. But on second thought that probably doesn't make any sense...

Again, unrelated to the above. IIuc, this

fn test() {
    hello(a <|>
    return 1
    ...
}

will pull the return expr into the arg list right? That's quite unfortunate.

Copy link
Member Author

@Veykril Veykril Feb 14, 2023

Choose a reason for hiding this comment

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

Oh that's what you meant with unbounded 😬. It will yes, but I don't think that's gonna be a problem, in this (broken syntax) spot, the only features that are relevant to the user are signature help and completions, neither of which would break from this (and assuming the return expression is termianted by a semicolon, nothing else after would be consumed either)

@Veykril Veykril force-pushed the parser branch 2 times, most recently from 127bd70 to 109ddec Compare February 14, 2023 12:51
@@ -1126,5 +1126,5 @@ fn benchmark_syntax_highlighting_parser() {
.filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
.count()
};
assert_eq!(hash, 1609);
assert_eq!(hash, 1608);
Copy link
Member Author

Choose a reason for hiding this comment

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

This somehow affects the outcome here, yet the parse trees don't differ on my machine 😕

@Veykril
Copy link
Member Author

Veykril commented Feb 14, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Feb 14, 2023

📌 Commit 4f6b5f4 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 14, 2023

⌛ Testing commit 4f6b5f4 with merge 4456800...

@bors
Copy link
Contributor

bors commented Feb 14, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 4456800 to master...

@bors bors merged commit 4456800 into rust-lang:master Feb 14, 2023
@Veykril Veykril deleted the parser branch February 16, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve parser (recovery) for expressions
4 participants