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>
impl<'a, T: Default + PartialEq + Clone + Debug, Tables: ParsingTablesTrait<T>> Parser<'a, T, Tables>
sourcepub fn parse(
source: &str,
initial: Option<usize>,
verbosity: u8
) -> Result<T, ParsingError>
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.
pub fn re(&mut self, regex: &'a str, source: &str) -> Option<(usize, String)>
pub fn keyword(&mut self, key: &str, source: &str) -> Option<(usize, String)>
pub fn tokenize(&mut self) -> Result<(), ParsingError>
sourcepub fn earley(&mut self) -> Result<T, ParsingError>
pub fn earley(&mut self) -> Result<T, ParsingError>
Perform the Earley parser over the internal tokenized string.
sourcepub fn compute_value(&mut self, set_index: usize, state_index: usize)
pub fn compute_value(&mut self, set_index: usize, state_index: usize)
Compute the value of some state, computing other states as needed.
sourcepub fn compute_value_recursive(&mut self, set_index: usize, state_index: usize)
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.