Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod __private;

use std::ops::Deref;
use std::ops::{Deref, Index, IndexMut};

pub use rust_sitter_macro::*;

Expand Down Expand Up @@ -108,7 +108,7 @@ impl<T: Extract<U>, U> Extract<Vec<U>> for Vec<T> {
}
}

#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
/// A wrapper around a value that also contains the span of the value in the source.
pub struct Spanned<T> {
/// The underlying parsed node.
Expand Down Expand Up @@ -143,6 +143,20 @@ impl<T: Extract<U>, U> Extract<Spanned<U>> for Spanned<T> {
}
}

impl<T> Index<Spanned<T>> for str {
type Output = str;

fn index(&self, index: Spanned<T>) -> &Self::Output {
&self[index.span.0..index.span.1]
}
}

impl<T> IndexMut<Spanned<T>> for str {
fn index_mut(&mut self, index: Spanned<T>) -> &mut Self::Output {
&mut self[index.span.0..index.span.1]
}
}

pub mod errors {
#[cfg(feature = "tree-sitter-standard")]
use tree_sitter_runtime_standard as tree_sitter;
Expand Down