Skip to main content

InputRef

Struct InputRef 

Source
pub struct InputRef<'src, 'parse, I: Input<'src>, E: ParserExtra<'src, I>> { /* private fields */ }
Expand description

Internal type representing an input as well as all the necessary context for parsing.

Implementations§

Source§

impl<'src, 'parse, I: Input<'src>, E: ParserExtra<'src, I>> InputRef<'src, 'parse, I, E>

Source

pub fn cursor(&self) -> Cursor<'src, 'parse, I>

Get the internal cursor of the input at this moment in time.

Can be used for generating spans or slices. See InputRef::span_from and InputRef::slice.

Source

pub fn save( &self, ) -> Checkpoint<'src, 'parse, I, <E::State as Inspector<'src, I>>::Checkpoint>

Save the current parse state as a Checkpoint.

You can rewind back to this state later with InputRef::rewind.

Source

pub fn rewind( &mut self, checkpoint: Checkpoint<'src, 'parse, I, <E::State as Inspector<'src, I>>::Checkpoint>, )

Reset the parse state to that represented by the given Checkpoint.

You can create a checkpoint with which to perform rewinding using InputRef::save.

Source

pub fn state(&mut self) -> &mut E::State

Get a mutable reference to the state associated with the current parse.

Source

pub fn ctx(&self) -> &E::Context

Get a reference to the context fed to the current parser.

See ConfigParser::configure, Parser::ignore_with_ctx and Parser::then_with_ctx for more information about context-sensitive parsing.

Source

pub fn parse<O, P: Parser<'src, I, O, E>>( &mut self, parser: P, ) -> Result<O, E::Error>

Attempt to parse this input using the given parser.

§Important Notice

Parsers that return Err(...) are permitted to leave the input in an unspecified (but not undefined) state.

The only well-specified action you are permitted to perform on the input after an error has occurred is rewinding to a checkpoint created before the error occurred via InputRef::rewind.

This state is not consistent between releases of chumsky, compilations of the final binary, or even invocations of the parser. You should not rely on this state for anything, and choosing to rely on it means that your parser may break in unexpected ways at any time.

You have been warned.

Source

pub fn check<O, P: Parser<'src, I, O, E>>( &mut self, parser: P, ) -> Result<(), E::Error>

A check-only version of InputRef::parse.

§Import Notice

See InputRef::parse about unspecified behavior associated with this function.

Source

pub fn next_maybe(&mut self) -> Option<MaybeRef<'src, I::Token>>

Get the next token in the input. Returns None if the end of the input has been reached.

This function is more flexible than either InputRef::next or InputRef::next_ref since it only requires that the Input trait be implemented for I (instead of either ValueInput or BorrowInput). However, that increased flexibility for the end user comes with a trade-off for the implementation: this function returns a MaybeRef<I::Token> that provides only a temporary reference to the token.

See InputRef::next_ref if you want get a reference to the next token instead.

Source

pub fn next(&mut self) -> Option<I::Token>
where I: ValueInput<'src>,

Get the next token in the input by value. Returns None if the end of the input has been reached.

See InputRef::next_ref if you want get a reference to the next token instead.

Source

pub fn next_ref(&mut self) -> Option<&'src I::Token>
where I: BorrowInput<'src>,

Get a reference to the next token in the input. Returns None if the end of the input has been reached.

See InputRef::next if you want get the next token by value instead.

Source

pub fn peek_maybe(&mut self) -> Option<MaybeRef<'src, I::Token>>

Peek the next token in the input. Returns None if the end of the input has been reached.

See InputRef::next_maybe for more information about what this function guarantees.

Source

pub fn peek(&mut self) -> Option<I::Token>
where I: ValueInput<'src>,

Peek the next token in the input. Returns None if the end of the input has been reached.

Source

pub fn peek_ref(&mut self) -> Option<&'src I::Token>
where I: BorrowInput<'src>,

Peek the next token in the input. Returns None if the end of the input has been reached.

Source

pub fn skip(&mut self)
where I: ValueInput<'src>,

Skip the next token in the input.

Source

pub fn full_slice(&mut self) -> I::Slice
where I: SliceInput<'src>,

Get full slice of raw input.

Source

pub fn slice(&mut self, range: Range<&Cursor<'src, 'parse, I>>) -> I::Slice
where I: SliceInput<'src>,

Get a slice of the input that covers the given cursor range.

Source

pub fn slice_from( &mut self, range: RangeFrom<&Cursor<'src, 'parse, I>>, ) -> I::Slice
where I: SliceInput<'src>,

Get a slice of the input that covers the given cursor range.

Source

pub fn slice_since( &mut self, range: RangeFrom<&Cursor<'src, 'parse, I>>, ) -> I::Slice
where I: SliceInput<'src>,

Get a slice of the input that covers the given cursor range.

Source

pub fn span_from( &mut self, range: RangeFrom<&Cursor<'src, 'parse, I>>, ) -> I::Span
where I: ExactSizeInput<'src>,

Get a span over the input that goes from the given cursor to the end of the input.

Source

pub fn span_since(&mut self, before: &Cursor<'src, 'parse, I>) -> I::Span

Generate a span that extends from the provided Cursor to the current input position.

Source

pub fn emit(&mut self, error: E::Error)

Emits a non-fatal error at the current position. This is equivalent to emit_at(self.cursor(), error).

Source

pub fn emit_at(&mut self, cursor: Cursor<'src, 'parse, I>, error: E::Error)

Emits a non-fatal error at the given cursor position.

Auto Trait Implementations§

§

impl<'src, 'parse, I, E> Freeze for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: Freeze,

§

impl<'src, 'parse, I, E> RefUnwindSafe for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: RefUnwindSafe, <I as Input<'src>>::Cache: RefUnwindSafe, <E as ParserExtra<'src, I>>::State: RefUnwindSafe, <E as ParserExtra<'src, I>>::Context: RefUnwindSafe, <E as ParserExtra<'src, I>>::Error: RefUnwindSafe,

§

impl<'src, 'parse, I, E> Send for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: Send, <I as Input<'src>>::Cache: Send, <E as ParserExtra<'src, I>>::State: Send, <E as ParserExtra<'src, I>>::Context: Sync, <E as ParserExtra<'src, I>>::Error: Send,

§

impl<'src, 'parse, I, E> Sync for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: Sync, <I as Input<'src>>::Cache: Sync, <E as ParserExtra<'src, I>>::State: Sync, <E as ParserExtra<'src, I>>::Context: Sync, <E as ParserExtra<'src, I>>::Error: Sync,

§

impl<'src, 'parse, I, E> Unpin for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: Unpin,

§

impl<'src, 'parse, I, E> UnsafeUnpin for InputRef<'src, 'parse, I, E>
where <I as Input<'src>>::Cursor: UnsafeUnpin,

§

impl<'src, 'parse, I, E> !UnwindSafe for InputRef<'src, 'parse, I, E>

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> 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

Source§

fn with_span(self, span: S) -> S::Spanned

Invokes WrappingSpan::make_wrapped to wrap an AST node in a span.
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.