Skip to content

Instantly share code, notes, and snippets.

@boxdot
Created October 12, 2018 17:21
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 boxdot/041393bcce6d62eda46e958d7d5f5d68 to your computer and use it in GitHub Desktop.
Save boxdot/041393bcce6d62eda46e958d7d5f5d68 to your computer and use it in GitHub Desktop.
#[macro_use]
extern crate nom;
use nom::alpha;
use nom::types::CompleteStr;
use nom::ErrorKind;
named!(block<CompleteStr, Vec<(CompleteStr, CompleteStr)>>,
do_parse!(
tag!("BEGIN") >>
char!('\n') >>
lines: return_error!(ErrorKind::Custom(0),many0!(line)) >>
return_error!(ErrorKind::Custom(1), tag!("END")) >>
char!('\n') >>
(lines)
));
named!(line<CompleteStr, (CompleteStr, CompleteStr)>,
do_parse!(
a: alpha >>
char!(',') >>
b: alpha >>
char!('\n') >>
(a, b)
));
fn main() {
const INPUT: &str = r#"BEGIN
hello,world
fo
END
"#;
let res = block(CompleteStr(INPUT));
println!("{:?}", res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment