Struct gramatica::Parser

source ·
pub struct Parser<'a, T, Tables: ParsingTablesTrait<T>> {
    pub sets: Vec<StateSet<T>>,
    pub source: &'a str,
    pub source_index: usize,
    pub cursor: &'a str,
    pub tokens: Vec<T>,
    pub tokens_range: Vec<(usize, usize)>,
    pub regex_map: HashMap<String, Regex>,
    pub verbosity: u8,
    pub phantom: PhantomData<Tables>,
}
Expand description

The main structure, containing the intermediate data.

Fields§

§sets: Vec<StateSet<T>>

A list of state groups with shared rules.

§source: &'a str

The string being parsed.

§source_index: usize

The current position at the source string while tokenizing. TODO: this is very inadequate, as they are unicode strings…

§cursor: &'a str

A cursor to current position.

§tokens: Vec<T>

The list of tokens after tokenization.

§tokens_range: Vec<(usize, usize)>

For each token we keep its being index and end index relative to the string. TODO: again, bad idea for unicode strings…

§regex_map: HashMap<String, Regex>

A collection of compiled regular expressions, for repeated use.

§verbosity: u8

0 for no output 1 for for some output on errors 2 for some little info 3 for quite some text

§phantom: PhantomData<Tables>

Implementations§

source§

impl<'a, T: Default + PartialEq + Clone + Debug, Tables: ParsingTablesTrait<T>> Parser<'a, T, Tables>

source

pub fn parse( source: &str, initial: Option<usize>, verbosity: u8 ) -> Result<T, ParsingError>

Direct call to the parsing algorithm. Builds the parser and performs tokenization and parsing itself. source is the string being parsed. initial is initial state, None to use the default. verbosity is one of the following

  • 0 for no output,
  • 1 for for some output on errors,
  • 2 for some little info,
  • 3 for quite some text.
source

pub fn re(&mut self, regex: &'a str, source: &str) -> Option<(usize, String)>

source

pub fn keyword(&mut self, key: &str, source: &str) -> Option<(usize, String)>

source

pub fn tokenize(&mut self) -> Result<(), ParsingError>

source

pub fn earley(&mut self) -> Result<T, ParsingError>

Perform the Earley parser over the internal tokenized string.

source

pub fn compute_value(&mut self, set_index: usize, state_index: usize)

Compute the value of some state, computing other states as needed.

source

pub fn compute_value_recursive(&mut self, set_index: usize, state_index: usize)

Compute the value of some state, computing other states as needed. TODO: avoid recursion, which reaches stacks overflow sometimes.

Auto Trait Implementations§

§

impl<'a, T, Tables> RefUnwindSafe for Parser<'a, T, Tables>where T: RefUnwindSafe, Tables: RefUnwindSafe,

§

impl<'a, T, Tables> Send for Parser<'a, T, Tables>where T: Send, Tables: Send,

§

impl<'a, T, Tables> Sync for Parser<'a, T, Tables>where T: Sync, Tables: Sync,

§

impl<'a, T, Tables> Unpin for Parser<'a, T, Tables>where T: Unpin, Tables: Unpin,

§

impl<'a, T, Tables> UnwindSafe for Parser<'a, T, Tables>where T: UnwindSafe, Tables: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.