Struct rustemo_compiler::Settings
source · pub struct Settings { /* private fields */ }
Expand description
Provides parser settings information. It is the main entry point in the
parser generation process. It is meant to be used from the project
build.rs
script. See tests crate build.rs
script
for examples of various configurations.
The first step is to create default Settings
instance, do necessary
configuration by calling methods in a builder (chain) style and, at the end,
call the method to process the grammar, either by directly specifying the
file or recursivelly processing the directory.
Most of these settings are also exposed through rcomp
CLI tool so you can
process grammar and generate parsers from the command line (or shell script)
if you prefer.
You can read more in the Rustemo book
Example
rustemo_compiler::Settings::new().parser_algo(ParserAlgo::GLR).process_crate_dir()
Implementations§
source§impl Settings
impl Settings
sourcepub fn root_dir(self, root_dir: PathBuf) -> Self
pub fn root_dir(self, root_dir: PathBuf) -> Self
Root dir used to calculate output file path from the input grammar path
when the out_dir_root
is not None
.
It can be overridden explicitly or when using process_dir
call.
It is an error if root_dir
is None
, our_dir_root
is set and
CARGO_MANIFEST_DIR
env variable cannot be found.
sourcepub fn out_dir_root(self, out_dir: PathBuf) -> Self
pub fn out_dir_root(self, out_dir: PathBuf) -> Self
Sets output root for the generated parser. By default, the parser is generated in the source tree next to the grammar.
sourcepub fn out_dir_actions_root(self, out_dir: PathBuf) -> Self
pub fn out_dir_actions_root(self, out_dir: PathBuf) -> Self
Output root for the generated actions when default builder is used. By default, actions are generated in the source tree next to the grammar.
sourcepub fn in_source_tree(self) -> Self
pub fn in_source_tree(self) -> Self
Generate both parser and actions (for default builder) in the source
tree, next to the grammar. By default, parser and actions are generated
in out OUT_DIR
.
sourcepub fn actions_in_source_tree(self) -> Self
pub fn actions_in_source_tree(self) -> Self
Generate actions in the source tree (if the default builder is used),
next to the grammar. By default, actions are generated in out OUT_DIR
.
sourcepub fn exclude(self, exclude: Vec<String>) -> Self
pub fn exclude(self, exclude: Vec<String>) -> Self
Excludes path from processing. If path contains any of the string given
in exclude
vector it will be skipped.
sourcepub fn prefer_shifts(self, prefer: bool) -> Self
pub fn prefer_shifts(self, prefer: bool) -> Self
When there are competing REDUCE and SHIFT operations, this settings will always favor SHIFT.
sourcepub fn prefer_shifts_over_empty(self, prefer: bool) -> Self
pub fn prefer_shifts_over_empty(self, prefer: bool) -> Self
When there are competing EMPTY reduction and SHIFT, this settings will always favor SHIFT.
sourcepub fn table_type(self, table_type: TableType) -> Self
pub fn table_type(self, table_type: TableType) -> Self
LR table type to construct.
sourcepub fn parser_algo(self, parser_algo: ParserAlgo) -> Self
pub fn parser_algo(self, parser_algo: ParserAlgo) -> Self
LR algorithm to use
sourcepub fn lexer_type(self, lexer_type: LexerType) -> Self
pub fn lexer_type(self, lexer_type: LexerType) -> Self
Sets lexer type. Default lexer is used for string inputs and is based on regex/string matches from the grammar.
sourcepub fn builder_type(self, builder_type: BuilderType) -> Self
pub fn builder_type(self, builder_type: BuilderType) -> Self
Sets builder type. The default builder will deduce AST types and actions.
sourcepub fn generator_table_type(
self,
generator_table_type: GeneratorTableType
) -> Self
pub fn generator_table_type( self, generator_table_type: GeneratorTableType ) -> Self
Sets generator table type. The default is nested static arrays.
sourcepub fn input_type(self, input_type: String) -> Self
pub fn input_type(self, input_type: String) -> Self
Sets the input type. Default is str
pub fn print_table(self, print_table: bool) -> Self
sourcepub fn partial_parse(self, partial_parse: bool) -> Self
pub fn partial_parse(self, partial_parse: bool) -> Self
If partial parse is allowed parsing can succeed even if the parser didn’t reach the end of the input. Use with care, especially with GLR parsing as it may lead to a large number of partial solutions.
sourcepub fn skip_ws(self, skip_ws: bool) -> Self
pub fn skip_ws(self, skip_ws: bool) -> Self
Should whitespaces be skipped. true
by default. Not used if Layout
rule exists in the Grammar. Used only in the default lexer.
sourcepub fn actions(self, actions: bool) -> Self
pub fn actions(self, actions: bool) -> Self
Should actions be generated. true
by default. Used only if default
builder is used.
sourcepub fn force(self, force: bool) -> Self
pub fn force(self, force: bool) -> Self
Should actions file be recreated if exist. Use with care.
sourcepub fn dot(self, dot: bool) -> Self
pub fn dot(self, dot: bool) -> Self
If this is set a .dot file with automata visualization will be produced during compiling.
sourcepub fn process_dir(&self) -> Result<()>
pub fn process_dir(&self) -> Result<()>
Recursively traverse the root dir and process each Rustemo grammar found. Used as the last call to the configured Settings value.