Skip to content

Commit

Permalink
Added ability to get span and token from Cheap/Simple
Browse files Browse the repository at this point in the history
  • Loading branch information
zesterer committed Jan 1, 2024
1 parent dce5918 commit c9b9c38
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ pub struct Cheap<S = SimpleSpan<usize>> {
span: S,
}

impl<S> Cheap<S> {
/// Get the span than that error related to.
pub fn span(&self) -> &S {
&self.span
}
}

impl<'a, I: Input<'a>> Error<'a, I> for Cheap<I::Span> {
#[inline]
fn expected_found<E: IntoIterator<Item = Option<MaybeRef<'a, I::Token>>>>(
Expand Down Expand Up @@ -178,6 +185,18 @@ pub struct Simple<'a, T, S = SimpleSpan<usize>> {
found: Option<MaybeRef<'a, T>>,
}

impl<'a, T, S> Simple<'a, T, S> {
/// Get the span than that error related to.
pub fn span(&self) -> &S {
&self.span
}

/// Get the token, if any, that was found at the error location.
pub fn found(&self) -> Option<&T> {
self.found.as_deref()
}
}

impl<'a, T, S> Simple<'a, T, S> {
/// Transform this error's tokens using the given function.
///
Expand Down

0 comments on commit c9b9c38

Please sign in to comment.