Diffstat (limited to 'src/parser/types.rs')
-rw-r--r--src/parser/types.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/parser/types.rs b/src/parser/types.rs
index dc44e42..3ee1d7d 100644
--- a/src/parser/types.rs
+++ b/src/parser/types.rs
@@ -1,11 +1,14 @@
-use std::{fmt::FormattingOptions, ops::Deref};
-
+use crate::parser::util::Spanner;
use crate::{exec::Argc, lexer::Token};
use beef::lean::Cow;
use chumsky::{
input::{MappedInput, Stream},
prelude::*,
};
+use std::{
+ fmt::FormattingOptions,
+ ops::{Deref, Try},
+};
pub type Span = SimpleSpan<usize>;
pub type Error<'s> = Rich<'s, Token<'s>, Span>;
pub type Input<'s> = MappedInput<
@@ -112,6 +115,11 @@ impl<T> Spanned<T> {
}
}
+ pub fn try_map<U, E>(self, f: impl Fn(T, Span) -> Result<U, E>) -> Result<Spanned<U>, E> {
+ let Self { inner, span } = self;
+ f(inner, span).map(|x| x.spun(span))
+ }
+
pub fn unspan() -> impl Fn(Spanned<T>) -> T + Copy {
|x| x.inner
}