Enum parser_compose::ErrorTree
source · pub enum ErrorTree {
Or {
pos: usize,
left: Box<ErrorTree>,
right: Box<ErrorTree>,
},
Predicate {
pos: usize,
},
Fold {
pos: usize,
child: Box<ErrorTree>,
matched: usize,
lower_bound: usize,
upper_bound: Option<usize>,
},
Peeked {
pos: usize,
child: Box<ErrorTree>,
},
NotPeeked {
pos: usize,
},
AndThen {
pos: usize,
callback_error: Box<dyn Error>,
},
Sequence {
pos: usize,
position_in_sequence: usize,
child: Box<ErrorTree>,
},
Label {
pos: usize,
label: &'static str,
child: Box<ErrorTree>,
},
Mismatch {
expected: String,
pos: usize,
},
Custom {
pos: usize,
child: Box<ErrorTree>,
err: Box<dyn Error>,
},
}Expand description
The error type returned when parsers fail.
This is a tree-like structure where nodes represent specific parsers or combinators that failed.
Here is an example:
use parser_compose::Parser;
let msg = "ABCD";
let parser = "B".or("C").or("A");
let result = parser.accumulate(4).try_parse(msg.into());
assert!(result.is_err());
println!("{}", result.err().unwrap());
// stdout:
// expected 4 match(es). matched 3 time(s)
// both branches failed:
// both branches failed:
// expected 'B' at position 3
// expected 'C' at position 3
// expected 'A' at position 3In this case, the parser failed because it could not match “A”, “B,” or “C” at position 3 in the input.
You can augment the information in this tree by adding custom errors using
err() or labelling a parser using label().
Both methods insert additional nodes into the tree.
use parser_compose::Parser;
let msg = "A";
let parser = "B".or("C").label("failed to parse C or B");
let result = parser.try_parse(msg.into());
assert!(result.is_err());
println!("{}", result.err().unwrap());
// stdout:
// [failed to parse C or B]
// both branches failed:
// expected 'B' at position 0
// expected 'C' at position 0Variants§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ErrorTree
impl !Send for ErrorTree
impl !Sync for ErrorTree
impl Unpin for ErrorTree
impl !UnwindSafe for ErrorTree
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more