Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
40
third-party/vendor/winnow/examples/custom_error.rs
vendored
Normal file
40
third-party/vendor/winnow/examples/custom_error.rs
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use winnow::error::ErrMode;
|
||||
use winnow::error::ErrorKind;
|
||||
use winnow::error::ParserError;
|
||||
use winnow::prelude::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum CustomError<I> {
|
||||
MyError,
|
||||
Nom(I, ErrorKind),
|
||||
}
|
||||
|
||||
impl<I: Clone> ParserError<I> for CustomError<I> {
|
||||
fn from_error_kind(input: &I, kind: ErrorKind) -> Self {
|
||||
CustomError::Nom(input.clone(), kind)
|
||||
}
|
||||
|
||||
fn append(self, _: &I, _: ErrorKind) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse<'s>(_input: &mut &'s str) -> PResult<&'s str, CustomError<&'s str>> {
|
||||
Err(ErrMode::Backtrack(CustomError::MyError))
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let err = parse.parse_next(&mut "").unwrap_err();
|
||||
match err {
|
||||
ErrMode::Backtrack(e) => assert_eq!(e, CustomError::MyError),
|
||||
_ => panic!("Unexpected error: {:?}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue