pub struct Builder { /* private fields */ }
Expand description
Builds the configuration for generating and analyzing parol
grammars.
A grammar file is required for almost all possible operations (set with Builder::grammar_file)
Does not actually generate anything until finished.
Implementations§
source§impl Builder
impl Builder
sourcepub fn with_cargo_script_output() -> Self
pub fn with_cargo_script_output() -> Self
Create a new builder fr use in a Cargo build script (build.rs
).
This is the recommended default way to get started.
All the outputs are set relative to the OUT_DIR
environment variable,
as is standard for Cargo build script outputs.
This sets sensible defaults for every output file name.
Method name | CLI Option | Default (relative) name |
---|---|---|
parser_output_file | --parser or -p | “parser.rs” |
actions_output_file | --actions or -a | “grammar_trait.rs” |
expanded_grammar_output_file | --expanded or -e | “grammar-exp.par” |
See the module documentation for how to include these files into your project.
Panics if used outside of a cargo build script.
sourcepub fn with_explicit_output_dir(output: impl AsRef<Path>) -> Self
pub fn with_explicit_output_dir(output: impl AsRef<Path>) -> Self
Create a new builder with an explicitly specified output directory.
This requires that output files be specified explicitly,
unless this check is disabled with Builder::disable_output_sanity_checks
If this detects running inside a build script, it will automatically enable cargo integration.
If output files are specified using absolute paths, it overrides this explicit output dir.
See module docs on “explicit output mode” for more details.
sourcepub fn disable_output_sanity_checks(&mut self) -> &mut Self
pub fn disable_output_sanity_checks(&mut self) -> &mut Self
By default, we require that the generated parser and action files are not discarded.
This disables that check (used for the CLI).
NOTE: When using Builder::with_cargo_script_output
, these are automatically inferred.
sourcepub fn parser_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
pub fn parser_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
Set the output location for the generated parser.
If you are using Builder::with_cargo_script_output, the default output is “$OUT_DIR/parser.rs”.
If you are using an explicitly specified output directory, then this option is required.
sourcepub fn actions_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
pub fn actions_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
Set the actions output location for the generated parser.
If you are using Builder::with_cargo_script_output, the default output is “$OUT_DIR/grammar_trait.rs”.
If you are using an explicitly specified output directory, then this option is required.
sourcepub fn expanded_grammar_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
pub fn expanded_grammar_output_file(&mut self, p: impl AsRef<Path>) -> &mut Self
Set the actions output location for the generated parser.
If you are using Builder::with_cargo_script_output, the default output is “$OUT_DIR/grammar-exp.par”.
Otherwise, this is ignored.
sourcepub fn set_cargo_integration(&mut self, enabled: bool) -> &mut Self
pub fn set_cargo_integration(&mut self, enabled: bool) -> &mut Self
Explicitly enable/disable cargo integration.
This is automatically set to true if you are running a build script,
and is false
otherwise.
sourcepub fn grammar_file(&mut self, grammar: impl AsRef<Path>) -> &mut Self
pub fn grammar_file(&mut self, grammar: impl AsRef<Path>) -> &mut Self
Set the grammar file used as input for parol.
This is required for most operations.
Does not check that the file exists.
sourcepub fn user_type_name(&mut self, name: &str) -> &mut Self
pub fn user_type_name(&mut self, name: &str) -> &mut Self
Set the name of the user type that implements the language processing
sourcepub fn user_trait_module_name(&mut self, name: &str) -> &mut Self
pub fn user_trait_module_name(&mut self, name: &str) -> &mut Self
Set the name of the user module that implements the language processing
This is the module that contains the Self::user_type_name
sourcepub fn max_lookahead(&mut self, k: usize) -> Result<&mut Self, BuilderError>
pub fn max_lookahead(&mut self, k: usize) -> Result<&mut Self, BuilderError>
Set the maximum lookahead for the generated parser.
If nothing is specified, the default lookahead is DEFAULT_MAX_LOOKAHEAD.
Returns a BuilderError if the lookahead is greater than crate::MAX_K.
sourcepub fn inner_attributes(
&mut self,
inner_attributes: Vec<InnerAttributes>,
) -> &mut Self
pub fn inner_attributes( &mut self, inner_attributes: Vec<InnerAttributes>, ) -> &mut Self
Inserts the given inner attributes at the top of the generated trait source.
sourcepub fn enable_auto_generation(&mut self) -> &mut Self
pub fn enable_auto_generation(&mut self) -> &mut Self
Enables the auto-generation of expanded grammar’s semantic actions - experimental
sourcepub fn minimize_boxed_types(&mut self) -> &mut Self
pub fn minimize_boxed_types(&mut self) -> &mut Self
Activate the minimization of boxed types in the generated parser
sourcepub fn trim_parse_tree(&mut self) -> &mut Self
pub fn trim_parse_tree(&mut self) -> &mut Self
Enables trimming of the parse tree during parsing. Generates the call to trim_parse_tree on the parser object before the call of parse.
sourcepub fn begin_generation_with<'l>(
&mut self,
listener: Option<&'l mut dyn BuildListener>,
) -> Result<GrammarGenerator<'l>, BuilderError>
pub fn begin_generation_with<'l>( &mut self, listener: Option<&'l mut dyn BuildListener>, ) -> Result<GrammarGenerator<'l>, BuilderError>
Begin the process of generating the grammar using the specified listener (or None if no listener is desired).
Returns an error if the build is configured incorrectly. In a build script, this is typically a programmer error.
sourcepub fn generate_parser(&mut self) -> Result<()>
pub fn generate_parser(&mut self) -> Result<()>
Generate the parser, writing it to the pre-configured output files.