-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
take_until
equivalent combinator
#436
Comments
Here is what I have so far:- impl Synom for ToComma {
fn parse(mut rest: Cursor) -> PResult<Self> {
let mut tokens = Vec::new();
while let Some((tree, cursor)) = rest.token_tree() {
rest = cursor;
if let TokenTree::Punct(p) = tree.clone() {
if p.as_char() == ',' {
break;
}
}
tokens.push(tree);
}
let stream = TokenStream::from_iter(tokens);
Ok((ToComma(stream), rest))
}
fn description() -> Option<&'static str> {
Some("token stream to comma")
}
}
EDIT: Never mind. This parser is actually working as expected. The final parser used in tests has to consume all tokens, otherwise it will be seen as a failure. Now I simply need to know if there is already a way to do this in |
Here is the final version (in case someone is interested):- impl Synom for ToComma {
fn parse(mut rest: Cursor) -> PResult<Self> {
let mut tokens = Vec::new();
while let Some((tree, cursor)) = rest.token_tree() {
if let TokenTree::Punct(p) = tree.clone() {
if p.as_char() == ',' {
if !tokens.is_empty() {
break;
}
}
}
rest = cursor;
tokens.push(tree);
}
let stream = TokenStream::from_iter(tokens);
Ok((ToComma(stream), rest))
}
fn description() -> Option<&'static str> {
Some("token stream to comma")
}
} |
What's
synom
's equivalent combinator fortake_until
, if any? If none, how can it be achieved? I want a way to grab everything in a token stream until I reach a comma.The text was updated successfully, but these errors were encountered: