Struct Cursor

Source
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>

Source

pub fn cur_span(&self) -> Span

Returns the span of the next Token token.

Does not take into account whitespace or comments.

Source

pub fn error(&self, msg: impl Display) -> Error

Same as Parser::error, but works with the current token in this Cursor instead.

Source

pub fn peek_lparen(self) -> Result<bool>

Tests whether the next token is an lparen

Source

pub fn peek_rparen(self) -> Result<bool>

Tests whether the next token is an rparen

Source

pub fn peek_id(self) -> Result<bool>

Tests whether the next token is an id

Source

pub fn peek_reserved(self) -> Result<bool>

Tests whether the next token is reserved

Source

pub fn peek_keyword(self) -> Result<bool>

Tests whether the next token is a keyword

Source

pub fn peek_integer(self) -> Result<bool>

Tests whether the next token is an integer

Source

pub fn peek_float(self) -> Result<bool>

Tests whether the next token is a float

Source

pub fn peek_string(self) -> Result<bool>

Tests whether the next token is a string

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'a>

Source§

fn clone(&self) -> Cursor<'a>

Returns a copy 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<'a> Copy for Cursor<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Cursor<'a>

§

impl<'a> !RefUnwindSafe for Cursor<'a>

§

impl<'a> !Send for Cursor<'a>

§

impl<'a> !Sync for Cursor<'a>

§

impl<'a> Unpin for Cursor<'a>

§

impl<'a> !UnwindSafe for Cursor<'a>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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, 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.