Struct nom_locate::LocatedSpan[][src]

pub struct LocatedSpan<T> {
    pub offset: usize,
    pub line: u32,
    pub fragment: T,
}

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

The offset represents the position of the fragment relatively to the input of the parser. It starts at offset 0.

The line number of the fragment relatively to the input of the parser. It starts at line 1.

The fragment that is spanned. The fragment represents a part of the input of the parser.

Methods

impl<T: AsBytes> LocatedSpan<T>
[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::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"[..]);

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);

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);

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]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Debug> Debug for LocatedSpan<T>
[src]

Formats the value using the given formatter. Read more

impl<T: Clone> Clone for LocatedSpan<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for LocatedSpan<T>
[src]

impl<T: InputLength> InputLength for LocatedSpan<T>
[src]

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> InputTake for LocatedSpan<T> where
    Self: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>, 
[src]

returns a slice of count bytes. panics if count > length

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<'a> InputIter for LocatedSpan<&'a str>
[src]

returns an iterator over the elements and their byte offsets

returns an iterator over the elements

finds the byte position of the element

get the byte offset from the element's position in the stream

impl<'a> InputIter for LocatedSpan<&'a [u8]>
[src]

returns an iterator over the elements and their byte offsets

returns an iterator over the elements

finds the byte position of the element

get the byte offset from the element's position in the stream

impl<'a> InputIter for LocatedSpan<CompleteStr<'a>>
[src]

returns an iterator over the elements and their byte offsets

returns an iterator over the elements

finds the byte position of the element

get the byte offset from the element's position in the stream

impl<'a> InputIter for LocatedSpan<CompleteByteSlice<'a>>
[src]

returns an iterator over the elements and their byte offsets

returns an iterator over the elements

finds the byte position of the element

get the byte offset from the element's position in the stream

impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b str>
[src]

compares self to another value for equality

compares self to another value for equality independently of the case. Read more

impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteStr<'b>>
[src]

compares self to another value for equality

compares self to another value for equality independently of the case. Read more

impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<&'b [u8]>
[src]

compares self to another value for equality

compares self to another value for equality independently of the case. Read more

impl<'a, 'b> Compare<&'a [u8]> for LocatedSpan<CompleteByteSlice<'b>>
[src]

compares self to another value for equality

compares self to another value for equality independently of the case. Read more

impl<'a, 'b> Compare<&'a str> for LocatedSpan<&'b [u8]>
[src]

compares self to another value for equality

compares self to another value for equality independently of the case. Read more

impl<'a, 'b> Compare<&'a str> for LocatedSpan<CompleteByteSlice<'b>>
[src]

compares self to another value for equality

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]

compares self to another value for equality

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<RangeTo<usize>> for LocatedSpan<&'a str>
[src]

impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a str>
[src]

impl<'a> Slice<RangeFull> for LocatedSpan<&'a str>
[src]

impl<'a> Slice<Range<usize>> for LocatedSpan<&'a [u8]>
[src]

impl<'a> Slice<RangeTo<usize>> for LocatedSpan<&'a [u8]>
[src]

impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<&'a [u8]>
[src]

impl<'a> Slice<RangeFull> for LocatedSpan<&'a [u8]>
[src]

impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteStr<'a>>
[src]

impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteStr<'a>>
[src]

impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteStr<'a>>
[src]

impl<'a> Slice<RangeFull> for LocatedSpan<CompleteStr<'a>>
[src]

impl<'a> Slice<Range<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]

impl<'a> Slice<RangeTo<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]

impl<'a> Slice<RangeFrom<usize>> for LocatedSpan<CompleteByteSlice<'a>>
[src]

impl<'a> Slice<RangeFull> for LocatedSpan<CompleteByteSlice<'a>>
[src]

impl<Fragment: FindToken<Token>, Token> FindToken<Token> for LocatedSpan<Fragment>
[src]

impl<'a, T> FindSubstring<&'a str> for LocatedSpan<T> where
    T: FindSubstring<&'a str>, 
[src]

impl<R: FromStr, T> ParseTo<R> for LocatedSpan<T> where
    T: ParseTo<R>, 
[src]

impl<T> Offset for LocatedSpan<T>
[src]

offset between the first byte of self and the first byte of the argument

impl<T: ToString> ToString for LocatedSpan<T>
[src]

Converts the given value to a String. Read more

impl<'a> ExtendInto for LocatedSpan<&'a str>
[src]

create a new Extend of the correct type

accumulate the input into an accumulator

impl<'a> ExtendInto for LocatedSpan<CompleteStr<'a>>
[src]

create a new Extend of the correct type

accumulate the input into an accumulator

impl<'a> ExtendInto for LocatedSpan<&'a [u8]>
[src]

create a new Extend of the correct type

accumulate the input into an accumulator

impl<'a> ExtendInto for LocatedSpan<CompleteByteSlice<'a>>
[src]

create a new Extend of the correct type

accumulate the input into an accumulator

impl<'a> HexDisplay for LocatedSpan<&'a str>
[src]

Converts the value of self to a hex dump, returning the owned string. Read more

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]

Converts the value of self to a hex dump, returning the owned string. Read more

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]

Converts the value of self to a hex dump, returning the owned string. Read more

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]

Converts the value of self to a hex dump, returning the owned string. Read more

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> Sync for LocatedSpan<T> where
    T: Sync