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 builder_loc_info(self, builder_loc_info: bool) -> Self
pub fn builder_loc_info(self, builder_loc_info: bool) -> Self
Should generated default AST builder types contain location/layout information This is only used if builder-type is default.
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
Sourcepub fn lexical_disamb_most_specific(self, most_specific: bool) -> Self
pub fn lexical_disamb_most_specific(self, most_specific: bool) -> Self
Lexical disambiguation using most specific match strategy.
Sourcepub fn lexical_disamb_longest_match(self, longest_match: bool) -> Self
pub fn lexical_disamb_longest_match(self, longest_match: bool) -> Self
Lexical disambiguation using longest match strategy.
Sourcepub fn lexical_disamb_grammar_order(self, grammar_order: bool) -> Self
pub fn lexical_disamb_grammar_order(self, grammar_order: bool) -> Self
Lexical disambiguation using grammar order.
Sourcepub fn fancy_regex(self, fancy_regex: bool) -> Self
pub fn fancy_regex(self, fancy_regex: bool) -> Self
Set whether or not we use fancy_regex
instead of regex
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 notrace(self, notrace: bool) -> Self
pub fn notrace(self, notrace: bool) -> Self
Should trace log be printed. false
by default. Does nothing for
release builds as trace is only available in debug build. Can also be
set by RUSTEMO_NOTRACE=1
env variable.
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Settings
impl RefUnwindSafe for Settings
impl Send for Settings
impl Sync for Settings
impl Unpin for Settings
impl UnwindSafe for Settings
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more