Class: Ibex::Verify::ReferenceCollection
- Inherits:
-
Object
- Object
- Ibex::Verify::ReferenceCollection
- Defined in:
- lib/ibex/verify/reference_collection.rb
Overview
Independently derives canonical LR(1) and LR(0) item collections.
Defined Under Namespace
Classes: Collection
Instance Method Summary collapse
- #build(kind) ⇒ Object
-
#initialize(grammar, max_states: 100_000, max_items: 1_000_000) ⇒ ReferenceCollection
constructor
A new instance of ReferenceCollection.
Constructor Details
#initialize(grammar, max_states: 100_000, max_items: 1_000_000) ⇒ ReferenceCollection
Returns a new instance of ReferenceCollection.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ibex/verify/reference_collection.rb', line 24 def initialize(grammar, max_states: 100_000, max_items: 1_000_000) raise ArgumentError, "max_states must be positive" unless max_states.positive? raise ArgumentError, "max_items must be positive" unless max_items.positive? @grammar = grammar @max_states = max_states @max_items = max_items @sets = Analysis::Sets.new(grammar) @productions = grammar.productions.group_by(&:lhs) @item_count = 0 end |
Instance Method Details
#build(kind) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ibex/verify/reference_collection.rb', line 37 def build(kind) raise ArgumentError, "kind must be :lr0 or :lr1" unless %i[lr0 lr1].include?(kind) @item_count = 0 seeds = @grammar.starts.map.with_index do |name, index| raise Ibex::Error, "(verify):1:1: missing start symbol #{name}" unless @grammar.symbol(name) item = kind == :lr1 ? [-index - 1, 0, eof_id] : [-index - 1, 0] account_item closure(Set[item], kind) end collection(seeds, kind) end |