[][src]Struct lrpar::CTParserBuilder

pub struct CTParserBuilder<'a, StorageT = u32> where
    StorageT: Eq + Hash
{ /* fields omitted */ }

A CTParserBuilder allows one to specify the criteria for building a statically generated parser.

Methods

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 + TypeName + Unsigned,
    usize: AsPrimitive<StorageT>,
    u32: AsPrimitive<StorageT>, 
[src]

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(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 recoverer(self, rk: RecoveryKind) -> Self[src]

Set the recoverer for this parser to rk.

pub fn yacckind(self, yk: YaccKind) -> Self[src]

Set the YaccKind for this parser to ak.

pub fn error_on_conflicts(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]

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]

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]

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, sgraph, and stable, overwriting any existing files with those names.

outp defines a module as follows:

  mod modname {
    fn parse(lexemes: &::std::vec::Vec<::lrpar::Lexeme<StorageT>>) { ... }
        -> (::std::option::Option<ActionT>,
            ::std::vec::Vec<::lrpar::LexParseError<StorageT>>)> { ...}

    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 is c_y (i.e. the file's leaf name, minus its extension, with a prefix of _y).
  • ActionT is either:
    • the %actiontype value given to the grammar
    • or, if the yacckind was set YaccKind::Original(YaccOriginalActionKind::UserAction), it is Node<StorageT>

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

impl<'a, StorageT> Send for CTParserBuilder<'a, StorageT> where
    StorageT: Send

impl<'a, StorageT> Sync for CTParserBuilder<'a, StorageT> where
    StorageT: Sync

impl<'a, StorageT> Unpin for CTParserBuilder<'a, StorageT> where
    StorageT: Unpin

impl<'a, StorageT> UnwindSafe for CTParserBuilder<'a, StorageT> where
    StorageT: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err