pub(crate) struct Lookahead1<'a, 'cx> {
expected: Vec<Expected>,
cx: &'a mut ParseCtxt<'cx>,
}Expand description
Support for checking the next token in a stream to decide how to parse.
An important advantage of using this struct over ParseCtxt::peek is that here we
automatically construct an appropriate error message based on the token alternatives
that get peeked.
Use ParseCtxt::lookahead1 to construct this object.
Fields§
§expected: Vec<Expected>List of “expected” tokens that have been peeked by this struct
cx: &'a mut ParseCtxt<'cx>Implementations§
Source§impl<'a, 'cx> Lookahead1<'a, 'cx>
impl<'a, 'cx> Lookahead1<'a, 'cx>
fn new(cx: &'a mut ParseCtxt<'cx>) -> Self
Sourcepub(crate) fn peek<T: PeekExpected>(&mut self, t: T) -> bool
pub(crate) fn peek<T: PeekExpected>(&mut self, t: T) -> bool
Like ParseCtxt::lookahead1 but it records the expected token to construct an error in
case parsing can’t proceed. If this method returns true, this Lookahead1 object should be
discarded.
Sourcepub(crate) fn advance_if<T: PeekExpected>(&mut self, t: T) -> bool
pub(crate) fn advance_if<T: PeekExpected>(&mut self, t: T) -> bool
Like ParseCtxt::advance_if but it records the expected token to construct an error in
case parsing can’t proceed. If this method returns true, this Lookahead1 object should be
discarded.
Sourcepub(crate) fn into_error(self) -> ParseError
pub(crate) fn into_error(self) -> ParseError
Create an unexpected token error based on the expected tokens that have been peeked
with this Lookahead1 object.