-
Notifications
You must be signed in to change notification settings - Fork 30
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
Feature request: Support .clone() #55
Comments
The parser contains a box of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a simple sample program that uses Pom to decode a list of ranges, like "30-42,10-40".
To parse an integer it adapts number() from the sample code:
Then it uses this like
Notice it must call pinteger() twice. This is to make the borrow checker happy, but it also makes sense because (I expect?) each positive() will need internal state.
What if instead the Parser objects supported .clone() and/or Copy? Then it would not need to execute the code in positive() every time, and also the "fn"s and their <'a> boilerplate would be unnecessary. For example the code could just say:
let integerPattern = one_of("123456789") - one_of("0123456789").repeat(0..) | sym('0');
let positive = integerPattern.collect().convert(|s|String::from_iter(s.iter()).parse::())
let range = positive.clone() - sym('-') + positive.clone()
This is a lot less typing because the signatures are not needed.
The text was updated successfully, but these errors were encountered: