Created
January 27, 2015 23:58
-
-
Save avwhite/94a76e0718f095d5cfdc to your computer and use it in GitHub Desktop.
This file contains 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
extern crate "parser-combinators" as parser; | |
use parser::{Parser, ParserExt}; | |
fn main() { | |
let good_test = "2 + 12 + 22"; | |
let integer = parser::spaces().with( | |
parser::chars1(parser::digit()).map(|s| s.parse::<i32>().unwrap()) | |
); | |
let plus = parser::spaces().with(parser::string("+")); | |
let mut sum = parser::chainl1(integer, plus.map(|str| | |
Box::new(|&mut: a:i32, b:i32| {a + b}) as Box<FnMut(i32,i32) -> i32> | |
)); | |
match sum.parse(good_test) { | |
Ok((value, _)) => println!("Good! {}", value), | |
Err(err) => println!("{}", err) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment