[−][src]Struct nom_locate::LocatedSpanEx
A LocatedSpanEx is a set of meta information about the location of a token, including extra information.
The LocatedSpanEx
structure can be used as an input of the nom parsers.
It implements all the necessary traits for LocatedSpanEx<&str,X>
and LocatedSpanEx<&[u8],X>
Fields
offset: usize
The offset represents the position of the fragment relatively to the input of the parser. It starts at offset 0.
line: u32
The line number of the fragment relatively to the input of the parser. It starts at line 1.
fragment: T
The fragment that is spanned. The fragment represents a part of the input of the parser.
extra: X
Extra information that can be embededd by the user. Example: the parsed file name
Methods
impl<T: AsBytes> LocatedSpanEx<T, ()>
[src]
pub fn new(program: T) -> LocatedSpanEx<T, ()>
[src]
Create a span for a particular input with default offset
and
line
values and empty extra data.
You can compute the column through the get_column
or get_utf8_column
methods.
offset
starts at 0, line
starts at 1, and column
starts at 1.
Example of use
use nom_locate::LocatedSpanEx; let span = LocatedSpanEx::new(b"foobar"); assert_eq!(span.offset, 0); assert_eq!(span.line, 1); assert_eq!(span.get_column(), 1); assert_eq!(span.fragment, &b"foobar"[..]);
impl<T: AsBytes, X> LocatedSpanEx<T, X>
[src]
pub fn new_extra(program: T, extra: X) -> LocatedSpanEx<T, X>
[src]
Create a span for a particular input with default offset
and
line
values. You can compute the column through the get_column
or get_utf8_column
methods.
offset
starts at 0, line
starts at 1, and column
starts at 1.
Example of use
use nom_locate::LocatedSpanEx; let span = LocatedSpanEx::new_extra(b"foobar", "extra"); assert_eq!(span.offset, 0); assert_eq!(span.line, 1); assert_eq!(span.get_column(), 1); assert_eq!(span.fragment, &b"foobar"[..]); assert_eq!(span.extra, "extra");
pub fn get_column(&self) -> usize
[src]
Return the column index, assuming 1 byte = 1 column.
Use it for ascii text, or use get_utf8_column for UTF8.
Example of use
let span = LocatedSpanEx::new("foobar"); assert_eq!(span.slice(3..).get_column(), 4);
pub fn get_utf8_column(&self) -> usize
[src]
Return the column index for UTF8 text. Return value is unspecified for non-utf8 text.
This version uses bytecount's hyper algorithm to count characters. This is much faster
for long lines, but is non-negligibly slower for short slices (below around 100 bytes).
This is also sped up significantly more depending on architecture and enabling the simd
feature gates. If you expect primarily short lines, you may get a noticeable speedup in
parsing by using naive_get_utf8_column
instead. Benchmark your specific use case!
Example of use
let span = LocatedSpanEx::new("メカジキ"); let indexOf3dKanji = span.find_substring("ジ").unwrap(); assert_eq!(span.slice(indexOf3dKanji..).get_column(), 7); assert_eq!(span.slice(indexOf3dKanji..).get_utf8_column(), 3);
pub fn naive_get_utf8_column(&self) -> usize
[src]
Return the column index for UTF8 text. Return value is unspecified for non-utf8 text.
A simpler implementation of get_utf8_column
that may be faster on shorter lines.
If benchmarking shows that this is faster, you can use it instead of get_utf8_column
.
Prefer defaulting to get_utf8_column
unless this legitimately is a performance bottleneck.
Example of use
let span = LocatedSpanEx::new("メカジキ"); let indexOf3dKanji = span.find_substring("ジ").unwrap(); assert_eq!(span.slice(indexOf3dKanji..).get_column(), 7); assert_eq!(span.slice(indexOf3dKanji..).naive_get_utf8_column(), 3);
Trait Implementations
impl<T: Clone, X: Clone> Clone for LocatedSpanEx<T, X>
[src]
fn clone(&self) -> LocatedSpanEx<T, X>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: PartialEq, X: PartialEq> PartialEq<LocatedSpanEx<T, X>> for LocatedSpanEx<T, X>
[src]
fn eq(&self, other: &LocatedSpanEx<T, X>) -> bool
[src]
fn ne(&self, other: &LocatedSpanEx<T, X>) -> bool
[src]
impl<T: ToString, X> ToString for LocatedSpanEx<T, X>
[src]
impl<T: Copy, X: Copy> Copy for LocatedSpanEx<T, X>
[src]
impl<T: Debug, X: Debug> Debug for LocatedSpanEx<T, X>
[src]
impl<'a, X> HexDisplay for LocatedSpanEx<&'a str, X>
[src]
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
impl<'a, X> HexDisplay for LocatedSpanEx<&'a [u8], X>
[src]
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
impl<T: InputLength, X> InputLength for LocatedSpanEx<T, X>
[src]
impl<T, X> Offset for LocatedSpanEx<T, X>
[src]
impl<T: AsBytes, X> AsBytes for LocatedSpanEx<T, X>
[src]
impl<'a, X> InputIter for LocatedSpanEx<&'a str, X>
[src]
type Item = char
the current input type is a sequence of that Item
type. Read more
type Iter = CharIndices<'a>
an iterator over the input type, producing the item and its position for use with [Slice]. If we're iterating over &str
, the position corresponds to the byte index of the character Read more
type IterElem = Chars<'a>
an iterator over the input type, producing the item
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_elements(&self) -> Self::IterElem
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::Item) -> bool,
[src]
P: Fn(Self::Item) -> bool,
fn slice_index(&self, count: usize) -> Option<usize>
[src]
impl<'a, X> InputIter for LocatedSpanEx<&'a [u8], X>
[src]
type Item = u8
the current input type is a sequence of that Item
type. Read more
type Iter = Enumerate<Self::IterElem>
an iterator over the input type, producing the item and its position for use with [Slice]. If we're iterating over &str
, the position corresponds to the byte index of the character Read more
type IterElem = Map<Iter<'a, Self::Item>, fn(_: &u8) -> u8>
an iterator over the input type, producing the item
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_elements(&self) -> Self::IterElem
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::Item) -> bool,
[src]
P: Fn(Self::Item) -> bool,
fn slice_index(&self, count: usize) -> Option<usize>
[src]
impl<T, X> InputTake for LocatedSpanEx<T, X> where
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
[src]
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
impl<T, X> InputTakeAtPosition for LocatedSpanEx<T, X> where
T: InputTakeAtPosition + InputLength + InputIter,
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone,
[src]
T: InputTakeAtPosition + InputLength + InputIter,
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone,
type Item = <T as InputIter>::Item
the current input type is a sequence of that Item
type. Read more
fn split_at_position_complete<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
[src]
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
[src]
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position1<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
[src]
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position1_complete<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
[src]
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
impl<'a, 'b, X> Compare<&'a str> for LocatedSpanEx<&'b str, X>
[src]
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
impl<'a, 'b, X> Compare<&'a [u8]> for LocatedSpanEx<&'b [u8], X>
[src]
fn compare(&self, t: &'a [u8]) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a [u8]) -> CompareResult
[src]
impl<'a, 'b, X> Compare<&'a str> for LocatedSpanEx<&'b [u8], X>
[src]
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
impl<A: Compare<B>, B, X, Y> Compare<LocatedSpanEx<B, X>> for LocatedSpanEx<A, Y>
[src]
fn compare(&self, t: LocatedSpanEx<B, X>) -> CompareResult
[src]
fn compare_no_case(&self, t: LocatedSpanEx<B, X>) -> CompareResult
[src]
impl<Fragment: FindToken<Token>, Token, X> FindToken<Token> for LocatedSpanEx<Fragment, X>
[src]
fn find_token(&self, token: Token) -> bool
[src]
impl<'a, T, X> FindSubstring<&'a str> for LocatedSpanEx<T, X> where
T: FindSubstring<&'a str>,
[src]
T: FindSubstring<&'a str>,
fn find_substring(&self, substr: &'a str) -> Option<usize>
[src]
impl<R: FromStr, T, X> ParseTo<R> for LocatedSpanEx<T, X> where
T: ParseTo<R>,
[src]
T: ParseTo<R>,
impl<'a, X: Clone> Slice<Range<usize>> for LocatedSpanEx<&'a str, X>
[src]
impl<'a, X: Clone> Slice<RangeTo<usize>> for LocatedSpanEx<&'a str, X>
[src]
impl<'a, X: Clone> Slice<RangeFrom<usize>> for LocatedSpanEx<&'a str, X>
[src]
impl<'a, X: Clone> Slice<RangeFull> for LocatedSpanEx<&'a str, X>
[src]
impl<'a, X: Clone> Slice<Range<usize>> for LocatedSpanEx<&'a [u8], X>
[src]
impl<'a, X: Clone> Slice<RangeTo<usize>> for LocatedSpanEx<&'a [u8], X>
[src]
impl<'a, X: Clone> Slice<RangeFrom<usize>> for LocatedSpanEx<&'a [u8], X>
[src]
impl<'a, X: Clone> Slice<RangeFull> for LocatedSpanEx<&'a [u8], X>
[src]
impl<'a, X> ExtendInto for LocatedSpanEx<&'a str, X>
[src]
type Item = char
the current input type is a sequence of that Item
type. Read more
type Extender = String
the type that will be produced
fn new_builder(&self) -> Self::Extender
[src]
fn extend_into(&self, acc: &mut Self::Extender)
[src]
impl<'a, X> ExtendInto for LocatedSpanEx<&'a [u8], X>
[src]
Auto Trait Implementations
impl<T, X> Unpin for LocatedSpanEx<T, X> where
T: Unpin,
X: Unpin,
T: Unpin,
X: Unpin,
impl<T, X> Sync for LocatedSpanEx<T, X> where
T: Sync,
X: Sync,
T: Sync,
X: Sync,
impl<T, X> Send for LocatedSpanEx<T, X> where
T: Send,
X: Send,
T: Send,
X: Send,
impl<T, X> UnwindSafe for LocatedSpanEx<T, X> where
T: UnwindSafe,
X: UnwindSafe,
T: UnwindSafe,
X: UnwindSafe,
impl<T, X> RefUnwindSafe for LocatedSpanEx<T, X> where
T: RefUnwindSafe,
X: RefUnwindSafe,
T: RefUnwindSafe,
X: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> InputTakeAtPosition for T where
T: InputLength + InputIter + InputTake + UnspecializedInput + Clone,
[src]
T: InputLength + InputIter + InputTake + UnspecializedInput + Clone,
type Item = <T as InputIter>::Item
the current input type is a sequence of that Item
type. Read more
fn split_at_position<P, E>(&self, predicate: P) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
[src]
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
fn split_at_position1<P, E>(
&self,
predicate: P,
e: ErrorKind
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
[src]
&self,
predicate: P,
e: ErrorKind
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
fn split_at_position_complete<P, E>(
&self,
predicate: P
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
[src]
&self,
predicate: P
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
fn split_at_position1_complete<P, E>(
&self,
predicate: P,
e: ErrorKind
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,
[src]
&self,
predicate: P,
e: ErrorKind
) -> Result<(T, T), Err<E>> where
E: ParseError<T>,
P: Fn(<T as InputTakeAtPosition>::Item) -> bool,