Skip to content

Commit

Permalink
Test ParserError
Browse files Browse the repository at this point in the history
  • Loading branch information
sthiele committed Nov 20, 2023
1 parent 46198a7 commit 1eabb5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions examples/fz-parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ContextError<&str>>(&mut line) {
match flatzinc::statement::<ContextError<&str>, &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)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/statements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use winnow::{
combinator::{alt, eof},
error::{FromExternalError, ParserError},
error::{FromExternalError, ParseError, ParserError},
PResult, Parser,
};

Expand All @@ -26,22 +26,22 @@ pub enum Stmt {
SolveItem(SolveItem),
}

pub fn statement<'a, E: ParserError<&'a str>>(input: &mut &'a str) -> PResult<Stmt, E>
pub fn statement<'a, E: ParserError<&'a str>, I>(
input: &'a str,
) -> Result<Stmt, ParseError<&'a str, E>>
where
E: FromExternalError<&'a str, std::num::ParseIntError>
+ FromExternalError<&'a str, std::num::ParseFloatError>,
{
let res = alt((
alt((
stmt_predicate,
stmt_parameter,
stmt_variable,
stmt_constraint,
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<Stmt, E>
Expand Down

0 comments on commit 1eabb5d

Please sign in to comment.