-
Notifications
You must be signed in to change notification settings - Fork 94
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
Example of higher order parser generating functions. #66
Comments
Ah, I used to be generic over the stream type, but elsewhere I followed an example for the
This is with |
It appears that // Fn -> Parser
pub fn keyword(kw: &'static str) -> Box<Parser<Input = &str, Output = ()>
{
use combine::{ParserExt, string, value};
assert!(KEYWORDS.contains(&kw));
// Remove the closure
Box::new(string(kw)
.with(value(())))
} Just be aware that boxing incurs a runtime cost (allocation + indirection) so if you want the best performance you should avoid it as much as possible (once rust-lang/rust#35091 becomes stable creating higher order parsers should be much more convenient as well!). |
Thanks, this indeed fixes all type errors. This is my first use of a trait object. |
Happy to be of help! |
I'm having trouble implementing higher order functions that create parsers. My latest attempt looks like this:
Later I want to compose
keyword
in different ways. Here's an attempted use in a unit test:Variations on the types I've tried include:
Box<…>
from the return value ofkeyword
-Sized
is not satisfied.keyword("let")
-Sized
is not satisfied.How can I make this work?
Note: if there's a better way to implement
keyword
itself, that's of secondary interest. My primary interest is to learn how to create higher order parser generators.The text was updated successfully, but these errors were encountered: