pub struct ParserGen { /* private fields */ }Implementations§
Source§impl ParserGen
impl ParserGen
Sourcepub fn build_from_rules<T>(rules: ProdRuleSet<T>, name: String) -> Self
pub fn build_from_rules<T>(rules: ProdRuleSet<T>, name: String) -> Self
Creates a ParserGen from a set of production rules and gives it a specific name, which is used to name the user listener trait in the generated code.
If rules already has a name, it is best to use the
BuildFrom<ProdRuleSet<T>> trait.
pub fn set_options(&mut self, options: ParserGenOptions)
pub fn set_name(&mut self, name: String)
pub fn get_name(&self) -> &str
pub fn get_symbol_table(&self) -> Option<&SymbolTable>
pub fn get_parsing_table(&self) -> &LLParsingTable
pub fn set_terminal_hooks(&mut self, terminal_hooks: Vec<TokenId>)
pub fn add_header<T: Into<String>>(&mut self, header: T)
pub fn extend_headers<I: IntoIterator<Item = T>, T: Into<String>>( &mut self, headers: I, )
pub fn add_lib<T: Into<String>>(&mut self, lib: T)
pub fn extend_libs<I: IntoIterator<Item = T>, T: Into<String>>( &mut self, libs: I, )
Sourcepub fn add_nt_type<T: Into<String>>(&mut self, org_var: VarId, var_type: T)
pub fn add_nt_type<T: Into<String>>(&mut self, org_var: VarId, var_type: T)
Declares the type of a non-terminal. The index of the NT, org_var, is the original index
in the ruletree set, which is the index originally assigned when parsing the grammar file.
pub fn get_nt_type(&self, v: VarId) -> &str
Sourcepub fn set_nt_value(&mut self, nt_value: NTValue)
pub fn set_nt_value(&mut self, nt_value: NTValue)
Sets which nonterminals have a value, from nt_value.
pub fn set_nt_has_value(&mut self, v: VarId, has_value: bool)
Sourcepub fn set_gen_parser(&mut self, gen_parser: bool)
pub fn set_gen_parser(&mut self, gen_parser: bool)
Generates the parser source code if gen_parser is true. This option is true by default.
Sourcepub fn set_gen_wrapper(&mut self, gen_wrapper: bool)
pub fn set_gen_wrapper(&mut self, gen_wrapper: bool)
Generates the wrapper source code if gen_parser is true. This option is true by default.
Sourcepub fn set_indent(&mut self, indent: usize)
pub fn set_indent(&mut self, indent: usize)
Sets the source code indentation. This option is 0 by default.
Sourcepub fn set_types_indent(&mut self, indent: usize)
pub fn set_types_indent(&mut self, indent: usize)
Sets the source code indentation of the template for the user types. This option is 0 by default.
Sourcepub fn set_listener_indent(&mut self, indent: usize)
pub fn set_listener_indent(&mut self, indent: usize)
Sets the source code indentation of the template for the listener implementation. This option is 0 by default.
Sourcepub fn set_indents(&mut self, wrapper: usize, types: usize, listner: usize)
pub fn set_indents(&mut self, wrapper: usize, types: usize, listner: usize)
Sets the source code indentation for the wrapper, the template for the user types and the template for the listener implementation.
Sourcepub fn set_gen_span_params(&mut self, gen_span_params: bool)
pub fn set_gen_span_params(&mut self, gen_span_params: bool)
Generates code to give the location of nonterminals and tokens as extra parameters of listener methods.
Sourcepub fn set_gen_token_enums(&mut self, gen_token_enums: bool)
pub fn set_gen_token_enums(&mut self, gen_token_enums: bool)
Generates enums for the terminal and nonterminal values. They may be helpful in the optional
listener trait methods like hook() and intercept_token() when they are used.
§Example
#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(u16)]
pub enum Term {
#[doc = "','"] Comma = 0,
#[doc = "';'"] SemiColon = 1,
}
#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(u16)]
pub enum NTerm {
#[doc = "`program`"] Program = 0,
#[doc = "`stmt_i`, parent: `program`"] StmtI = 1,
}pub fn get_nt_parent(&self, v: VarId) -> Option<VarId>
Sourcepub fn set_include_alts(&mut self, include_alts: bool)
pub fn set_include_alts(&mut self, include_alts: bool)
Include the definitions of the alternatives in the parser, for debugging purposes: allows to print out the alternatives in VERBOSE mode.
pub fn use_full_lib(&mut self, use_full_lib: bool)
pub fn set_crate(&mut self, lcrate: LexigramCrate)
Sourcepub fn gen_source_code(&mut self) -> (String, String, String)
pub fn gen_source_code(&mut self) -> (String, String, String)
Generates the source code of the wrapper and the accompanying templates. Returns
- the indented source of the wrapper
- the indented source of the template for the user types
- the indented source of the template for the listener implementation
pub fn try_gen_source_code( self, ) -> Result<(BufLog, String, String, String), BuildError>
Source§impl ParserGen
impl ParserGen
pub fn get_nt_tree(&self) -> VecTree<VarId>
pub fn get_indented_nt(&self) -> Vec<(VarId, String)>
pub fn nt_info_str(&self) -> Vec<String>
pub fn log_nt_info(&mut self)
pub fn alt_info_str(&self) -> Vec<String>
pub fn log_alt_info(&mut self)
pub fn print_items(&self, indent: usize, show_symbols: bool, show_span: bool)
pub fn print_flags(&self, indent: usize)
Trait Implementations§
Source§impl BuildFrom<ParserGen> for ParserTables
impl BuildFrom<ParserGen> for ParserTables
Source§fn build_from(parser_gen: ParserGen) -> Self
fn build_from(parser_gen: ParserGen) -> Self
Creates a ParserTables, from which a parser can be created dynamically with
parser_table.make_parser().
Source§impl<T> BuildFrom<ProdRuleSet<T>> for ParserGen
impl<T> BuildFrom<ProdRuleSet<T>> for ParserGen
Source§fn build_from(rules: ProdRuleSet<T>) -> Self
fn build_from(rules: ProdRuleSet<T>) -> Self
Creates a ParserGen from a set of production rules.
If the rule set has a name, it’s transmitted to the parser generator to name the user
listener trait in the generated code. If the rule set has no name, a default “Parser” name
is used instead (unless the name is set with ParserGen::set_name().
Source§impl HasBuildErrorSource for ParserGen
impl HasBuildErrorSource for ParserGen
const SOURCE: BuildErrorSource = BuildErrorSource::ParserGen
fn get_build_error_source() -> BuildErrorSource
Source§impl TryBuildFrom<ParserGen> for ParserTables
impl TryBuildFrom<ParserGen> for ParserTables
Source§type Error = BuildError
type Error = BuildError
Auto Trait Implementations§
impl Freeze for ParserGen
impl !RefUnwindSafe for ParserGen
impl Send for ParserGen
impl !Sync for ParserGen
impl Unpin for ParserGen
impl UnsafeUnpin for ParserGen
impl UnwindSafe for ParserGen
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<S> BuildFrom<S> for S
impl<S> BuildFrom<S> for S
Source§fn build_from(source: S) -> S
fn build_from(source: S) -> S
Source§impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
impl<S, T> BuildInto<T> for Swhere
T: BuildFrom<S>,
Source§fn build_into(self) -> T
fn build_into(self) -> T
Calls T::from(self) to convert a S into a T.