pub struct Cursor<'a> { /* private fields */ }Expand description
An immutable cursor into a list of tokens.
This cursor cannot be mutated but can be used to parse more tokens in a list
of tokens. Cursors are created from the Parser::step method. This is a
very low-level parsing structure and you likely won’t use it much.
Implementations§
source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
sourcepub fn cur_span(&self) -> Span
pub fn cur_span(&self) -> Span
Returns the span of the next Token token.
Does not take into account whitespace or comments.
sourcepub fn error(&self, msg: impl Display) -> Error
pub fn error(&self, msg: impl Display) -> Error
Same as Parser::error, but works with the current token in this
Cursor instead.
sourcepub fn peek_lparen(self) -> Result<bool>
pub fn peek_lparen(self) -> Result<bool>
Tests whether the next token is an lparen
sourcepub fn peek_rparen(self) -> Result<bool>
pub fn peek_rparen(self) -> Result<bool>
Tests whether the next token is an rparen
sourcepub fn peek_reserved(self) -> Result<bool>
pub fn peek_reserved(self) -> Result<bool>
Tests whether the next token is reserved
sourcepub fn peek_keyword(self) -> Result<bool>
pub fn peek_keyword(self) -> Result<bool>
Tests whether the next token is a keyword
sourcepub fn peek_integer(self) -> Result<bool>
pub fn peek_integer(self) -> Result<bool>
Tests whether the next token is an integer
sourcepub fn peek_float(self) -> Result<bool>
pub fn peek_float(self) -> Result<bool>
Tests whether the next token is a float
sourcepub fn peek_string(self) -> Result<bool>
pub fn peek_string(self) -> Result<bool>
Tests whether the next token is a string
sourcepub fn lparen(self) -> Result<Option<Self>>
pub fn lparen(self) -> Result<Option<Self>>
Attempts to advance this cursor if the current token is a (.
If the current token is (, returns a new Cursor pointing at the
rest of the tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn rparen(self) -> Result<Option<Self>>
pub fn rparen(self) -> Result<Option<Self>>
Attempts to advance this cursor if the current token is a ).
If the current token is ), returns a new Cursor pointing at the
rest of the tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn id(self) -> Result<Option<(&'a str, Self)>>
pub fn id(self) -> Result<Option<(&'a str, Self)>>
Attempts to advance this cursor if the current token is a
Token::Id
If the current token is Id, returns the identifier minus the leading
$ character as well as a new Cursor pointing at the rest of the
tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn keyword(self) -> Result<Option<(&'a str, Self)>>
pub fn keyword(self) -> Result<Option<(&'a str, Self)>>
Attempts to advance this cursor if the current token is a
Token::Keyword
If the current token is Keyword, returns the keyword as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn annotation(self) -> Result<Option<(&'a str, Self)>>
pub fn annotation(self) -> Result<Option<(&'a str, Self)>>
Attempts to advance this cursor if the current token is a
Token::Annotation
If the current token is Annotation, returns the annotation token as well
as a new Cursor pointing at the rest of the tokens in the stream.
Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn reserved(self) -> Result<Option<(&'a str, Self)>>
pub fn reserved(self) -> Result<Option<(&'a str, Self)>>
Attempts to advance this cursor if the current token is a
Token::Reserved
If the current token is Reserved, returns the reserved token as well
as a new Cursor pointing at the rest of the tokens in the stream.
Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn integer(self) -> Result<Option<(Integer<'a>, Self)>>
pub fn integer(self) -> Result<Option<(Integer<'a>, Self)>>
Attempts to advance this cursor if the current token is a
Token::Integer
If the current token is Integer, returns the integer as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn float(self) -> Result<Option<(Float<'a>, Self)>>
pub fn float(self) -> Result<Option<(Float<'a>, Self)>>
Attempts to advance this cursor if the current token is a
Token::Float
If the current token is Float, returns the float as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn string(self) -> Result<Option<(&'a [u8], Self)>>
pub fn string(self) -> Result<Option<(&'a [u8], Self)>>
Attempts to advance this cursor if the current token is a
Token::String
If the current token is String, returns the byte value of the string
as well as a new Cursor pointing at the rest of the tokens in the
stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn comment(self) -> Result<Option<(&'a str, Self)>>
pub fn comment(self) -> Result<Option<(&'a str, Self)>>
Attempts to advance this cursor if the current token is a
Token::LineComment or a
Token::BlockComment
This function will only skip whitespace, no other tokens.