Skip to main content

TokenParser

Struct TokenParser 

Source
pub struct TokenParser<'a> { /* private fields */ }
Expand description

Helper for the composition expression parser: a cursor over the text that consumes tokens from its start.

TokenParser::position and TokenParser::length count UTF-16 code units, the unit of the reference implementation.

Implementations§

Source§

impl<'a> TokenParser<'a>

Source

pub fn new(s: &'a str) -> Self

Creates a parser over the given text.

Source

pub fn position(&self) -> i32

The number of UTF-16 code units consumed so far.

Source

pub fn skip_whitespace(&mut self)

Source

pub fn next_is_whitespace(&self) -> bool

Source

pub fn try_consume(&mut self, c: char) -> bool

Consumes the given character if it is next (after white space).

Source

pub fn try_consume_str(&mut self, s: &str) -> bool

Consumes the given text if it is next (after white space).

Source

pub fn try_consume_any(&mut self, chars: &str) -> Option<char>

Consumes whichever of the given characters is next (after white space).

Source

pub fn try_parse_keyword(&mut self, keyword: &str) -> bool

Consumes the given keyword if it is next (after white space) and is not followed by a letter or a digit.

Source

pub fn try_parse_keyword_lower_case( &mut self, keyword_in_lower_case: &str, ) -> bool

Like TokenParser::try_parse_keyword, ignoring the case of the text; the keyword must be given in lower case.

Source

pub fn advance(&mut self, c: i32)

Consumes c UTF-16 code units.

Source

pub fn length(&self) -> i32

The number of UTF-16 code units left.

Source

pub fn try_parse_identifier_with( &mut self, extra_valid_chars: &str, ) -> Option<&'a str>

Consumes an identifier: an ASCII letter followed by ASCII letters, digits and any of the extra valid characters.

Source

pub fn try_parse_identifier(&mut self) -> Option<&'a str>

Consumes an identifier: an ASCII letter followed by ASCII letters and digits.

Source

pub fn try_parse_call(&mut self) -> Option<&'a str>

Consumes a function name (an identifier that may contain dots) together with the opening parenthesis that follows it. Nothing is consumed when the name is not followed by a parenthesis.

Source

pub fn try_parse_float(&mut self) -> Option<f32>

Consumes a single-precision number.

Source

pub fn try_parse_double(&mut self) -> Option<f64>

Consumes a double-precision number.

Source

pub fn is_eof_with_whitespace(&mut self) -> bool

Whether only white space is left (which is consumed).

Source

pub fn as_str(&self) -> &'a str

The text that has not been consumed yet.

Trait Implementations§

Source§

impl<'a> Clone for TokenParser<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for TokenParser<'a>

Source§

impl<'a> Debug for TokenParser<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TokenParser<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TokenParser<'a>

§

impl<'a> RefUnwindSafe for TokenParser<'a>

§

impl<'a> Send for TokenParser<'a>

§

impl<'a> Sync for TokenParser<'a>

§

impl<'a> Unpin for TokenParser<'a>

§

impl<'a> UnsafeUnpin for TokenParser<'a>

§

impl<'a> UnwindSafe for TokenParser<'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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.