-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
lookahead1 is_empty, or Peek for Nothing #1550
Comments
This would probably be achievable without breaking changes by adding a |
I'd very much like something like that but, @dtolnay repeatedly argued against adding a way to peek for EOF, e.g., AFAICT it would be trivial for syn to add an I guess another solution would be to allow people to implement |
Yeah peeking is simply not appropriate for EOF. Peek is normally used for ascertaining whether a particular pattern of tokens would successfully parse if parsed from the input in a given order: EOF is a different question than this because asking whether Ultimately, forking and parsing the tokens in the desired order is the foolproof way to ascertain whether they will parse successfully if parsed in that order. |
I'm puzzled. You seem to be explaining that if there was a But that doesn't seem to apply to Right now I do this:
But this produces inaccurate error messages because the
|
My last comment was in response to ModProg's ping and "I'd very much like something like that" (
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `@`
--> src/lib.rs:1:19
|
1 | fn f() -> i32 { 1 @ }
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
error: expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found `@`
--> src/lib.rs:2:25
|
2 | fn g() -> [i32; 1] { [1 @] }
| ^ expected one of `,`, `.`, `;`, `?`, `]`, or an operator |
Sorry, my comment was probably snarkier than it had to be, I did not consider non-delimited groups. If I understand that correctly, this would always be a problem while parsing, right? If I have I think having an |
Maybe |
I think it's impossible to have a ParseStream with the tokens you showed and with the cursor at the position you showed. The issue is rather |
After looking at both the peek2 and Cursor impls, I understand what you mean, So to support a peek like that, one would need to handle non-delimited groups explicitly (I think one would need to call |
#1625 solved the problematic case described in #1550 (comment). Separately, #1680 + #1681 added a way that Lookahead1 will be able to report the correct closing delimiter at the end of a group per #1550 (comment). I think this is ready to move forward if someone can provide realistic example code for the docs. Preferably 2 examples: one with |
Ideally I would be able to say
But
Lookahead
doesn't have anis_empty()
method. And.peek
doesn't work, I think just becauseNothing
isn'tCopy
.I can use
input.is_empty()
but of course that doesn't note in the error message that empty input was permissible.The text was updated successfully, but these errors were encountered: