Created
October 12, 2018 17:21
-
-
Save boxdot/041393bcce6d62eda46e958d7d5f5d68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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