pub struct CTParserBuilder<StorageT = u32>where
    StorageT: Eq + Hash,
{ /* private fields */ }
Expand description

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

Implementations§

Create a new CTParserBuilder.

Examples
CTParserBuilder::new()
    .process_file_in_src("grm.y")
    .unwrap();

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();

Set the recoverer for this parser to rk.

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.

Set the action kind for this parser to ak.

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.

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.

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 to ActionKind::GenericParseTree, it is Node<StorageT>
Panics

If StorageT is not big enough to index the grammar’s tokens, rules, or productions.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.