Skip to content

Instantly share code, notes, and snippets.

View danielbodart's full-sized avatar

Daniel Worthington-Bodart danielbodart

View GitHub Profile
#[macro_export]
macro_rules! optional (
($i:expr, $submac:ident!( $($args:tt)* )) => (
{
opt!($i, complete!($i, $submac!($i, $($args)*)))
}
);
($i:expr, $f:expr) => (
optional!($i, call!($f));
);
pub fn among(characters:&[u8]) -> Box<Fn(u8) -> bool> {
Box::new(move |chr| {
characters.iter().any(chr)
})
}
@danielbodart
danielbodart / filter.rs
Created December 18, 2016 21:17
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 {