Class: Ibex::Tables::CompactProductions
- Inherits:
-
Array
- Object
- Array
- Ibex::Tables::CompactProductions
- Defined in:
- lib/json5/generated_parser.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, Object?]]
1- BORROWED_VALUES_ACTION =
2- LOCATION_ACTION =
4- COMPOSITION_ACTION =
8- POSITIONAL_ACTION =
16
Instance Attribute Summary collapse
- #actions ⇒ Object readonly
- #flags ⇒ Object readonly
- #lengths ⇒ Object readonly
- #lhs_ids ⇒ Object readonly
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.
9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 |
# File 'lib/json5/generated_parser.rb', line 9888 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)
9830 9831 9832 |
# File 'lib/json5/generated_parser.rb', line 9830 def actions @actions end |
#flags ⇒ Object (readonly)
9831 9832 9833 |
# File 'lib/json5/generated_parser.rb', line 9831 def flags @flags end |
#lengths ⇒ Object (readonly)
9829 9830 9831 |
# File 'lib/json5/generated_parser.rb', line 9829 def lengths @lengths end |
#lhs_ids ⇒ Object (readonly)
9828 9829 9830 |
# File 'lib/json5/generated_parser.rb', line 9828 def lhs_ids @lhs_ids end |
Class Method Details
.build(productions) ⇒ Object
9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 |
# File 'lib/json5/generated_parser.rb', line 9835 def build(productions) lhs_ids = [] #: Array[Integer] lengths = [] #: Array[Integer] actions = [] #: Array[Symbol?] flags = [] #: Array[Integer] = {} #: Hash[Integer, Hash[Symbol, Object?]] productions.each_with_index do |production, index| lhs = production.fetch(:lhs) #: Integer length = production.fetch(:length) #: Integer action = production[:action] #: Symbol? lhs_ids << lhs lengths << length actions << 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
9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 |
# File 'lib/json5/generated_parser.rb', line 9859 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
9905 9906 9907 |
# File 'lib/json5/generated_parser.rb', line 9905 def direct_values? @direct_values end |