Skip to content

Instantly share code, notes, and snippets.

@peckpeck
Last active July 12, 2019 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peckpeck/8cc405c70f00433a247d350c17fc122f to your computer and use it in GitHub Desktop.
Save peckpeck/8cc405c70f00433a247d350c17fc122f to your computer and use it in GitHub Desktop.
macro_rules! sequence {
( { $($f:ident : $parser:expr;)* } => $output:expr ) => {
move |i| {
$(
let (i,$f) = $parser (i)?;
)*
Ok((i, $output))
}
};
}
// example
fn one_or_two_lines(i: &str) -> IResult<&str,(&str,Option<&str>)> {
sequence!(
{
a: terminated(take_until("\n"),tag("\n"));
b: opt(take_until("\n"));
} => (a,b)
)(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment