Struct nom_locate::LocatedSpan [−][src]
A LocatedSpan is a set of meta information about the location of a token.
The LocatedSpan
structure can be used as an input of the nom parsers.
It implements all the necessary traits for LocatedSpan<&str>
and LocatedSpan<&[u8]>
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.
Methods
impl<T: AsBytes> LocatedSpan<T>
[src]
impl<T: AsBytes> LocatedSpan<T>
pub fn new(program: T) -> LocatedSpan<T>
[src]
pub fn new(program: T) -> LocatedSpan<T>
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::LocatedSpan; let span = LocatedSpan::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"[..]);
pub fn get_column(&self) -> usize
[src]
pub fn get_column(&self) -> usize
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 = LocatedSpan::new("foobar"); assert_eq!(span.slice(3..).get_column(), 4);
pub fn get_utf8_column(&self) -> usize
[src]
pub fn get_utf8_column(&self) -> usize
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 = LocatedSpan::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]
pub fn naive_get_utf8_column(&self) -> usize
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 = LocatedSpan::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: PartialEq> PartialEq for LocatedSpan<T>
[src]
impl<T: PartialEq> PartialEq for LocatedSpan<T>
fn eq(&self, other: &LocatedSpan<T>) -> bool
[src]
fn eq(&self, other: &LocatedSpan<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &LocatedSpan<T>) -> bool
[src]
fn ne(&self, other: &LocatedSpan<T>) -> bool
This method tests for !=
.
impl<T: Debug> Debug for LocatedSpan<T>
[src]
impl<T: Debug> Debug for LocatedSpan<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: Clone> Clone for LocatedSpan<T>
[src]
impl<T: Clone> Clone for LocatedSpan<T>
fn clone(&self) -> LocatedSpan<T>
[src]
fn clone(&self) -> LocatedSpan<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: Copy> Copy for LocatedSpan<T>
[src]
impl<T: Copy> Copy for LocatedSpan<T>
impl<T: InputLength> InputLength for LocatedSpan<T>
[src]
impl<T: InputLength> InputLength for LocatedSpan<T>
fn input_len(&self) -> usize
[src]
fn input_len(&self) -> usize
calculates the input length, as indicated by its name, and the name of the trait itself Read more
impl<T: AtEof> AtEof for LocatedSpan<T>
[src]
impl<T: AtEof> AtEof for LocatedSpan<T>
impl<T> InputTake for LocatedSpan<T> where
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
[src]
impl<T> InputTake for LocatedSpan<T> where
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
fn take(&self, count: usize) -> Self
[src]
fn take(&self, count: usize) -> Self
returns a slice of count
bytes. panics if count > length
fn take_split(&self, count: usize) -> (Self, Self)
[src]
fn take_split(&self, count: usize) -> (Self, Self)
split the stream at the count
byte offset. panics if count > length
impl<T> InputTakeAtPosition for LocatedSpan<T> where
T: InputTakeAtPosition + InputLength,
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone,
[src]
impl<T> InputTakeAtPosition for LocatedSpan<T> where
T: InputTakeAtPosition + InputLength,
Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Clone,
type Item = <T as InputTakeAtPosition>::Item
fn split_at_position<P>(&self, predicate: P) -> IResult<Self, Self, u32> where
P: Fn(Self::Item) -> bool,
[src]
fn split_at_position<P>(&self, predicate: P) -> IResult<Self, Self, u32> where
P: Fn(Self::Item) -> bool,
fn split_at_position1<P>(
&self,
predicate: P,
e: ErrorKind<u32>
) -> IResult<Self, Self, u32> where
P: Fn(Self::Item) -> bool,
[src]
fn split_at_position1<P>(
&self,
predicate: P,
e: ErrorKind<u32>
) -> IResult<Self, Self, u32> where
P: Fn(Self::Item) -> bool,
impl<'a> InputIter for LocatedSpan<&'a str>
[src]
impl<'a> InputIter for LocatedSpan<&'a str>
type Item = char
type RawItem = char
type Iter = CharIndices<'a>
type IterElem = Chars<'a>
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_indices(&self) -> Self::Iter
returns an iterator over the elements and their byte offsets
fn iter_elements(&self) -> Self::IterElem
[src]
fn iter_elements(&self) -> Self::IterElem
returns an iterator over the elements
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
finds the byte position of the element
fn slice_index(&self, count: usize) -> Option<usize>
[src]
fn slice_index(&self, count: usize) -> Option<usize>
get the byte offset from the element's position in the stream
impl<'a> InputIter for LocatedSpan<&'a [u8]>
[src]
impl<'a> InputIter for LocatedSpan<&'a [u8]>
type Item = u8
type RawItem = u8
type Iter = Enumerate<Self::IterElem>
type IterElem = Map<Iter<'a, Self::Item>, fn(_: &u8) -> u8>
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_indices(&self) -> Self::Iter
returns an iterator over the elements and their byte offsets
fn iter_elements(&self) -> Self::IterElem
[src]
fn iter_elements(&self) -> Self::IterElem
returns an iterator over the elements
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
finds the byte position of the element
fn slice_index(&self, count: usize) -> Option<usize>
[src]
fn slice_index(&self, count: usize) -> Option<usize>
get the byte offset from the element's position in the stream
impl<'a> InputIter for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> InputIter for LocatedSpan<CompleteStr<'a>>
type Item = char
type RawItem = char
type Iter = CharIndices<'a>
type IterElem = Chars<'a>
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_indices(&self) -> Self::Iter
returns an iterator over the elements and their byte offsets
fn iter_elements(&self) -> Self::IterElem
[src]
fn iter_elements(&self) -> Self::IterElem
returns an iterator over the elements
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
finds the byte position of the element
fn slice_index(&self, count: usize) -> Option<usize>
[src]
fn slice_index(&self, count: usize) -> Option<usize>
get the byte offset from the element's position in the stream
impl<'a> InputIter for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> InputIter for LocatedSpan<CompleteByteSlice<'a>>
type Item = u8
type RawItem = u8
type Iter = Enumerate<Self::IterElem>
type IterElem = Map<Iter<'a, Self::Item>, fn(_: &u8) -> u8>
fn iter_indices(&self) -> Self::Iter
[src]
fn iter_indices(&self) -> Self::Iter
returns an iterator over the elements and their byte offsets
fn iter_elements(&self) -> Self::IterElem
[src]
fn iter_elements(&self) -> Self::IterElem
returns an iterator over the elements
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
[src]
fn position<P>(&self, predicate: P) -> Option<usize> where
P: Fn(Self::RawItem) -> bool,
finds the byte position of the element
fn slice_index(&self, count: usize) -> Option<usize>
[src]
fn slice_index(&self, count: usize) -> Option<usize>
get the byte offset from the element's position in the stream
impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b str>
[src]
impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b str>
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare(&self, t: &'a str) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteStr<'b>>
[src]
impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteStr<'b>>
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare(&self, t: &'a str) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<&'b [u8]>
[src]
impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<&'b [u8]>
fn compare(&self, t: &'a [u8]) -> CompareResult
[src]
fn compare(&self, t: &'a [u8]) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a [u8]) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a [u8]) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<CompleteByteSlice<'b>>
[src]
impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<CompleteByteSlice<'b>>
fn compare(&self, t: &'a [u8]) -> CompareResult
[src]
fn compare(&self, t: &'a [u8]) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a [u8]) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a [u8]) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b [u8]>
[src]
impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b [u8]>
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare(&self, t: &'a str) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteByteSlice<'b>>
[src]
impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteByteSlice<'b>>
fn compare(&self, t: &'a str) -> CompareResult
[src]
fn compare(&self, t: &'a str) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: &'a str) -> CompareResult
[src]
fn compare_no_case(&self, t: &'a str) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<A: Compare<B>, B> Compare<LocatedSpan<B>> for LocatedSpan<A>
[src]
impl<A: Compare<B>, B> Compare<LocatedSpan<B>> for LocatedSpan<A>
fn compare(&self, t: LocatedSpan<B>) -> CompareResult
[src]
fn compare(&self, t: LocatedSpan<B>) -> CompareResult
compares self to another value for equality
fn compare_no_case(&self, t: LocatedSpan<B>) -> CompareResult
[src]
fn compare_no_case(&self, t: LocatedSpan<B>) -> CompareResult
compares self to another value for equality independently of the case. Read more
impl<'a> Slice<Range<usize>> for LocatedSpan<&'a str>
[src]
impl<'a> Slice<Range<usize>> for LocatedSpan<&'a str>
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<&'a str>
[src]
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<&'a str>
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a str>
[src]
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a str>
impl<'a> Slice<RangeFull> for LocatedSpan<&'a str>
[src]
impl<'a> Slice<RangeFull> for LocatedSpan<&'a str>
impl<'a> Slice<Range<usize>> for LocatedSpan<&'a [u8]>
[src]
impl<'a> Slice<Range<usize>> for LocatedSpan<&'a [u8]>
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<&'a [u8]>
[src]
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<&'a [u8]>
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a [u8]>
[src]
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a [u8]>
impl<'a> Slice<RangeFull> for LocatedSpan<&'a [u8]>
[src]
impl<'a> Slice<RangeFull> for LocatedSpan<&'a [u8]>
impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteStr<'a>>
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteStr<'a>>
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteStr<'a>>
impl<'a> Slice<RangeFull> for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> Slice<RangeFull> for LocatedSpan<CompleteStr<'a>>
impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteByteSlice<'a>>
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteByteSlice<'a>>
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteByteSlice<'a>>
impl<'a> Slice<RangeFull> for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> Slice<RangeFull> for LocatedSpan<CompleteByteSlice<'a>>
impl<Fragment: FindToken<Token>, Token> FindToken<Token> for LocatedSpan<Fragment>
[src]
impl<Fragment: FindToken<Token>, Token> FindToken<Token> for LocatedSpan<Fragment>
fn find_token(&self, token: Token) -> bool
[src]
fn find_token(&self, token: Token) -> bool
impl<'a, T> FindSubstring<&'a str> for LocatedSpan<T> where
T: FindSubstring<&'a str>,
[src]
impl<'a, T> FindSubstring<&'a str> for LocatedSpan<T> where
T: FindSubstring<&'a str>,
fn find_substring(&self, substr: &'a str) -> Option<usize>
[src]
fn find_substring(&self, substr: &'a str) -> Option<usize>
impl<R: FromStr, T> ParseTo<R> for LocatedSpan<T> where
T: ParseTo<R>,
[src]
impl<R: FromStr, T> ParseTo<R> for LocatedSpan<T> where
T: ParseTo<R>,
impl<T> Offset for LocatedSpan<T>
[src]
impl<T> Offset for LocatedSpan<T>
fn offset(&self, second: &Self) -> usize
[src]
fn offset(&self, second: &Self) -> usize
offset between the first byte of self and the first byte of the argument
impl<T: ToString> ToString for LocatedSpan<T>
[src]
impl<T: ToString> ToString for LocatedSpan<T>
impl<'a> ExtendInto for LocatedSpan<&'a str>
[src]
impl<'a> ExtendInto for LocatedSpan<&'a str>
type Item = char
type Extender = String
fn new_builder(&self) -> Self::Extender
[src]
fn new_builder(&self) -> Self::Extender
create a new Extend
of the correct type
fn extend_into(&self, acc: &mut Self::Extender)
[src]
fn extend_into(&self, acc: &mut Self::Extender)
accumulate the input into an accumulator
impl<'a> ExtendInto for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> ExtendInto for LocatedSpan<CompleteStr<'a>>
type Item = char
type Extender = String
fn new_builder(&self) -> Self::Extender
[src]
fn new_builder(&self) -> Self::Extender
create a new Extend
of the correct type
fn extend_into(&self, acc: &mut Self::Extender)
[src]
fn extend_into(&self, acc: &mut Self::Extender)
accumulate the input into an accumulator
impl<'a> ExtendInto for LocatedSpan<&'a [u8]>
[src]
impl<'a> ExtendInto for LocatedSpan<&'a [u8]>
type Item = u8
type Extender = Vec<u8>
fn new_builder(&self) -> Self::Extender
[src]
fn new_builder(&self) -> Self::Extender
create a new Extend
of the correct type
fn extend_into(&self, acc: &mut Self::Extender)
[src]
fn extend_into(&self, acc: &mut Self::Extender)
accumulate the input into an accumulator
impl<'a> ExtendInto for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> ExtendInto for LocatedSpan<CompleteByteSlice<'a>>
type Item = u8
type Extender = Vec<u8>
fn new_builder(&self) -> Self::Extender
[src]
fn new_builder(&self) -> Self::Extender
create a new Extend
of the correct type
fn extend_into(&self, acc: &mut Self::Extender)
[src]
fn extend_into(&self, acc: &mut Self::Extender)
accumulate the input into an accumulator
impl<'a> HexDisplay for LocatedSpan<&'a str>
[src]
impl<'a> HexDisplay for LocatedSpan<&'a str>
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex(&self, chunk_size: usize) -> String
Converts the value of self
to a hex dump, returning the owned string. Read more
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
Converts the value of self
to a hex dump beginning at from
address, returning the owned string. Read more
impl<'a> HexDisplay for LocatedSpan<CompleteStr<'a>>
[src]
impl<'a> HexDisplay for LocatedSpan<CompleteStr<'a>>
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex(&self, chunk_size: usize) -> String
Converts the value of self
to a hex dump, returning the owned string. Read more
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
Converts the value of self
to a hex dump beginning at from
address, returning the owned string. Read more
impl<'a> HexDisplay for LocatedSpan<&'a [u8]>
[src]
impl<'a> HexDisplay for LocatedSpan<&'a [u8]>
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex(&self, chunk_size: usize) -> String
Converts the value of self
to a hex dump, returning the owned string. Read more
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
Converts the value of self
to a hex dump beginning at from
address, returning the owned string. Read more
impl<'a> HexDisplay for LocatedSpan<CompleteByteSlice<'a>>
[src]
impl<'a> HexDisplay for LocatedSpan<CompleteByteSlice<'a>>
fn to_hex(&self, chunk_size: usize) -> String
[src]
fn to_hex(&self, chunk_size: usize) -> String
Converts the value of self
to a hex dump, returning the owned string. Read more
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
[src]
fn to_hex_from(&self, chunk_size: usize, from: usize) -> String
Converts the value of self
to a hex dump beginning at from
address, returning the owned string. Read more
Auto Trait Implementations
impl<T> Send for LocatedSpan<T> where
T: Send,
impl<T> Send for LocatedSpan<T> where
T: Send,
impl<T> Sync for LocatedSpan<T> where
T: Sync,
impl<T> Sync for LocatedSpan<T> where
T: Sync,