Class: Ibex::Tables::CompactProductions
- Inherits:
-
Array
- Object
- Array
- Ibex::Tables::CompactProductions
- Defined in:
- lib/ibex/tables/compact_productions.rb
Overview
Production metadata with parallel primitive arrays for the direct parser and a compatible Array-of-Hash surface for generic runtime consumers.
Constant Summary collapse
- VALUES_ACTION =
[Hash[Symbol, untyped]]
1- BORROWED_VALUES_ACTION =
: Integer
2- LOCATION_ACTION =
: Integer
4- COMPOSITION_ACTION =
: Integer
8- POSITIONAL_ACTION =
: Integer
16
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
: Array.
-
#flags ⇒ Object
readonly
: Array.
-
#lengths ⇒ Object
readonly
: Array.
-
#lhs_ids ⇒ Object
readonly
: Array.
Class Method Summary collapse
Instance Method Summary collapse
- #direct_values? ⇒ Boolean
-
#initialize(lhs_ids:, lengths:, actions:, flags:, metadata: {}) ⇒ CompactProductions
constructor
A new instance of CompactProductions.
Constructor Details
#initialize(lhs_ids:, lengths:, actions:, flags:, metadata: {}) ⇒ CompactProductions
Returns a new instance of CompactProductions.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ibex/tables/compact_productions.rb', line 78 def initialize(lhs_ids:, lengths:, actions:, flags:, metadata: {}) size = lhs_ids.length unless lengths.length == size && actions.length == size && flags.length == size raise ArgumentError, "compact production arrays must have the same length" end @lhs_ids = lhs_ids.map { |value| nonnegative_integer!(value, "lhs") }.freeze @lengths = lengths.map { |value| nonnegative_integer!(value, "length") }.freeze @actions = actions.map { |value| action!(value) }.freeze @flags = flags.map { |value| flags!(value) }.freeze validate_markers! (, size) super(Array.new(size) { |index| decode(index, [index]) }) freeze end |
Instance Attribute Details
#actions ⇒ Object (readonly)
: Array
23 24 25 |
# File 'lib/ibex/tables/compact_productions.rb', line 23 def actions @actions end |
#flags ⇒ Object (readonly)
: Array
24 25 26 |
# File 'lib/ibex/tables/compact_productions.rb', line 24 def flags @flags end |
#lengths ⇒ Object (readonly)
: Array
22 23 24 |
# File 'lib/ibex/tables/compact_productions.rb', line 22 def lengths @lengths end |
#lhs_ids ⇒ Object (readonly)
: Array
21 22 23 |
# File 'lib/ibex/tables/compact_productions.rb', line 21 def lhs_ids @lhs_ids end |
Class Method Details
.build(productions) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ibex/tables/compact_productions.rb', line 28 def build(productions) lhs_ids = [] #: Array[Integer] lengths = [] #: Array[Integer] actions = [] #: Array[Symbol?] flags = [] #: Array[Integer] = {} #: Hash[Integer, Hash[Symbol, untyped]] productions.each_with_index do |production, index| lhs_ids << production.fetch(:lhs) lengths << production.fetch(:length) actions << production[:action] flags << flags_for(production) extra = production.except( :lhs, :length, :action, :values_action, :borrowed_values_action, :location_action, :composition_action ) [index] = extra unless extra.empty? end new(lhs_ids: lhs_ids, lengths: lengths, actions: actions, flags: flags, metadata: ) end |
.packed(lhs_ids, lengths, flags, metadata: {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ibex/tables/compact_productions.rb', line 49 def packed(lhs_ids, lengths, flags, metadata: {}) decoded_flags = PackedIntegers.decode_required(flags) actions = decoded_flags.each_index.map do |index| :"_ibex_action_#{index}" unless decoded_flags[index].zero? end new( lhs_ids: PackedIntegers.decode_required(lhs_ids), lengths: PackedIntegers.decode_required(lengths), actions: actions, flags: decoded_flags, metadata: ) end |
Instance Method Details
#direct_values? ⇒ Boolean
95 96 97 |
# File 'lib/ibex/tables/compact_productions.rb', line 95 def direct_values? @direct_values end |