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
Returning the entire slice matched by a chain of parsers #55
Comments
There are two solutions to this: a) move The first method is more flexible and should result in almost the exact same code unless the backtracking operation of the fn identifier<I: U8Input>(i: I) -> SimpleResult<I, I::Buffer> {
matched_by(i, parser!{
satisfy(is_alpha);
skip_while(is_alphanumeric)
}).map(|(b, _)| b)
} Note the change from The stateful closure is straightforward too, but not as clean (but could be more useful in certain situations since fn identifier<I: U8Input>(i: I) -> SimpleResult<I, I::Buffer> {
let mut first = true;
take_while1(i, |c| if first { first = false; is_alpha(c) } else { is_alphanumeric(c) })
} EDIT: Fixed typo Hope this helps! |
Thank you, that helps a lot! That's the solution I was looking for with |
As suggested in m4rw3r/chomp#55
Awesome! :) |
Is there a clean way to use the
parse!
macro and return the entire slice that was matched? Currently, I do something like this:It would be nicer if
alias
didn't have to usematched_by
and could just saylet left = identifier()
. Does chomp provide a good way of doing this?The text was updated successfully, but these errors were encountered: