Struct 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

Source

pub fn new() -> Self

Creates a default instance.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn prefer_shifts(self, prefer: bool) -> Self

When there are competing REDUCE and SHIFT operations, this settings will always favor SHIFT.

Source

pub fn prefer_shifts_over_empty(self, prefer: bool) -> Self

When there are competing EMPTY reduction and SHIFT, this settings will always favor SHIFT.

Source

pub fn table_type(self, table_type: TableType) -> Self

LR table type to construct.

Source

pub fn parser_algo(self, parser_algo: ParserAlgo) -> Self

LR algorithm to use

Source

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.

Source

pub fn builder_type(self, builder_type: BuilderType) -> Self

Sets builder type. The default builder will deduce AST types and actions.

Source

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.

Source

pub fn generator_table_type( self, generator_table_type: GeneratorTableType, ) -> Self

Sets generator table type. The default is nested static arrays.

Source

pub fn input_type(self, input_type: String) -> Self

Sets the input type. Default is str

Source

pub fn lexical_disamb_most_specific(self, most_specific: bool) -> Self

Lexical disambiguation using most specific match strategy.

Source

pub fn lexical_disamb_longest_match(self, longest_match: bool) -> Self

Lexical disambiguation using longest match strategy.

Source

pub fn lexical_disamb_grammar_order(self, grammar_order: bool) -> Self

Lexical disambiguation using grammar order.

Source

pub fn fancy_regex(self, fancy_regex: bool) -> Self

Set whether or not we use fancy_regex instead of regex

Source

pub fn print_table(self, print_table: bool) -> Self

Source

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.

Source

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.

Source

pub fn actions(self, actions: bool) -> Self

Should actions be generated. true by default. Used only if default builder is used.

Source

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.

Source

pub fn force(self, force: bool) -> Self

Should actions file be recreated if exist. Use with care.

Source

pub fn dot(self, dot: bool) -> Self

If this is set a .dot file with automata visualization will be produced during compiling.

Source

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.

Source

pub fn process_grammar(&self, grammar: &Path) -> Result<()>

Process the given grammar and generates the parser and actions (if default builder is used). Used as the last call to the configured Settings value.

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Settings

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.