pub struct ItemSetCollection {
pub sets: Vec<ItemSet>,
pub goto_table: IndexMap<(StateId, SymbolId), StateId>,
pub symbol_is_terminal: IndexMap<SymbolId, bool>,
}Expand description
Collection of all LR(1) item sets (parser states)
Fields§
§sets: Vec<ItemSet>All computed LR(1) item sets (parser states).
goto_table: IndexMap<(StateId, SymbolId), StateId>GOTO transitions: (from_state, symbol) -> to_state.
symbol_is_terminal: IndexMap<SymbolId, bool>Track which symbols in goto_table are terminals (true) vs non-terminals (false)
Implementations§
Source§impl ItemSetCollection
impl ItemSetCollection
Sourcepub fn build_canonical_collection_augmented(
grammar: &Grammar,
first_follow: &FirstFollowSets,
augmented_start: SymbolId,
_original_start: SymbolId,
eof_symbol: SymbolId,
) -> Self
pub fn build_canonical_collection_augmented( grammar: &Grammar, first_follow: &FirstFollowSets, augmented_start: SymbolId, _original_start: SymbolId, eof_symbol: SymbolId, ) -> Self
Build canonical collection of LR(1) item sets for augmented grammar
Sourcepub fn build_canonical_collection(
grammar: &Grammar,
first_follow: &FirstFollowSets,
) -> Self
pub fn build_canonical_collection( grammar: &Grammar, first_follow: &FirstFollowSets, ) -> Self
Build canonical collection of LR(1) item sets.
§Examples
use adze_glr_core::{FirstFollowSets, ItemSetCollection};
use adze_ir::*;
let mut grammar = Grammar::new("simple".into());
let a = SymbolId(1);
let s = SymbolId(10);
grammar.tokens.insert(a, Token { name: "a".into(), pattern: TokenPattern::String("a".into()), fragile: false });
grammar.rule_names.insert(s, "S".into());
grammar.rules.insert(s, vec![
Rule { lhs: s, rhs: vec![Symbol::Terminal(a)], precedence: None, associativity: None, fields: vec![], production_id: ProductionId(0) },
]);
let ff = FirstFollowSets::compute(&grammar).unwrap();
let collection = ItemSetCollection::build_canonical_collection(&grammar, &ff);
assert!(!collection.sets.is_empty(), "should have at least one state");Trait Implementations§
Source§impl Clone for ItemSetCollection
impl Clone for ItemSetCollection
Source§fn clone(&self) -> ItemSetCollection
fn clone(&self) -> ItemSetCollection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ItemSetCollection
impl RefUnwindSafe for ItemSetCollection
impl Send for ItemSetCollection
impl Sync for ItemSetCollection
impl Unpin for ItemSetCollection
impl UnsafeUnpin for ItemSetCollection
impl UnwindSafe for ItemSetCollection
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
Mutably borrows from an owned value. Read more