Macro synom::call [] [src]

macro_rules! call {
    ($i:expr, $fun:expr $(, $args:expr)*) => { ... };
}

Invoke the given parser function with the passed in arguments.

#[macro_use] extern crate synom;

use synom::IResult;

// Parses any string up to but not including the given character, returning
// the content up to the given character. The given character is required to
// be present in the input string.
fn skip_until(input: &str, ch: char) -> IResult<&str, &str> {
    if let Some(pos) = input.find(ch) {
        IResult::Done(&input[pos..], &input[..pos])
    } else {
        IResult::Error
    }
}

// Parses any string surrounded by tilde characters '~'. Returns the content
// between the tilde characters.
named!(surrounded_by_tilde -> &str, delimited!(
    punct!("~"),
    call!(skip_until, '~'),
    punct!("~")
));

fn main() {
    let input = "~ abc def ~";

    let inner = surrounded_by_tilde(input).expect("surrounded by tilde");

    println!("{:?}", inner);
}