mirror of
https://github.com/nushell/nushell.git
synced 2024-11-29 20:03:54 +01:00
f70c6d5d48
This commit extracts Tag, Span, Text, as well as source-related debug facilities into a new crate called nu_source. This change is much bigger than one might have expected because the previous code relied heavily on implementing inherent methods on `Tagged<T>` and `Spanned<T>`, which is no longer possible. As a result, this change creates more concrete types instead of using `Tagged<T>`. One notable example: Tagged<Value> became Value, and Value became UntaggedValue. This change clarifies the intent of the code in many places, but it does make it a big change.
33 lines
766 B
Rust
33 lines
766 B
Rust
use derive_new::new;
|
|
use nom_locate::LocatedSpanEx;
|
|
use nom_tracable::{HasTracableInfo, TracableInfo};
|
|
|
|
pub type NomSpan<'a> = LocatedSpanEx<&'a str, TracableContext>;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, new)]
|
|
pub struct TracableContext {
|
|
pub(crate) info: TracableInfo,
|
|
}
|
|
|
|
impl HasTracableInfo for TracableContext {
|
|
fn get_tracable_info(&self) -> TracableInfo {
|
|
self.info
|
|
}
|
|
|
|
fn set_tracable_info(self, info: TracableInfo) -> Self {
|
|
TracableContext { info }
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for TracableContext {
|
|
type Target = TracableInfo;
|
|
|
|
fn deref(&self) -> &TracableInfo {
|
|
&self.info
|
|
}
|
|
}
|
|
|
|
pub fn nom_input(s: &str) -> NomSpan<'_> {
|
|
LocatedSpanEx::new_extra(s, TracableContext::new(TracableInfo::new()))
|
|
}
|