Type Alias arithmetic_parser::Location

source ·
pub type Location<T = ()> = LocatedSpan<usize, T>;
Expand description

Value with an associated code location. Unlike Spanned, Location does not retain a reference to the original code span, just its start position and length.

Aliased Type§

struct Location<T = ()> {
    pub extra: T,
    /* private fields */
}

Fields§

§extra: T

Extra information that can be embedded by the user.

Implementations§

source§

impl Location

source

pub fn from_str<'a, R>(code: &'a str, range: R) -> Selfwhere InputSpan<'a>: Slice<R>,

Creates a location from a range in the provided code. This is mostly useful for testing.

source§

impl<T> Location<T>

source

pub fn to_string(&self, default_name: &str) -> String

Returns a string representation of this location in the form {default_name} at {line}:{column}.

source

pub fn span<'a>(&self, code: &'a str) -> &'a str

Returns this location in the provided code. It is caller’s responsibility to ensure that this is called with the original code that produced this location.

source§

impl<Span, T> LocatedSpan<Span, T>

source

pub fn location_offset(&self) -> usize

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

source

pub fn location_line(&self) -> u32

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

source

pub fn get_column(&self) -> usize

The column of the fragment start.

source

pub fn fragment(&self) -> &Span

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

source

pub fn map_extra<U>(self, map_fn: impl FnOnce(T) -> U) -> LocatedSpan<Span, U>

Maps the extra field of this span using the provided closure.

source

pub fn map_fragment<U>( self, map_fn: impl FnOnce(Span) -> U ) -> LocatedSpan<U, T>

Maps the fragment field of this span using the provided closure.

source§

impl<Span: Copy, T> LocatedSpan<Span, T>

source

pub fn as_ref(&self) -> LocatedSpan<Span, &T>

Returns a copy of this span with borrowed extra field.

source

pub fn copy_with_extra<U>(&self, value: U) -> LocatedSpan<Span, U>

Copies this span with the provided extra field.

source

pub fn with_no_extra(&self) -> LocatedSpan<Span>

Removes extra field from this span.

Trait Implementations§

source§

impl<Span: Clone, T: Clone> Clone for LocatedSpan<Span, T>

source§

fn clone(&self) -> LocatedSpan<Span, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Span: Debug, T: Debug> Debug for LocatedSpan<Span, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> From<LocatedSpan<&str, T>> for Location<T>

source§

fn from(value: Spanned<'_, T>) -> Self

Converts to this type from the input type.
source§

impl<Span: PartialEq, T> PartialEq<LocatedSpan<Span, T>> for LocatedSpan<Span, T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Span: Copy, T: Copy> Copy for LocatedSpan<Span, T>