Skip to content

Commit

Permalink
feat(error): Deal with nested ParseError
Browse files Browse the repository at this point in the history
  • Loading branch information
watcol committed Aug 2, 2022
1 parent b7781ce commit d2bd7b3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions drake-types/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::convert::Infallible;
use core::ops::Range;
use somen::error::{Expects, ParseError};

Expand All @@ -22,14 +23,28 @@ pub enum Error<L> {
Unexpected,
}

impl<L, E> From<ParseError<L, E>> for Error<L> {
fn from(err: ParseError<L, E>) -> Self {
impl<L> From<ParseError<L, Infallible>> for Error<L> {
fn from(err: ParseError<L, Infallible>) -> Self {
match err {
ParseError::Parser(err) => Error::ParseError {
expects: err.expects,
span: err.position,
},
ParseError::Stream(_) => Error::Unexpected,
_ => unreachable!(),
}
}
}

impl<L> From<ParseError<L, ParseError<L, Infallible>>> for Error<L> {
fn from(err: ParseError<L, ParseError<L, Infallible>>) -> Self {
match err {
ParseError::Parser(err) | ParseError::Stream(ParseError::Parser(err)) => {
Error::ParseError {
expects: err.expects,
span: err.position,
}
}
_ => unreachable!(),
}
}
}

0 comments on commit d2bd7b3

Please sign in to comment.