Class: Ibex::Runtime::CST::ParseMemo
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::ParseMemo
- Defined in:
- lib/ibex/runtime/cst/incremental/parse_memo.rb,
sig/ibex/runtime/cst/incremental/parse_memo.rbs
Overview
Parser-state metadata parallel to Green preorder occurrences.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- VERSION =
1- ENTRY_BYTES =
8
Instance Attribute Summary collapse
- #grammar_digest ⇒ String readonly
- #left_states ⇒ Array[Integer?] readonly
- #production_count ⇒ Integer readonly
- #state_count ⇒ Integer readonly
Instance Method Summary collapse
- #compatible?(tables) ⇒ Boolean
- #estimated_bytes ⇒ Integer
-
#initialize(left_states:, grammar_digest:, state_count:, production_count:) ⇒ ParseMemo
constructor
A new instance of ParseMemo.
- #left_state(preorder_index) ⇒ Integer?
- #slice(preorder_index, element) ⇒ Array[Integer?]
- #to_h ⇒ Hash[String, untyped]
Constructor Details
#initialize(left_states:, grammar_digest:, state_count:, production_count:) ⇒ ParseMemo
Returns a new instance of ParseMemo.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 19 def initialize(left_states:, grammar_digest:, state_count:, production_count:) unless left_states.all? { |state| state.nil? || state.between?(0, state_count - 1) } raise ArgumentError, "parse memo contains an invalid parser state" end @left_states = left_states.dup.freeze @grammar_digest = grammar_digest.dup.freeze @state_count = state_count @production_count = production_count freeze end |
Instance Attribute Details
#grammar_digest ⇒ String (readonly)
13 14 15 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 13 def grammar_digest @grammar_digest end |
#left_states ⇒ Array[Integer?] (readonly)
12 13 14 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 12 def left_states @left_states end |
#production_count ⇒ Integer (readonly)
15 16 17 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 15 def production_count @production_count end |
#state_count ⇒ Integer (readonly)
14 15 16 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 14 def state_count @state_count end |
Instance Method Details
#compatible?(tables) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 43 def compatible?(tables) @grammar_digest == tables[:grammar_digest] && @state_count == tables[:state_count] && @production_count == tables[:production_count] end |
#estimated_bytes ⇒ Integer
50 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 50 def estimated_bytes = @left_states.length * ENTRY_BYTES |
#left_state(preorder_index) ⇒ Integer?
32 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 32 def left_state(preorder_index) = @left_states.fetch(preorder_index) |
#slice(preorder_index, element) ⇒ Array[Integer?]
35 36 37 38 39 40 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 35 def slice(preorder_index, element) value = @left_states.slice(preorder_index, element.descendant_count) return value if value && value.length == element.descendant_count raise IndexError, "parse memo subtree range is outside the preorder state array" end |
#to_h ⇒ Hash[String, untyped]
53 54 55 |
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 53 def to_h { "version" => VERSION, "left_states" => @left_states }.freeze end |