-
Notifications
You must be signed in to change notification settings - Fork 4
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
Rewrite the whole combinators module to use HRTB only where necessary. #1
Conversation
let RPAREN = string(")").map(|_| RParen); | ||
let WHITESPACE = character(char::is_whitespace).map(|_| Whitespace); | ||
let IDENTIFIER = character(char::is_alphabetic).and_then(character(char::is_alphanumeric).star()) | ||
.buffer().map(mk_identifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use Identifier
here, I get an ICE. I will try to reduce and submit a Rust issue.
OK, this is really cool. The crucial trick seems to be not mentioning the target type in I added a test to make sure it works with different lifetimes:
Interestingly, it passes with a named function, but not with an anonymous function, which is a bit annoying, and may be related to the issue with the lexer you were mentioning above. Anyway, thanks for all the work, the parser combinators are a lot slicker now! |
Rewrite the whole combinators module to use HRTB only where necessary.
Hmm, I realized that there's a problem with ParserConsumer.
The problem is that the parser producer is getting to pick the lifetime 'a. Really the consumer should be picking that lifetime, not the producer. I think parser producers are going to have to be specialized, so no generic |
The trait is fine, it's just how you #[test]
fn test_parser_consumer() {
fn mk_parser<'a,C,D>(mut consumer: C)
where C: ParserConsumer<&'a str,D>, D: for<'b> Consumer<&'b str> {
fn tail(x:&str) -> &str { &x[1..] }
consumer.accept(string("abc").buffer().map(tail));
}
struct TestConsumer<'a>(&'a str);
impl<'a> ParserConsumer<&'a str, String> for TestConsumer<'a> {
fn accept<P>(&mut self, mut parser: P) where P: ParseTo<&'a str,String> {
let mut result = String::new();
assert_eq!(parser.push_to(self.0, &mut result), Matched(Some("d")));
assert_eq!(result, "bc");
}
}
mk_parser::<TestConsumer,String>(TestConsumer("abcd"));
} |
Most of the changes are straight-forward, except for the
Fn<(T,)>
workaround for rust-lang/rust#30867, which requires the two feature-gates.