diff --git a/examples/fz-parser.rs b/examples/fz-parser.rs index 22914b9..76da09e 100644 --- a/examples/fz-parser.rs +++ b/examples/fz-parser.rs @@ -30,10 +30,13 @@ fn run() -> Result<()> { let opt = Opt::parse(); let buf = std::fs::read_to_string(opt.file)?; for mut line in buf.lines() { - match flatzinc::statement::>(&mut line) { + match flatzinc::statement::, &str>(&mut line) { Ok(result) => println!("{:#?}", result), Err(e) => { - error!("Failed to parse flatzinc!\n{}", e) + let a = e.to_owned().into_inner(); + let b = a.cause(); + let c = e.to_owned().offset(); + error!("Failed to parse flatzinc!\n{} {:?} {:?}", c, a, b) } } } diff --git a/src/statements/mod.rs b/src/statements/mod.rs index 4cd25be..4c32241 100644 --- a/src/statements/mod.rs +++ b/src/statements/mod.rs @@ -1,6 +1,6 @@ use winnow::{ combinator::{alt, eof}, - error::{FromExternalError, ParserError}, + error::{FromExternalError, ParseError, ParserError}, PResult, Parser, }; @@ -26,12 +26,14 @@ pub enum Stmt { SolveItem(SolveItem), } -pub fn statement<'a, E: ParserError<&'a str>>(input: &mut &'a str) -> PResult +pub fn statement<'a, E: ParserError<&'a str>, I>( + input: &'a str, +) -> Result> where E: FromExternalError<&'a str, std::num::ParseIntError> + FromExternalError<&'a str, std::num::ParseFloatError>, { - let res = alt(( + alt(( stmt_predicate, stmt_parameter, stmt_variable, @@ -39,9 +41,7 @@ where stmt_solve_item, space_or_comment, )) - .parse_next(input)?; - eof.parse_next(input)?; - Ok(res) + .parse(input) } fn stmt_predicate<'a, E: ParserError<&'a str>>(input: &mut &'a str) -> PResult