Class: Ibex::TableArtifact::Builder

Inherits:
Object
  • Object
show all
Includes:
CSTProjection
Defined in:
lib/ibex/table_artifact/builder.rb

Overview

Projects validated Automaton IR into an action-free executable sidecar.

Constant Summary collapse

REPRESENTATIONS =

: Array

%i[plain compact].freeze

Instance Method Summary collapse

Constructor Details

#initialize(automaton, representation: :compact, cst_trivia: nil, omit_action_call: nil) ⇒ Builder

Returns a new instance of Builder.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
# File 'lib/ibex/table_artifact/builder.rb', line 21

def initialize(automaton, representation: :compact, cst_trivia: nil, omit_action_call: nil)
  @automaton = automaton
  @grammar = automaton.grammar
  @representation = representation.to_sym
  @cst_trivia = effective_cst_trivia(cst_trivia)
  @omit_action_call = omit_action_call.nil? ? @grammar.options.fetch(:omit_action_call) : omit_action_call
  return if REPRESENTATIONS.include?(@representation)

  raise ArgumentError, "representation must be :plain or :compact"
end

Instance Method Details

#buildObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ibex/table_artifact/builder.rb', line 33

def build
  source_identity = {
    "grammar_digest" => @automaton.grammar_digest,
    "automaton_digest" => automaton_digest
  }
  payload = build_payload(source_identity)
  cost = build_cost(payload)
  identity = source_identity.merge(
    "payload_digest" => Serializer.digest(payload),
    "cst_metadata_digest" => Serializer.digest(payload.fetch("cst")),
    "recovery_metadata_digest" => Serializer.digest(payload.fetch("recovery"))
  )
  Document.new(
    "artifact_type" => ARTIFACT_TYPE,
    "schema_version" => SCHEMA_VERSION,
    "identity" => identity,
    "payload" => payload,
    "cost" => cost
  )
end