Struct lrpar::ctbuilder::CTParserBuilder
source · Expand description
A CTParserBuilder
allows one to specify the criteria for building a statically generated
parser.
Implementations§
source§impl CTParserBuilder<u32>
impl CTParserBuilder<u32>
source§impl<StorageT> CTParserBuilder<StorageT>where
StorageT: 'static + Debug + Hash + PrimInt + Serialize + TypeName + Unsigned,
usize: AsPrimitive<StorageT>,
u32: AsPrimitive<StorageT>,
impl<StorageT> CTParserBuilder<StorageT>where
StorageT: 'static + Debug + Hash + PrimInt + Serialize + TypeName + Unsigned,
usize: AsPrimitive<StorageT>,
u32: AsPrimitive<StorageT>,
sourcepub fn new_with_storaget() -> Self
pub fn new_with_storaget() -> Self
Create a new CTParserBuilder
.
StorageT
must be an unsigned integer type (e.g. u8
, u16
) which is big enough to index
(separately) all the tokens, rules, and productions in the grammar and less than or
equal in size to usize
(e.g. on a 64-bit machine u128
would be too big). In other
words, if you have a grammar with 256 tokens, 256 rules, and 256 productions, you
can safely specify u8
here; but if any of those counts becomes 256 you will need to
specify u16
. If you are parsing large files, the additional storage requirements of
larger integer types can be noticeable, and in such cases it can be worth specifying a
smaller type. StorageT
defaults to u32
if unspecified.
Examples
CTParserBuilder::<u8>::new_with_storaget()
.process_file_in_src("grm.y")
.unwrap();
sourcepub fn recoverer(self, rk: RecoveryKind) -> Self
pub fn recoverer(self, rk: RecoveryKind) -> Self
Set the recoverer for this parser to rk
.
sourcepub fn process_file_in_src(
&mut self,
srcp: &str
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>
pub fn process_file_in_src(
&mut self,
srcp: &str
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>
Given the filename x/y.z
as input, statically compile the grammar src/x/y.z
into a Rust
module which can then be imported using lrpar_mod!(x_y)
. This is a convenience function
around process_file
which makes it easier to compile .y
files
stored in a project’s src/
directory.
Note that leaf names must be unique within a single project, even if they are in different
directories: in other words, y.z
and x/y.z
will both be mapped to the same module y_z
(and it is undefined which of the input files will “win” the compilation race).
Panics
If StorageT
is not big enough to index the grammar’s tokens, rules, or
productions.
sourcepub fn action_kind(self, ak: ActionKind) -> Self
pub fn action_kind(self, ak: ActionKind) -> Self
Set the action kind for this parser to ak
.
sourcepub fn error_on_conflicts(self, b: bool) -> Self
pub fn error_on_conflicts(self, b: bool) -> Self
If set to true, process_file_in_src
will return an error if the given grammar contains
any Shift/Reduce or Reduce/Reduce conflicts. Defaults to true
.
sourcepub fn conflicts(
&self
) -> Option<(&YaccGrammar<StorageT>, &StateGraph<StorageT>, &StateTable<StorageT>, &Conflicts<StorageT>)>
pub fn conflicts(
&self
) -> Option<(&YaccGrammar<StorageT>, &StateGraph<StorageT>, &StateTable<StorageT>, &Conflicts<StorageT>)>
If there are any conflicts in the grammar, return a tuple which allows users to inspect
and pretty print them; otherwise returns None
. Note: The conflicts feature is currently
unstable and may change in the future.
sourcepub fn process_file<P, Q>(
&mut self,
inp: P,
outd: Q
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>where
P: AsRef<Path>,
Q: AsRef<Path>,
pub fn process_file<P, Q>(
&mut self,
inp: P,
outd: Q
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>where
P: AsRef<Path>,
Q: AsRef<Path>,
Statically compile the Yacc file inp
into Rust, placing the output file(s) into
the directory outd
. The latter defines a module with the following functions:
fn parser(lexemes: &Vec<Lexeme<StorageT>>)
-> (Option<ActionT>, Vec<LexParseError<StorageT>>)>
fn token_epp<'a>(tidx: TIdx<StorageT>) -> Option<&'a str>
Where ActionT
is either:
- the
%type
value given to the grammar - or, if the
action_kind
was set toActionKind::GenericParseTree
, it isNode<StorageT>
Panics
If StorageT
is not big enough to index the grammar’s tokens, rules, or
productions.