Parser

Struct Parser 

Source
pub struct Parser<'input> { /* private fields */ }
Expand description

A parser containing state for the active parsing of an SVG value

Implementations§

Source§

impl<'input> Parser<'input>

Source

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

Create a new parser with the input

Source

pub fn cursor(&self) -> usize

Returns the current position in the input being read

Source

pub fn read(&mut self) -> Result<char, Error<'input>>

Try reading the next value

§Errors

If the input has ended

Source

pub fn advance(&mut self)

Go to the next value without reading

Source

pub fn rewind(&mut self, n: usize)

Move backwards without reading

Source

pub fn done(&mut self)

Skip remaining input

Source

pub fn try_parse<T, E, F: FnOnce(&mut Self) -> Result<T, E>>( &mut self, f: F, ) -> Result<T, E>

Try parsing a portion of the input, reverting to the original state if failed

§Errors

If the attempted parsing fails

Source

pub fn slice(&self) -> &'input str

Get remaining slice of input

Source

pub fn take_slice(&mut self) -> &'input str

Get remaining slice of input and advance to the end of the input

Source

pub fn slice_from(&self, start: usize) -> &'input str

Get slice from start position to current position

Source

pub fn len(&self) -> usize

Get the length of the remaining input

Source

pub fn is_empty(&self) -> bool

Returns whether the remaining input is empty

Source

pub fn current(&self) -> Result<char, Error<'input>>

Gets the current character of the input

§Errors

If reached the end of input

Source

pub fn take_matches<F: FnMut(char) -> bool>(&mut self, f: F) -> &'input str

Move the cursor forward while the characters match the given predicate

Returns the skipped content as a slice

Source

pub fn skip_matches<F: FnMut(char) -> bool>(&mut self, pat: F)

Moves the cursor forward the number of matching characters

Source

pub fn skip_char(&mut self, char: char)

Moves the cursor forward the number of matching characters

Source

pub fn skip_whitespace(&mut self)

Moves the cursor forward the number of whitespace characters

Source

pub fn expect_done(&self) -> Result<(), Error<'input>>

Asserts the end of the input was reached

§Errors

When the cursor is prior to the end of the string

Source

pub fn expect_char(&mut self, expected: char) -> Result<(), Error<'input>>

Read and assert the next character matches the expected character

§Errors

If the end of the input is reached, or the character does not match

Source

pub fn expect_matches<F: Fn(char) -> Result<bool, &'static str>>( &mut self, expected: &'static str, f: F, ) -> Result<&'input str, Error<'input>>

Read and assert a set of characters matches the expected pattern.

§Errors
  • If the end of the input is reached
  • If none of the characters match the expected pattern
  • If the patterns matcher asserts an error
Source

pub fn expect_whitespace(&mut self) -> Result<(), Error<'input>>

Read and assert a set of characters is whitespace

§Errors

If none of the next characters are whitespace

Source

pub fn expect_str( &mut self, expected: &'static str, ) -> Result<(), Error<'input>>

Read and assert a set of characters matches the given string

§Errors

If the next set of characters does not match the given string

Source

pub fn expect_ident(&mut self) -> Result<&'input str, Error<'input>>

Read and assert a set of characters matches some ident

§Errors

When an invalid ident is received

Source

pub fn expect_ident_matching( &mut self, expected: &'static str, ) -> Result<(), Error<'input>>

Read and assert a set of characters matches the given identifier

§Errors

If the next set of characters does not match the given identifier

Auto Trait Implementations§

§

impl<'input> Freeze for Parser<'input>

§

impl<'input> RefUnwindSafe for Parser<'input>

§

impl<'input> Send for Parser<'input>

§

impl<'input> Sync for Parser<'input>

§

impl<'input> Unpin for Parser<'input>

§

impl<'input> UnwindSafe for Parser<'input>

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> 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, 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.