[−][src]Struct lrpar::CTParserBuilder
A CTParserBuilder
allows one to specify the criteria for building a statically generated
parser.
Implementations
impl<'a> CTParserBuilder<'a, u32>
[src]
pub fn new() -> Self
[src]
Create a new CTParserBuilder
.
Examples
CTParserBuilder::new()
.process_file_in_src("grm.y")
.unwrap();
impl<'a, StorageT> CTParserBuilder<'a, StorageT> where
StorageT: 'static + Debug + Hash + PrimInt + Serialize + Unsigned,
usize: AsPrimitive<StorageT>,
u32: AsPrimitive<StorageT>,
[src]
StorageT: 'static + Debug + Hash + PrimInt + Serialize + Unsigned,
usize: AsPrimitive<StorageT>,
u32: AsPrimitive<StorageT>,
pub fn new_with_storaget() -> Self
[src]
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();
pub fn mod_name(mut self: Self, mod_name: &'a str) -> Self
[src]
Set the generated module name to mod_name
. If no module name is specified,
process_file
will attempt to create a sensible default based on
the input filename.
pub fn visibility(mut self: Self, vis: Visibility) -> Self
[src]
Set the visibility of the generated module to vis
. Defaults to Visibility::Private
.
pub fn recoverer(mut self: Self, rk: RecoveryKind) -> Self
[src]
Set the recoverer for this parser to rk
. Defaults to RecoveryKind::CPCTPlus
.
pub fn yacckind(mut self: Self, yk: YaccKind) -> Self
[src]
Set the YaccKind
for this parser to ak
.
pub fn error_on_conflicts(mut self: Self, b: bool) -> Self
[src]
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
.
pub fn conflicts(
&self
) -> Option<(&YaccGrammar<StorageT>, &StateGraph<StorageT>, &StateTable<StorageT>, &Conflicts<StorageT>)>
[src]
&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.
pub fn process_file_in_src(
&mut self,
srcp: &str
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>
[src]
&mut self,
srcp: &str
) -> Result<HashMap<String, StorageT>, Box<dyn Error>>
Given the filename a/b.y
as input, statically compile the grammar src/a/b.y
into a Rust
module which can then be imported using lrpar_mod!("a/b.y")
. This is a convenience
function around process_file
which makes it easier to compile
grammar files stored in a project's src/
directory: please see
process_file
for additional constraints and information about the
generated files.
pub fn process_file<P, Q>(
&mut self,
inp: P,
outp: Q
) -> Result<HashMap<String, StorageT>, Box<dyn Error>> where
P: AsRef<Path>,
Q: AsRef<Path>,
[src]
&mut self,
inp: P,
outp: 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 into the file outp
.
Note that three additional files will be created with the same name as outp
but with the
extensions grm
, and stable
, overwriting any existing files with those names.
outp
defines a module as follows:
mod modname {
pub fn parse(lexemes: &::std::vec::Vec<::lrpar::Lexeme<StorageT>>) { ... }
-> (::std::option::Option<ActionT>,
::std::vec::Vec<::lrpar::LexParseError<StorageT>>)> { ...}
pub fn token_epp<'a>(tidx: ::cfgrammar::TIdx<StorageT>) -> ::std::option::Option<&'a str> {
...
}
...
}
where:
modname
is either:- the module name specified
mod_name
- or, if no module name was explicitly specified, then for the file
/a/b/c.y
the module name isc_y
(i.e. the file's leaf name, minus its extension, with a prefix of_y
).
- the module name specified
ActionT
is either:- the
%actiontype
value given to the grammar - or, if the
yacckind
was set YaccKind::Original(YaccOriginalActionKind::UserAction), it isNode<StorageT>
- the
Panics
If StorageT
is not big enough to index the grammar's tokens, rules, or
productions.
Auto Trait Implementations
impl<'a, StorageT> RefUnwindSafe for CTParserBuilder<'a, StorageT> where
StorageT: RefUnwindSafe,
[src]
StorageT: RefUnwindSafe,
impl<'a, StorageT> Send for CTParserBuilder<'a, StorageT> where
StorageT: Send,
[src]
StorageT: Send,
impl<'a, StorageT> Sync for CTParserBuilder<'a, StorageT> where
StorageT: Sync,
[src]
StorageT: Sync,
impl<'a, StorageT> Unpin for CTParserBuilder<'a, StorageT> where
StorageT: Unpin,
[src]
StorageT: Unpin,
impl<'a, StorageT> UnwindSafe for CTParserBuilder<'a, StorageT> where
StorageT: UnwindSafe,
[src]
StorageT: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,