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

Analog of delimited_by with better error generation #715

Open
Hedgehogo opened this issue Jan 7, 2025 · 1 comment
Open

Analog of delimited_by with better error generation #715

Hedgehogo opened this issue Jan 7, 2025 · 1 comment

Comments

@Hedgehogo
Copy link
Contributor

I would like to have an analog of delimited_by, which would allow to pass to the error that occurred when the closing parser worked, information about how the opening parser worked, most often span, the dumbest way to do it -
inner.xxx(just(“(”“), |span| just(”“)”).map_err(|e: Error| Error::new(Expected::TupleClose(OpenBracket::new(span.clone())), e.found(), e.span()). But clearly there is a more elegant solution using the abstractions we already have.

@zesterer
Copy link
Owner

zesterer commented Feb 1, 2025

So this actually existed in 0.9: Error had a dedicated method for unclosed delimiters and the nested_delimiters recovery strategy would make use of it.

We could do exactly the same thing in 1.0: perhaps if this is something you'd be happy with, we can go right ahead and just implement that. My feeling is that there might be space to add something that allows for more fine-grained control over the final error though, perhaps via the labelling system, allowing the unclosed delimiter to become an extra annotation on top of the existing error (i.e: a new method that sits alongside LabelError::in_context).

Interested to know your thoughts!

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

No branches or pull requests

2 participants