Class: Ibex::Runtime::CST::ParseMemo
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::ParseMemo
- Defined in:
- lib/json5/generated_parser.rb
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 ⇒ Object readonly
- #left_states ⇒ Object readonly
- #production_count ⇒ Object readonly
- #state_count ⇒ Object readonly
Instance Method Summary collapse
- #compatible?(tables) ⇒ Boolean
- #estimated_bytes ⇒ Object
-
#initialize(left_states:, grammar_digest:, state_count:, production_count:) ⇒ ParseMemo
constructor
A new instance of ParseMemo.
- #left_state(preorder_index) ⇒ Object
- #slice(preorder_index, element) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(left_states:, grammar_digest:, state_count:, production_count:) ⇒ ParseMemo
Returns a new instance of ParseMemo.
2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 |
# File 'lib/json5/generated_parser.rb', line 2939 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 ⇒ Object (readonly)
2933 2934 2935 |
# File 'lib/json5/generated_parser.rb', line 2933 def grammar_digest @grammar_digest end |
#left_states ⇒ Object (readonly)
2932 2933 2934 |
# File 'lib/json5/generated_parser.rb', line 2932 def left_states @left_states end |
#production_count ⇒ Object (readonly)
2935 2936 2937 |
# File 'lib/json5/generated_parser.rb', line 2935 def production_count @production_count end |
#state_count ⇒ Object (readonly)
2934 2935 2936 |
# File 'lib/json5/generated_parser.rb', line 2934 def state_count @state_count end |
Instance Method Details
#compatible?(tables) ⇒ Boolean
2963 2964 2965 2966 2967 |
# File 'lib/json5/generated_parser.rb', line 2963 def compatible?(tables) @grammar_digest == tables[:grammar_digest] && @state_count == tables[:state_count] && @production_count == tables[:production_count] end |
#estimated_bytes ⇒ Object
2970 |
# File 'lib/json5/generated_parser.rb', line 2970 def estimated_bytes = @left_states.length * ENTRY_BYTES |
#left_state(preorder_index) ⇒ Object
2952 |
# File 'lib/json5/generated_parser.rb', line 2952 def left_state(preorder_index) = @left_states.fetch(preorder_index) |
#slice(preorder_index, element) ⇒ Object
2955 2956 2957 2958 2959 2960 |
# File 'lib/json5/generated_parser.rb', line 2955 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 ⇒ Object
2973 2974 2975 |
# File 'lib/json5/generated_parser.rb', line 2973 def to_h { "version" => VERSION, "left_states" => @left_states }.freeze end |