Located

Struct Located 

Source
pub struct Located<D, Sp = SimpleSpan, Sl = ()> { /* private fields */ }
Expand description

A value with complete location information: both which source and where in that source.

Located<D, Sp, Sl> combines a value of type D with:

  • A slice identifier Sl indicating which source the data came from
  • A span Sp indicating where within that source the data is located

This provides the most complete location tracking possible, combining the benefits of both Sliced (source tracking) and Spanned (position tracking).

§Design

Located uses public fields for direct access, but also provides accessor methods for consistency. It implements Deref and DerefMut to allow transparent access to the inner data while keeping full location information available when needed.

§Common Patterns

§Transparent Access via Deref

Thanks to Deref, you can call methods on the wrapped value directly:

use tokit::utils::{Located, Span};

let located = Located::new("main.rs", Span::new(10, 15), "hello");

// Can call str methods directly
assert_eq!(located.len(), 5);
assert_eq!(located.to_uppercase(), "HELLO");

// But can still access location info
assert_eq!(located.slice(), "main.rs");
assert_eq!(located.span().start(), 10);

§Multi-File Error Reporting

use tokit::utils::{Located, Span};
use std::path::PathBuf;

fn report_error<T>(loc: &Located<T, Span, PathBuf>, message: &str)
where
    T: core::fmt::Debug
{
    eprintln!(
        "Error in {}:{}:{}: {}\n  {:?}",
        loc.slice().display(),
        get_line_number(loc.span().start()),
        get_column_number(loc.span().start()),
        message,
        loc.data()
    );
}

§Building Complete AST Nodes

use tokit::utils::{Located, Span};
use std::path::PathBuf;

type Loc<T> = Located<T, Span, PathBuf>;

enum Expr {
    Number(i64),
    BinOp {
        op: String,
        left: Box<Loc<Expr>>,
        right: Box<Loc<Expr>>,
    },
}

// Each expression knows exactly where it came from
let expr = Loc::new(
    PathBuf::from("src/calc.rs"),
    Span::new(45, 52),
    Expr::Number(42)
);

// Can report: "Error in src/calc.rs:3:12-19"

§Cross-File Reference Checking

use tokit::utils::{Located, Span};

fn check_reference(
    reference: &Located<String, Span, String>,
    definition: &Located<String, Span, String>
) -> Result<(), String> {
    if reference.slice() != definition.slice() {
        Err(format!(
            "Cross-file reference: {} (in {}) references {} (in {})",
            reference.data(),
            reference.slice(),
            definition.data(),
            definition.slice()
        ))
    } else {
        Ok(())
    }
}

§Mapping Values While Preserving Full Location

use tokit::utils::{Located, Span};

let located_str = Located::new("input.txt", Span::new(5, 7), "42");

// Parse the string, keeping both source and position
let parsed: Located<i32, Span, &str> = located_str.map_data(|s| s.parse().unwrap());

assert_eq!(*parsed, 42);
assert_eq!(parsed.slice(), "input.txt");
assert_eq!(parsed.span().start(), 5);

§IDE Integration

use tokit::utils::{Located, Span};
use std::path::PathBuf;

struct Diagnostic {
    severity: Severity,
    message: String,
    location: Located<(), Span, PathBuf>,
}

// Generate diagnostics with complete location info
fn undefined_variable(name: &Located<String, Span, PathBuf>) -> Diagnostic {
    Diagnostic {
        severity: Severity::Error,
        message: format!("Undefined variable '{}'", name.data()),
        location: name.as_ref().map_data(|_| ()),
    }
}

// IDE can jump to exact location:
// - Open file: diagnostic.location.slice()
// - Navigate to: diagnostic.location.span()

§Incremental Compilation with Position Tracking

use tokit::utils::{Located, Span};
use std::collections::HashMap;

struct Definition {
    name: String,
    location: Located<(), Span, String>,
}

// Track where each definition is located
let mut definitions: HashMap<String, Definition> = HashMap::new();

// When a file changes, only recheck definitions in that file
fn recheck_file(file: &str, definitions: &mut HashMap<String, Definition>) {
    definitions.retain(|_, def| def.location.slice() != file);
    // Re-parse and add new definitions from the changed file
}

§Trait Implementations

  • Deref / DerefMut: Access the inner data transparently
  • Display: Delegates to the inner data’s Display implementation
  • IntoComponents: Destructure into (Sl, Sp, D) tuple

§Examples

§Basic Usage

use tokit::utils::{Located, Span};

let located = Located::new("file.rs", Span::new(0, 5), "hello");

assert_eq!(located.slice(), "file.rs");
assert_eq!(located.span(), Span::new(0, 5));
assert_eq!(located.data(), &"hello");
assert_eq!(*located, "hello"); // Via Deref

§Destructuring

use tokit::utils::{Located, Span};

let located = Located::new("main.rs", Span::new(10, 20), 42);

let (slice, span, value) = located.into_components();
assert_eq!(slice, "main.rs");
assert_eq!(span, Span::new(10, 20));
assert_eq!(value, 42);

§Mutable Access

use tokit::utils::{Located, Span};

let mut located = Located::new("input", Span::new(0, 2), 10);

// Modify the data
*located += 5;
assert_eq!(*located, 15);

// Modify the slice
*located.slice_mut() = "output";
assert_eq!(located.slice(), "output");

// Modify the span
located.span_mut().set_end(5);
assert_eq!(located.span().end(), 5);

§Conversion from Spanned or Sliced

use tokit::utils::{Located, Span, Spanned, Sliced};

// From Spanned by adding slice info
let spanned = Spanned::new(Span::new(5, 10), "data");
let located = Located::new("file.rs", spanned.span(), spanned.into_data());

// From Sliced by adding span info
let sliced = Sliced::new("config.toml", "value");
let located = Located::new(sliced.into_slice(), Span::new(0, 5), "value");

Implementations§

Source§

impl Located<(), ()>

Source

pub const PHANTOM: Self

A zero-sized located value for phantom usage.

Source

pub const fn phantom() -> Self

Returns the phantom located value.

Source§

impl<D, Sp, Sl> Located<D, Sp, Sl>

Source

pub const fn new(slice: Sl, span: Sp, data: D) -> Self

Create a new located value.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("file.rs", Span::new(10, 15), "hello");
assert_eq!(located.slice(), "file.rs");
assert_eq!(located.span(), Span::new(10, 15));
assert_eq!(located.data(), &"hello");
Source

pub const fn slice(&self) -> Sl
where Sl: Copy,

Get a copy of the slice.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("main.rs", Span::new(0, 5), "data");
assert_eq!(located.slice(), "main.rs");
Source

pub const fn slice_ref(&self) -> &Sl

Get a reference to the slice.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("config.toml", Span::new(5, 10), "data");
assert_eq!(located.slice_ref(), &"config.toml");
Source

pub const fn slice_mut(&mut self) -> &mut Sl

Get a mutable reference to the slice.

§Example
use tokit::utils::{Located, Span};

let mut located = Located::new("old.txt", Span::new(0, 3), "data");
*located.slice_mut() = "new.txt";
assert_eq!(located.slice(), "new.txt");
Source

pub const fn span(&self) -> Sp
where Sp: Copy,

Get a copy of the span.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("file.rs", Span::new(5, 10), "data");
assert_eq!(located.span(), Span::new(5, 10));
Source

pub const fn span_ref(&self) -> &Sp

Get a reference to the span.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("file.rs", Span::new(5, 10), "data");
assert_eq!(located.span_ref(), &Span::new(5, 10));
Source

pub const fn span_mut(&mut self) -> &mut Sp

Get a mutable reference to the span.

§Example
use tokit::utils::{Located, Span};

let mut located = Located::new("file.rs", Span::new(0, 5), "data");
located.span_mut().set_end(10);
assert_eq!(located.span().end(), 10);
Source

pub const fn data(&self) -> &D

Get a reference to the data.

§Example
use tokit::utils::{Located, Span};

let located = Located::new("file.txt", Span::new(0, 2), 42);
assert_eq!(*located.data(), 42);
Source

pub const fn data_mut(&mut self) -> &mut D

Get a mutable reference to the data.

§Example
use tokit::utils::{Located, Span};

let mut located = Located::new("file.txt", Span::new(0, 2), 42);
*located.data_mut() = 100;
assert_eq!(*located.data(), 100);
Source

pub const fn as_ref(&self) -> Located<&D, &Sp, &Sl>

Returns a reference to the slice, span, and data.

§Example
use tokit::utils::{Located, Span};

let located = Located::new(
    String::from("file.txt"),
    Span::new(0, 5),
    String::from("hello")
);
let borrowed: Located<&String, &Span, &String> = located.as_ref();
assert_eq!(borrowed.data(), &"hello");
Source

pub const fn as_mut(&mut self) -> Located<&mut D, &mut Sp, &mut Sl>

Returns a mutable reference to the slice, span, and data.

§Example
use tokit::utils::{Located, Span};

let mut located = Located::new(
    String::from("file.txt"),
    Span::new(0, 5),
    String::from("hello")
);
let mut borrowed: Located<&mut String, &mut Span, &mut String> = located.as_mut();
borrowed.data_mut().push_str(" world");
assert_eq!(located.data(), &"hello world");
Source

pub fn into_slice(self) -> Sl

Consume the located value and return the slice.

Source

pub fn into_span(self) -> Sp

Consume the located value and return the span.

Source

pub fn into_data(self) -> D

Consume the located value and return the data.

Source

pub fn into_components(self) -> (Sl, Sp, D)

Decompose the located value into its slice, span, and data.

Source

pub fn into_spanned(self) -> Spanned<D, Sp>

Convert into a Spanned value, discarding the slice information.

Source

pub fn into_sliced(self) -> Sliced<D, Sl>

Convert into a Sliced value, discarding the span information.

Source

pub fn map_data<F, U>(self, f: F) -> Located<U, Sp, Sl>
where F: FnOnce(D) -> U,

Map the data to a new value, preserving the slice and span.

Trait Implementations§

Source§

impl<D: Clone, Sp: Clone, Sl: Clone> Clone for Located<D, Sp, Sl>

Source§

fn clone(&self) -> Located<D, Sp, Sl>

Returns a duplicate 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<D: Debug, Sp: Debug, Sl: Debug> Debug for Located<D, Sp, Sl>

Source§

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

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

impl<D, Sp, Sl> Deref for Located<D, Sp, Sl>

Source§

type Target = D

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<D, Sp, Sl> DerefMut for Located<D, Sp, Sl>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<D, Sp, Sl> Display for Located<D, Sp, Sl>
where D: Display,

Source§

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

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

impl<D, Sp, Sl> Error for Located<D, Sp, Sl>
where D: Error, Sp: Debug, Sl: Debug,

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<D: Hash, Sp: Hash, Sl: Hash> Hash for Located<D, Sp, Sl>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<D, Sp, Sl> IntoComponents for Located<D, Sp, Sl>

Source§

type Components = (Sl, Sp, D)

The tuple or struct type containing the decomposed components. Read more
Source§

fn into_components(self) -> Self::Components

Consumes this element and returns its constituent components. Read more
Source§

impl<D: Ord, Sp: Ord, Sl: Ord> Ord for Located<D, Sp, Sl>

Source§

fn cmp(&self, other: &Located<D, Sp, Sl>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'inp, L, Ctx, Lang: ?Sized> ParseInput<'inp, L, Located<<L as Lexer<'inp>>::Token, <L as Lexer<'inp>>::Span, <<L as Lexer<'inp>>::Source as Source<<L as Lexer<'inp>>::Offset>>::Slice<'inp>>, Ctx, Lang> for With<Any<L, Ctx, Lang>, PhantomLocated>
where L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error: From<UnexpectedEot<L::Offset, Lang>> + From<<L::Token as Token<'inp>>::Error>,

Source§

fn parse_input( &mut self, inp: &mut InputRef<'inp, '_, L, Ctx, Lang>, ) -> Result<Located<L::Token, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>
where Ctx: ParseContext<'inp, L, Lang>,

Try to parse from the given input.
Source§

fn spanned(self) -> With<PhantomSpan, Self>
where Self: Sized,

Wraps the output of this parser in a Spanned with the span of the parsed input.
Source§

fn sourced(self) -> With<PhantomSliced, Self>
where Self: Sized,

Wraps the output of this parser in a Sliced with the source slice of the parsed input.
Source§

fn located(self) -> With<PhantomLocated, Self>
where Self: Sized,

Wraps the output of this parser in a Located with the span and source slice of the parsed input.
Source§

fn ignored(self) -> Ignore<Self, O>
where Self: Sized,

Ignores the output of this parser.
Source§

fn repeated<Condition, W>( self, condition: Condition, ) -> Repeated<Self, Condition, O, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W::CAPACITY>, W: Window,

Creates a Repeated combinator that applies this parser repeatedly until the condition handler Condition returns [RepeatedAction::End] or an fatal error.
Source§

fn separated_by<SepClassifier, Condition, W>( self, sep_classifier: SepClassifier, condition: Condition, ) -> SeparatedBy<Self, SepClassifier, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, SepClassifier: Check<L::Token>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn separated_by_comma<Condition, W>( self, condition: Condition, ) -> SeparatedBy<Self, Comma, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, L::Token: PunctuatorToken<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn peek_then<C, W>(self, condition: C) -> PeekThen<Self, C, L::Token, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: FnMut(Peeked<'_, 'inp, L, W>, &mut Ctx::Emitter) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, W: Window, PeekThen<Self, C, L::Token, W>: ParseInput<'inp, L, O, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn peek_then_or_not<C, W>( self, condition: C, ) -> OrNot<PeekThen<Self, C, L::Token, W>>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window, OrNot<PeekThen<Self, C, L::Token, W>>: ParseInput<'inp, L, Option<O>, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn map<U, F>(self, f: F) -> Map<Self, F, L, Ctx, O, U, Lang>
where Self: Sized, F: FnMut(O) -> U,

Map the output of this parser using the given function.
Source§

fn filter<F>(self, validator: F) -> Filter<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter the output of this parser using a validation function. Read more
Source§

fn filter_map<U, F>(self, mapper: F) -> FilterMap<Self, F, O>
where Self: Sized, L: Lexer<'inp>, F: FnMut(O) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter and map the output of this parser using a validation/transformation function. Read more
Source§

fn validate<F>(self, validator: F) -> Validate<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Validate the output of this parser with full location context. Read more
Source§

fn then_ignore<G, U>(self, second: G) -> ThenIgnore<Self, G, U>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, ignoring the output of the second.
Source§

fn then<T, U>(self, then: T) -> Then<Self, T>
where Self: Sized, T: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, using the first result to determine the second parser.
Source§

fn ignore_then<G, U>(self, second: G) -> IgnoreThen<Self, G, O>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>,

Sequence this parser with another, ignoring the output of the first.
Source§

fn recover<R>(self, recovery: R) -> Recover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover from errors produced by this parser using the given recovery parser.
Source§

fn inplace_recover<R>(self, recovery: R) -> InplaceRecover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover in-place from errors produced by this parser using the given recovery parser.
Source§

fn padded(self) -> Padded<Self>
where Self: Sized,

Creates a parser that accepts any token with optional padding.
Source§

impl<'inp, L, Ctx, Lang, Classifier> ParseInput<'inp, L, Located<<L as Lexer<'inp>>::Token, <L as Lexer<'inp>>::Span, <<L as Lexer<'inp>>::Source as Source<<L as Lexer<'inp>>::Offset>>::Slice<'inp>>, Ctx, Lang> for With<Expect<Classifier, Ctx, Lang>, PhantomLocated>
where L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error: From<UnexpectedToken<'inp, L::Token, <L::Token as Token<'inp>>::Kind, L::Span, Lang>> + From<<L::Token as Token<'inp>>::Error> + From<UnexpectedEot<L::Offset, Lang>>, Classifier: Check<L::Token, Result<(), Expected<'inp, <L::Token as Token<'inp>>::Kind>>>,

Source§

fn parse_input( &mut self, inp: &mut InputRef<'inp, '_, L, Ctx, Lang>, ) -> Result<Located<L::Token, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>

Try to parse from the given input.
Source§

fn spanned(self) -> With<PhantomSpan, Self>
where Self: Sized,

Wraps the output of this parser in a Spanned with the span of the parsed input.
Source§

fn sourced(self) -> With<PhantomSliced, Self>
where Self: Sized,

Wraps the output of this parser in a Sliced with the source slice of the parsed input.
Source§

fn located(self) -> With<PhantomLocated, Self>
where Self: Sized,

Wraps the output of this parser in a Located with the span and source slice of the parsed input.
Source§

fn ignored(self) -> Ignore<Self, O>
where Self: Sized,

Ignores the output of this parser.
Source§

fn repeated<Condition, W>( self, condition: Condition, ) -> Repeated<Self, Condition, O, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W::CAPACITY>, W: Window,

Creates a Repeated combinator that applies this parser repeatedly until the condition handler Condition returns [RepeatedAction::End] or an fatal error.
Source§

fn separated_by<SepClassifier, Condition, W>( self, sep_classifier: SepClassifier, condition: Condition, ) -> SeparatedBy<Self, SepClassifier, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, SepClassifier: Check<L::Token>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn separated_by_comma<Condition, W>( self, condition: Condition, ) -> SeparatedBy<Self, Comma, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, L::Token: PunctuatorToken<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn peek_then<C, W>(self, condition: C) -> PeekThen<Self, C, L::Token, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: FnMut(Peeked<'_, 'inp, L, W>, &mut Ctx::Emitter) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, W: Window, PeekThen<Self, C, L::Token, W>: ParseInput<'inp, L, O, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn peek_then_or_not<C, W>( self, condition: C, ) -> OrNot<PeekThen<Self, C, L::Token, W>>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window, OrNot<PeekThen<Self, C, L::Token, W>>: ParseInput<'inp, L, Option<O>, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn map<U, F>(self, f: F) -> Map<Self, F, L, Ctx, O, U, Lang>
where Self: Sized, F: FnMut(O) -> U,

Map the output of this parser using the given function.
Source§

fn filter<F>(self, validator: F) -> Filter<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter the output of this parser using a validation function. Read more
Source§

fn filter_map<U, F>(self, mapper: F) -> FilterMap<Self, F, O>
where Self: Sized, L: Lexer<'inp>, F: FnMut(O) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter and map the output of this parser using a validation/transformation function. Read more
Source§

fn validate<F>(self, validator: F) -> Validate<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Validate the output of this parser with full location context. Read more
Source§

fn then_ignore<G, U>(self, second: G) -> ThenIgnore<Self, G, U>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, ignoring the output of the second.
Source§

fn then<T, U>(self, then: T) -> Then<Self, T>
where Self: Sized, T: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, using the first result to determine the second parser.
Source§

fn ignore_then<G, U>(self, second: G) -> IgnoreThen<Self, G, O>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>,

Sequence this parser with another, ignoring the output of the first.
Source§

fn recover<R>(self, recovery: R) -> Recover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover from errors produced by this parser using the given recovery parser.
Source§

fn inplace_recover<R>(self, recovery: R) -> InplaceRecover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover in-place from errors produced by this parser using the given recovery parser.
Source§

fn padded(self) -> Padded<Self>
where Self: Sized,

Creates a parser that accepts any token with optional padding.
Source§

impl<'inp, L, O, Ctx, P, Lang: ?Sized> ParseInput<'inp, L, Located<O, <L as Lexer<'inp>>::Span, <<L as Lexer<'inp>>::Source as Source<<L as Lexer<'inp>>::Offset>>::Slice<'inp>>, Ctx, Lang> for With<PhantomLocated, P>
where P: ParseInput<'inp, L, O, Ctx, Lang>, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>,

Source§

fn parse_input( &mut self, inp: &mut InputRef<'inp, '_, L, Ctx, Lang>, ) -> Result<Located<O, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>

Try to parse from the given input.
Source§

fn spanned(self) -> With<PhantomSpan, Self>
where Self: Sized,

Wraps the output of this parser in a Spanned with the span of the parsed input.
Source§

fn sourced(self) -> With<PhantomSliced, Self>
where Self: Sized,

Wraps the output of this parser in a Sliced with the source slice of the parsed input.
Source§

fn located(self) -> With<PhantomLocated, Self>
where Self: Sized,

Wraps the output of this parser in a Located with the span and source slice of the parsed input.
Source§

fn ignored(self) -> Ignore<Self, O>
where Self: Sized,

Ignores the output of this parser.
Source§

fn repeated<Condition, W>( self, condition: Condition, ) -> Repeated<Self, Condition, O, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W::CAPACITY>, W: Window,

Creates a Repeated combinator that applies this parser repeatedly until the condition handler Condition returns [RepeatedAction::End] or an fatal error.
Source§

fn separated_by<SepClassifier, Condition, W>( self, sep_classifier: SepClassifier, condition: Condition, ) -> SeparatedBy<Self, SepClassifier, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, SepClassifier: Check<L::Token>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn separated_by_comma<Condition, W>( self, condition: Condition, ) -> SeparatedBy<Self, Comma, Condition, O, W, L, Ctx>
where Self: Sized, L: Lexer<'inp>, L::Token: PunctuatorToken<'inp>, Ctx: ParseContext<'inp, L, Lang>, Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window,

Creates a SeparatedBy combinator that applies this parser repeatedly,
Source§

fn peek_then<C, W>(self, condition: C) -> PeekThen<Self, C, L::Token, W>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: FnMut(Peeked<'_, 'inp, L, W>, &mut Ctx::Emitter) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, W: Window, PeekThen<Self, C, L::Token, W>: ParseInput<'inp, L, O, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn peek_then_or_not<C, W>( self, condition: C, ) -> OrNot<PeekThen<Self, C, L::Token, W>>
where Self: Sized, L: Lexer<'inp>, Ctx: ParseContext<'inp, L, Lang>, C: Decision<'inp, L, Ctx::Emitter, W, Lang>, W: Window, OrNot<PeekThen<Self, C, L::Token, W>>: ParseInput<'inp, L, Option<O>, Ctx, Lang>,

Creates a PeekThen combinator that peeks at most N tokens first from the input before parsing. Read more
Source§

fn map<U, F>(self, f: F) -> Map<Self, F, L, Ctx, O, U, Lang>
where Self: Sized, F: FnMut(O) -> U,

Map the output of this parser using the given function.
Source§

fn filter<F>(self, validator: F) -> Filter<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter the output of this parser using a validation function. Read more
Source§

fn filter_map<U, F>(self, mapper: F) -> FilterMap<Self, F, O>
where Self: Sized, L: Lexer<'inp>, F: FnMut(O) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Filter and map the output of this parser using a validation/transformation function. Read more
Source§

fn validate<F>(self, validator: F) -> Validate<Self, F>
where Self: Sized, L: Lexer<'inp>, F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>, Ctx: ParseContext<'inp, L, Lang>,

Validate the output of this parser with full location context. Read more
Source§

fn then_ignore<G, U>(self, second: G) -> ThenIgnore<Self, G, U>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, ignoring the output of the second.
Source§

fn then<T, U>(self, then: T) -> Then<Self, T>
where Self: Sized, T: ParseInput<'inp, L, U, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Sequence this parser with another, using the first result to determine the second parser.
Source§

fn ignore_then<G, U>(self, second: G) -> IgnoreThen<Self, G, O>
where Self: Sized, G: ParseInput<'inp, L, U, Ctx, Lang>,

Sequence this parser with another, ignoring the output of the first.
Source§

fn recover<R>(self, recovery: R) -> Recover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover from errors produced by this parser using the given recovery parser.
Source§

fn inplace_recover<R>(self, recovery: R) -> InplaceRecover<Self, R>
where Self: Sized, R: ParseInput<'inp, L, O, Ctx, Lang>, Ctx: ParseContext<'inp, L, Lang>,

Recover in-place from errors produced by this parser using the given recovery parser.
Source§

fn padded(self) -> Padded<Self>
where Self: Sized,

Creates a parser that accepts any token with optional padding.
Source§

impl<D: PartialEq, Sp: PartialEq, Sl: PartialEq> PartialEq for Located<D, Sp, Sl>

Source§

fn eq(&self, other: &Located<D, Sp, Sl>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: PartialOrd, Sp: PartialOrd, Sl: PartialOrd> PartialOrd for Located<D, Sp, Sl>

Source§

fn partial_cmp(&self, other: &Located<D, Sp, Sl>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<D: Copy, Sp: Copy, Sl: Copy> Copy for Located<D, Sp, Sl>

Source§

impl<D: Eq, Sp: Eq, Sl: Eq> Eq for Located<D, Sp, Sl>

Source§

impl<D, Sp, Sl> StructuralPartialEq for Located<D, Sp, Sl>

Auto Trait Implementations§

§

impl<D, Sp, Sl> Freeze for Located<D, Sp, Sl>
where Sl: Freeze, Sp: Freeze, D: Freeze,

§

impl<D, Sp, Sl> RefUnwindSafe for Located<D, Sp, Sl>

§

impl<D, Sp, Sl> Send for Located<D, Sp, Sl>
where Sl: Send, Sp: Send, D: Send,

§

impl<D, Sp, Sl> Sync for Located<D, Sp, Sl>
where Sl: Sync, Sp: Sync, D: Sync,

§

impl<D, Sp, Sl> Unpin for Located<D, Sp, Sl>
where Sl: Unpin, Sp: Unpin, D: Unpin,

§

impl<D, Sp, Sl> UnwindSafe for Located<D, Sp, Sl>
where Sl: UnwindSafe, Sp: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Source for T
where T: Deref, <T as Deref>::Target: Source,

Source§

type Slice<'a> = <<T as Deref>::Target as Source>::Slice<'a> where T: 'a

A type this Source can be sliced into.
Source§

fn len(&self) -> usize

Length of the source
Source§

fn read<'a, Chunk>(&'a self, offset: usize) -> Option<Chunk>
where Chunk: Chunk<'a>,

Read a chunk of bytes into an array. Returns None when reading out of bounds would occur. Read more
Source§

unsafe fn read_byte_unchecked(&self, offset: usize) -> u8

Available on non-crate feature forbid_unsafe only.
Read a byte without doing bounds checks. Read more
Source§

fn slice(&self, range: Range<usize>) -> Option<<T as Source>::Slice<'_>>

Get a slice of the source at given range. This is analogous to slice::get(range). Read more
Source§

unsafe fn slice_unchecked( &self, range: Range<usize>, ) -> <T as Source>::Slice<'_>

Available on non-crate feature forbid_unsafe only.
Get a slice of the source at given range. This is analogous to slice::get_unchecked(range). Read more
Source§

fn is_boundary(&self, index: usize) -> bool

Check if index is valid for this Source, that is: Read more
Source§

fn find_boundary(&self, index: usize) -> usize

For &str sources attempts to find the closest char boundary at which source can be sliced, starting from index. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.