mirror of
https://github.com/nushell/nushell.git
synced 2025-08-11 22:09:59 +02:00
WIP
This commit is contained in:
@ -16,6 +16,13 @@ pub trait SpannedItem: Sized {
|
||||
fn spanned(self, span: impl Into<Span>) -> Spanned<Self> {
|
||||
Spanned::from_item(self, span.into())
|
||||
}
|
||||
|
||||
// For now, this is a temporary facility. In many cases, there are other useful spans that we
|
||||
// could be using, such as the original source spans of JSON or Toml files, but we don't yet
|
||||
// have the infrastructure to make that work.
|
||||
fn spanned_unknown(self) -> Spanned<Self> {
|
||||
Spanned::from_item(self, (0, 0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SpannedItem for T {}
|
||||
@ -64,6 +71,15 @@ pub struct Span {
|
||||
// source: &'source str,
|
||||
}
|
||||
|
||||
impl From<Option<Span>> for Span {
|
||||
fn from(input: Option<Span>) -> Span {
|
||||
match input {
|
||||
None => Span { start: 0, end: 0 },
|
||||
Some(span) => span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<&Spanned<T>> for Span {
|
||||
fn from(input: &Spanned<T>) -> Span {
|
||||
input.span
|
||||
@ -113,6 +129,14 @@ impl From<&std::ops::Range<usize>> for Span {
|
||||
}
|
||||
|
||||
impl Span {
|
||||
pub fn unknown() -> Span {
|
||||
Span { start: 0, end: 0 }
|
||||
}
|
||||
|
||||
pub fn is_unknown(&self) -> bool {
|
||||
self.start == 0 && self.end == 0
|
||||
}
|
||||
|
||||
pub fn slice(&self, source: &'a str) -> &'a str {
|
||||
&source[self.start..self.end]
|
||||
}
|
||||
|
Reference in New Issue
Block a user