Skip to main content

ParserGen

Struct ParserGen 

Source
pub struct ParserGen { /* private fields */ }

Implementations§

Source§

impl ParserGen

Source

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.

Source

pub fn set_options(&mut self, options: ParserGenOptions)

Source

pub fn set_name(&mut self, name: String)

Source

pub fn get_name(&self) -> &str

Source

pub fn get_symbol_table(&self) -> Option<&SymbolTable>

Source

pub fn get_parsing_table(&self) -> &LLParsingTable

Source

pub fn set_terminal_hooks(&mut self, terminal_hooks: Vec<TokenId>)

Source

pub fn add_header<T: Into<String>>(&mut self, header: T)

Source

pub fn extend_headers<I: IntoIterator<Item = T>, T: Into<String>>( &mut self, headers: I, )

Source

pub fn add_lib<T: Into<String>>(&mut self, lib: T)

Source

pub fn extend_libs<I: IntoIterator<Item = T>, T: Into<String>>( &mut self, libs: I, )

Source

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.

Source

pub fn get_nt_type(&self, v: VarId) -> &str

Source

pub fn set_nt_value(&mut self, nt_value: NTValue)

Sets which nonterminals have a value, from nt_value.

Source

pub fn set_nt_has_value(&mut self, v: VarId, has_value: bool)

Source

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.

Source

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.

Source

pub fn set_indent(&mut self, indent: usize)

Sets the source code indentation. This option is 0 by default.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

pub fn get_nt_parent(&self, v: VarId) -> Option<VarId>

Source

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.

Source

pub fn use_full_lib(&mut self, use_full_lib: bool)

Source

pub fn set_crate(&mut self, lcrate: LexigramCrate)

Source

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
Source

pub fn try_gen_source_code( self, ) -> Result<(BufLog, String, String, String), BuildError>

Source§

impl ParserGen

Source

pub fn get_nt_tree(&self) -> VecTree<VarId>

Source

pub fn get_indented_nt(&self) -> Vec<(VarId, String)>

Source

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

Source

pub fn log_nt_info(&mut self)

Source

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

Source

pub fn log_alt_info(&mut self)

Source

pub fn print_items(&self, indent: usize, show_symbols: bool, show_span: bool)

Source

pub fn print_flags(&self, indent: usize)

Trait Implementations§

Source§

impl BuildFrom<ParserGen> for ParserTables

Source§

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

Source§

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

Source§

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

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

impl HasBuildErrorSource for ParserGen

Source§

impl LogReader for ParserGen

Source§

type Item = BufLog

Source§

fn get_log(&self) -> &Self::Item

Source§

fn give_log(self) -> Self::Item

Source§

impl TryBuildFrom<ParserGen> for ParserTables

Source§

type Error = BuildError

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

fn try_build_from(source: ParserGen) -> Result<Self, Self::Error>

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<S> BuildFrom<S> for S

Source§

fn build_from(source: S) -> S

Converts to this type from the input type.
Source§

impl<S, T> BuildInto<T> for S
where T: BuildFrom<S>,

Source§

fn build_into(self) -> T

Calls T::from(self) to convert a S into a T.

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> LogStatus for T
where T: LogReader + Debug,

Source§

fn num_notes(&self) -> usize

Source§

fn num_infos(&self) -> usize

Source§

fn num_warnings(&self) -> usize

Source§

fn num_errors(&self) -> usize

Source§

fn has_no_errors(&self) -> bool

Source§

fn has_no_warnings(&self) -> bool

Source§

fn get_messages(&self) -> impl Iterator<Item = &LogMsg>

Source§

fn get_messages_str(&self) -> String

Source§

fn get_notes(&self) -> impl Iterator<Item = &LogMsg>

Source§

fn get_infos(&self) -> impl Iterator<Item = &LogMsg>

Source§

fn get_warnings(&self) -> impl Iterator<Item = &LogMsg>

Source§

fn get_errors(&self) -> impl Iterator<Item = &LogMsg>

Source§

fn get_totals(&self) -> String

Source§

impl<S, T> TryBuildFrom<S> for T

Source§

type Error = BuildError

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

fn try_build_from(source: S) -> Result<T, <T as TryBuildFrom<S>>::Error>

Performs the conversion.
Source§

impl<S, T> TryBuildInto<T> for S
where T: TryBuildFrom<S>,

Source§

type Error = <T as TryBuildFrom<S>>::Error

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

fn try_build_into(self) -> Result<T, <T as TryBuildFrom<S>>::Error>

Performs the conversion.
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.