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>
impl<'src, 'parse, I: Input<'src>, E: ParserExtra<'src, I>> InputRef<'src, 'parse, I, E>
Sourcepub fn cursor(&self) -> Cursor<'src, 'parse, I>
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.
Sourcepub fn save(
&self,
) -> Checkpoint<'src, 'parse, I, <E::State as Inspector<'src, I>>::Checkpoint>
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.
Sourcepub fn rewind(
&mut self,
checkpoint: Checkpoint<'src, 'parse, I, <E::State as Inspector<'src, I>>::Checkpoint>,
)
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.
Sourcepub fn state(&mut self) -> &mut E::State
pub fn state(&mut self) -> &mut E::State
Get a mutable reference to the state associated with the current parse.
Sourcepub fn ctx(&self) -> &E::Context
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.
Sourcepub fn parse<O, P: Parser<'src, I, O, E>>(
&mut self,
parser: P,
) -> Result<O, E::Error>
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.
Sourcepub fn check<O, P: Parser<'src, I, O, E>>(
&mut self,
parser: P,
) -> Result<(), E::Error>
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.
Sourcepub fn next_maybe(&mut self) -> Option<MaybeRef<'src, I::Token>>
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.
Sourcepub fn next(&mut self) -> Option<I::Token>where
I: ValueInput<'src>,
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.
Sourcepub fn next_ref(&mut self) -> Option<&'src I::Token>where
I: BorrowInput<'src>,
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.
Sourcepub fn peek_maybe(&mut self) -> Option<MaybeRef<'src, I::Token>>
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.
Sourcepub fn peek(&mut self) -> Option<I::Token>where
I: ValueInput<'src>,
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.
Sourcepub fn peek_ref(&mut self) -> Option<&'src I::Token>where
I: BorrowInput<'src>,
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.
Sourcepub fn skip(&mut self)where
I: ValueInput<'src>,
pub fn skip(&mut self)where
I: ValueInput<'src>,
Skip the next token in the input.
Sourcepub fn full_slice(&mut self) -> I::Slicewhere
I: SliceInput<'src>,
pub fn full_slice(&mut self) -> I::Slicewhere
I: SliceInput<'src>,
Get full slice of raw input.
Sourcepub fn slice(&mut self, range: Range<&Cursor<'src, 'parse, I>>) -> I::Slicewhere
I: SliceInput<'src>,
pub fn slice(&mut self, range: Range<&Cursor<'src, 'parse, I>>) -> I::Slicewhere
I: SliceInput<'src>,
Get a slice of the input that covers the given cursor range.
Sourcepub fn slice_from(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Slicewhere
I: SliceInput<'src>,
pub fn slice_from(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Slicewhere
I: SliceInput<'src>,
Get a slice of the input that covers the given cursor range.
Sourcepub fn slice_since(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Slicewhere
I: SliceInput<'src>,
pub fn slice_since(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Slicewhere
I: SliceInput<'src>,
Get a slice of the input that covers the given cursor range.
Sourcepub fn span_from(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Spanwhere
I: ExactSizeInput<'src>,
pub fn span_from(
&mut self,
range: RangeFrom<&Cursor<'src, 'parse, I>>,
) -> I::Spanwhere
I: ExactSizeInput<'src>,
Get a span over the input that goes from the given cursor to the end of the input.
Sourcepub fn span_since(&mut self, before: &Cursor<'src, 'parse, I>) -> I::Span
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.
Auto Trait Implementations§
impl<'src, 'parse, I, E> Freeze for InputRef<'src, 'parse, I, E>
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>
impl<'src, 'parse, I, E> UnsafeUnpin for InputRef<'src, 'parse, I, E>
impl<'src, 'parse, I, E> !UnwindSafe for InputRef<'src, 'parse, I, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> S::Spanned
fn with_span(self, span: S) -> S::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.