pub struct SymbolTable { /* private fields */ }Expand description
Stores the names of the terminal and nonterminal symbols when building a parser.
Terminals are defined in the lexicon and don’t change. They have two parts to their name:
- the identifier in the lexicon
- the value, which is the source string they represent (optional)
For example:
Plus : '+';
...
ID : [a-zA-Z][a-zA-Z_0-9]*;If Arrow’s token ID is 0 and ID’s is 24,
t[0] = ("Plus".to_string(), Some("+".to_string()));
t[24] = ("ID".to_string(), None);They’re added to the symbol table with add_terminal().
Nonterminals are defined in the grammar, and possibly completed by new ones when the rules are adapted to the target parser. For example, recursive rules are transformed for LL(1) parsers, which usually adds extra rules.
expr: expr Plus term | term;If expr is 0 and term is 1,
nt[0] = "expr".to_string();
nt[1] = "term".to_string();They’re added with add_nonterminal.
The new rules are called “children” of the transformed rules, and can be added
with add_child_nonterminal(). The name
is the parent’s name followed by “_
nt[2] = "expr_1".to_string()Implementations§
Source§impl SymbolTable
impl SymbolTable
pub fn new() -> Self
pub fn to_fixed_sym_table(self) -> FixedSymTable
pub fn add_terminal<T: Into<String>>( &mut self, name: T, value_maybe: Option<T>, ) -> TokenId
pub fn extend_terminals<I: IntoIterator<Item = (T, Option<T>)>, T: Into<String>>( &mut self, terminals: I, )
pub fn get_terminals(&self) -> impl Iterator<Item = &(String, Option<String>)>
pub fn get_num_t(&self) -> usize
pub fn set_t_value(&mut self, token: TokenId, name_maybe: Option<String>)
pub fn downsize_num_t(&mut self, num_t: usize)
pub fn add_nonterminal<T: Into<String>>(&mut self, name: T) -> VarId
pub fn add_child_nonterminal(&mut self, var: VarId) -> VarId
pub fn extend_nonterminals<I: IntoIterator<Item = T>, T: Into<String>>( &mut self, nonterminals: I, )
pub fn get_nonterminals(&self) -> impl Iterator<Item = &String>
pub fn get_num_nt(&self) -> usize
pub fn remove_nonterminal(&mut self, v: VarId)
pub fn set_nt_name(&mut self, var: VarId, name: String)
Sourcepub fn remove_nt_name(&mut self, var: VarId) -> String
pub fn remove_nt_name(&mut self, var: VarId) -> String
Removes the name assigned to NT var and returns it. Internally, the name of the NT is
replaced by another unique string. The NT is expected to be removed later.
pub fn gen_source_code_t( &self, indent: usize, has_enum: bool, has_array: bool, ) -> String
Trait Implementations§
Source§impl Clone for SymbolTable
impl Clone for SymbolTable
Source§fn clone(&self) -> SymbolTable
fn clone(&self) -> SymbolTable
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SymbolTable
impl Debug for SymbolTable
Source§impl Default for SymbolTable
impl Default for SymbolTable
Source§impl SymInfoTable for SymbolTable
impl SymInfoTable for SymbolTable
Source§fn is_token_data(&self, token: TokenId) -> bool
fn is_token_data(&self, token: TokenId) -> bool
Symbol::T(token) hold lexer string data? Read moreSource§fn is_symbol_t_data(&self, symbol: &Symbol) -> bool
fn is_symbol_t_data(&self, symbol: &Symbol) -> bool
symbol a terminal holding lexer string data? Read morefn is_symbol_t_fixed(&self, symbol: &Symbol) -> bool
fn get_t_str(&self, token: TokenId) -> String
fn get_t_name(&self, token: TokenId) -> String
fn get_nt_name(&self, var: VarId) -> String
Source§fn get_name(&self, symbol: &Symbol) -> String
fn get_name(&self, symbol: &Symbol) -> String
Source§fn get_str(&self, symbol: &Symbol) -> String
fn get_str(&self, symbol: &Symbol) -> String
fn get_name_quote(&self, symbol: &Symbol) -> String
Auto Trait Implementations§
impl Freeze for SymbolTable
impl RefUnwindSafe for SymbolTable
impl Send for SymbolTable
impl Sync for SymbolTable
impl Unpin for SymbolTable
impl UnwindSafe for SymbolTable
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].