Class: Ibex::Tables::CompactProductions

Inherits:
Array
  • Object
show all
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 =

Signature:

  • Integer

2
LOCATION_ACTION =

Signature:

  • Integer

4
COMPOSITION_ACTION =

Signature:

  • Integer

8
POSITIONAL_ACTION =

Signature:

  • Integer

16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lhs_ids:, lengths:, actions:, flags:, metadata: {}) ⇒ CompactProductions

Returns a new instance of CompactProductions.

RBS:

  • (lhs_ids: Array[Integer], lengths: Array[Integer], actions: Array[Symbol?], flags: Array[Integer], ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> void



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!
  validate_metadata!(, size)
  super(Array.new(size) { |index| decode(index, [index]) })
  freeze
end

Instance Attribute Details

#actionsObject (readonly)

Signature:

  • Array[Symbol?]



9830
9831
9832
# File 'lib/json5/generated_parser.rb', line 9830

def actions
  @actions
end

#flagsObject (readonly)

Signature:

  • Array[Integer]



9831
9832
9833
# File 'lib/json5/generated_parser.rb', line 9831

def flags
  @flags
end

#lengthsObject (readonly)

Signature:

  • Array[Integer]



9829
9830
9831
# File 'lib/json5/generated_parser.rb', line 9829

def lengths
  @lengths
end

#lhs_idsObject (readonly)

Signature:

  • Array[Integer]



9828
9829
9830
# File 'lib/json5/generated_parser.rb', line 9828

def lhs_ids
  @lhs_ids
end

Class Method Details

.build(productions) ⇒ Object

RBS:

  • (Array[Hash[Symbol, Object?]] productions) -> CompactProductions



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

RBS:

  • (String lhs_ids, String lengths, String flags, ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> CompactProductions



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

RBS:

  • () -> bool

Returns:

  • (Boolean)


9905
9906
9907
# File 'lib/json5/generated_parser.rb', line 9905

def direct_values?
  @direct_values
end