Struct parol::build::Builder

source ·
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

source

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 nameCLI OptionDefault (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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn user_type_name(&mut self, name: &str) -> &mut Self

Set the name of the user type that implements the language processing

source

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

source

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.

source

pub fn range(&mut self) -> &mut Self

Generate range information for AST types

source

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.

source

pub fn enable_auto_generation(&mut self) -> &mut Self

Enables the auto-generation of expanded grammar’s semantic actions - experimental

source

pub fn minimize_boxed_types(&mut self) -> &mut Self

Activate the minimization of boxed types in the generated parser

source

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.

source

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.

source

pub fn generate_parser(&mut self) -> Result<()>

Generate the parser, writing it to the pre-configured output files.

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy 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 CommonGeneratorConfig for Builder

source§

fn user_type_name(&self) -> &str

User type that implements the language processing
source§

fn module_name(&self) -> &str

User type’s module name
source§

fn auto_generate(&self) -> bool

Enable feature auto-generation for expanded grammar’s semantic actions
source§

fn minimize_boxed_types(&self) -> bool

Activate the minimization of boxed types in the generated parser
source§

fn range(&self) -> bool

Generate range information for AST types
source§

impl ParserGeneratorConfig for Builder

source§

fn trim_parse_tree(&self) -> bool

Enables trimming of the parse tree during parsing. Generates the call to trim_parse_tree on the parser object before the call of parse.
source§

impl UserTraitGeneratorConfig for Builder

source§

fn inner_attributes(&self) -> &[InnerAttributes]

Inserts the given inner attributes at the top of the generated trait source.

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V