Struct parol::generators::grammar_config::GrammarConfig

source ·
pub struct GrammarConfig {
    pub non_terminals: Vec<String>,
    pub cfg: Cfg,
    pub grammar_type: GrammarType,
    pub title: Option<String>,
    pub comment: Option<String>,
    pub user_type_defs: Vec<(String, String)>,
    pub scanner_configurations: Vec<ScannerConfig>,
    pub lookahead_size: usize,
}
Expand description

Configuration information for a context free grammar. Currently containing the CFG itself along with accompanying information as title and comment of the grammar, user type aliases, maximum lookahead size and a list of scanner configurations. Can later be amended with further information or pragmas that control lexer/parser generation.

Fields§

§non_terminals: Vec<String>

The non-terminals of the original context free grammar from the user’s grammar description before any checks and transformation has been conducted.

§cfg: Cfg

The actual context free grammar. It should be checked and left-factored here. For this task use the crate::generators::grammar_trans::check_and_transform_grammar function to prepare the grammar.

§grammar_type: GrammarType

The type of the grammar

§title: Option<String>

Title of the grammar

§comment: Option<String>

Optional comment

§user_type_defs: Vec<(String, String)>

User type definitions

§scanner_configurations: Vec<ScannerConfig>

At least one scanner configurations

§lookahead_size: usize

The maximum lookahead size, used for lexer generation

Implementations§

source§

impl GrammarConfig

source

pub fn new(cfg: Cfg, lookahead_size: usize) -> Self

Creates a new item

source

pub fn with_non_terminals(self, non_terminals: Vec<String>) -> Self

Sets the non-terminals

source

pub fn with_title(self, title: Option<String>) -> Self

Sets an optional title

source

pub fn with_comment(self, comment: Option<String>) -> Self

Sets an optional comment

source

pub fn with_grammar_type(self, grammar_type: GrammarType) -> Self

Sets the grammar type

source

pub fn add_scanner(self, scanner_config: ScannerConfig) -> Self

Adds a scanner configuration

source

pub fn add_user_type_def(self, alias: String, type_name: String) -> Self

Adds a user type definition

source

pub fn update_lookahead_size(&mut self, k: usize)

Sets the lookahead size

source

pub fn update_cfg(&mut self, cfg: Cfg)

Updates the cfg member after the grammar has been checked and transformed

source

pub fn generate_augmented_terminals(&self) -> Vec<String>

Generates the augmented tokens vector in the format needed by the lexer generator.

source

pub fn get_scanner_state_resolver(&self) -> Box<dyn Fn(&[usize]) -> String>

Generates a function that can be used as scanner_state_resolver argument on Pr::format

source

pub fn dummy_scanner_state_resolver() -> Box<dyn Fn(&[usize]) -> String>

Generates a dummy scanner_state_resolver function that can be used in Pr::format

source

pub fn get_user_type_resolver(&self) -> Box<dyn Fn(&str) -> Option<String>>

Generates a function that can be used as user_type_resolver argument on Pr::format

source

pub fn dummy_user_type_resolver() -> Box<dyn Fn(&str) -> Option<String>>

Generates a dummy user_type_resolver function that can be used in Pr::format

Trait Implementations§

source§

impl Clone for GrammarConfig

source§

fn clone(&self) -> GrammarConfig

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 Debug for GrammarConfig

source§

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

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

impl Default for &GrammarConfig

source§

fn default() -> Self

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

impl Default for GrammarConfig

source§

fn default() -> GrammarConfig

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

impl Display for GrammarConfig

source§

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

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

impl TryFrom<ParolGrammar<'_>> for GrammarConfig

§

type Error = Error

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

fn try_from(grammar: ParolGrammar<'_>) -> Result<Self>

Performs the conversion.

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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