Parser

Struct Parser 

Source
pub struct Parser<'s> {
    pub filepath: PathBuf,
    pub source_code: &'s str,
    pub root: DocumentFunction,
}
Expand description

Parser holds a reference to the text document source code. To generate better error messages, we also store the filepath. The parsing process fills a tree with data.

A typical parsing process is done with the following methods: consume_iter(iter) takes a LexingIterator and consumes the generated tokens. Then finalize declares the termination of the token consumption. Finally one can fetch the resulting abstract syntax tree by calling the method tree().

Fields§

§filepath: PathBuf§source_code: &'s str§root: DocumentFunction

Implementations§

Source§

impl<'s> Parser<'s>

Source

pub fn new(filepath: &Path, source_code: &'s str) -> Parser<'s>

Source

pub fn consume_iter(&mut self, iter: LexingIterator<'_>) -> Result<(), Error>

Consumes the tokens provided by the LexingIterator argument

Source

pub fn finalize(&mut self) -> Result<(), Error>

Declares the end of the text document

Source

pub fn tree(self) -> DocumentTree

Returns the Abstract Syntax Tree to be processed further

Auto Trait Implementations§

§

impl<'s> Freeze for Parser<'s>

§

impl<'s> RefUnwindSafe for Parser<'s>

§

impl<'s> Send for Parser<'s>

§

impl<'s> Sync for Parser<'s>

§

impl<'s> Unpin for Parser<'s>

§

impl<'s> UnwindSafe for Parser<'s>

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.