Skip to content

Instantly share code, notes, and snippets.

@danielbodart
Created December 18, 2016 21:17
Show Gist options
  • Select an option

  • Save danielbodart/a129dd091f6ccee65debfab946f4ecd3 to your computer and use it in GitHub Desktop.

Select an option

Save danielbodart/a129dd091f6ccee65debfab946f4ecd3 to your computer and use it in GitHub Desktop.
Rust nom filter macro
#[macro_export]
macro_rules! filter (
($i:expr, $c: expr) => (
{
if $i.is_empty() {
nom::IResult::Incomplete(nom::Needed::Size(1))
} else {
if $c($i[0]) {
nom::IResult::Done(&$i[1..], &$i[0..1])
} else {
nom::IResult::Error(error_position!(nom::ErrorKind::Char, $i))
}
}
}
);
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment