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
impl GrammarConfig
sourcepub fn with_non_terminals(self, non_terminals: Vec<String>) -> Self
pub fn with_non_terminals(self, non_terminals: Vec<String>) -> Self
Sets the non-terminals
sourcepub fn with_title(self, title: Option<String>) -> Self
pub fn with_title(self, title: Option<String>) -> Self
Sets an optional title
sourcepub fn with_comment(self, comment: Option<String>) -> Self
pub fn with_comment(self, comment: Option<String>) -> Self
Sets an optional comment
sourcepub fn with_grammar_type(self, grammar_type: GrammarType) -> Self
pub fn with_grammar_type(self, grammar_type: GrammarType) -> Self
Sets the grammar type
sourcepub fn add_scanner(self, scanner_config: ScannerConfig) -> Self
pub fn add_scanner(self, scanner_config: ScannerConfig) -> Self
Adds a scanner configuration
sourcepub fn add_user_type_def(self, alias: String, type_name: String) -> Self
pub fn add_user_type_def(self, alias: String, type_name: String) -> Self
Adds a user type definition
sourcepub fn update_lookahead_size(&mut self, k: usize)
pub fn update_lookahead_size(&mut self, k: usize)
Sets the lookahead size
sourcepub fn update_cfg(&mut self, cfg: Cfg)
pub fn update_cfg(&mut self, cfg: Cfg)
Updates the cfg member after the grammar has been checked and transformed
sourcepub fn generate_augmented_terminals(&self) -> Vec<String>
pub fn generate_augmented_terminals(&self) -> Vec<String>
Generates the augmented tokens vector in the format needed by the lexer generator.
sourcepub fn get_scanner_state_resolver(&self) -> Box<dyn Fn(&[usize]) -> String>
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
sourcepub fn dummy_scanner_state_resolver() -> Box<dyn Fn(&[usize]) -> String>
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
Trait Implementations§
source§impl Clone for GrammarConfig
impl Clone for GrammarConfig
source§fn clone(&self) -> GrammarConfig
fn clone(&self) -> GrammarConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more