Class: Ibex::Runtime::SyntaxRepairPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/json5/generated_parser.rb

Overview

One selected runtime plan plus its source-oriented edit projection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_plan:, edits:) ⇒ SyntaxRepairPlan

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

RBS:

  • (runtime_plan: RepairPlan, edits: Array[SyntaxRepairEdit]) -> void

Raises:

  • (ArgumentError)


5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
# File 'lib/json5/generated_parser.rb', line 5163

def initialize(runtime_plan:, edits:)
  unless runtime_plan.is_a?(RepairPlan) && edits.is_a?(Array) && edits.all?(SyntaxRepairEdit)
    raise ArgumentError, "syntax repair plan requires one runtime plan and syntax edits"
  end
  raise ArgumentError, "syntax repair edit count must match the runtime plan" unless
    runtime_plan.edits.length == edits.length

  runtime_plan.edits.each_with_index do |runtime_edit, index|
    syntax_edit = edits.fetch(index)
    next if runtime_edit.kind == syntax_edit.kind && runtime_edit.position == syntax_edit.position &&
            runtime_edit.token_id == syntax_edit.token_id && runtime_edit.token_name == syntax_edit.token_name &&
            runtime_edit.cost == syntax_edit.cost

    raise ArgumentError, "syntax repair edit metadata must match its runtime plan"
  end

  @runtime_plan = runtime_plan
  @edits = edits.dup.freeze
  @cost = runtime_plan.cost
  @configurations = runtime_plan.configurations
  freeze
end

Instance Attribute Details

#configurationsObject (readonly)

Signature:

  • Integer



5159
5160
5161
# File 'lib/json5/generated_parser.rb', line 5159

def configurations
  @configurations
end

#costObject (readonly)

Signature:

  • Integer



5158
5159
5160
# File 'lib/json5/generated_parser.rb', line 5158

def cost
  @cost
end

#editsObject (readonly)

Signature:

  • Array[SyntaxRepairEdit]



5157
5158
5159
# File 'lib/json5/generated_parser.rb', line 5157

def edits
  @edits
end

#runtime_planObject (readonly)

Signature:

  • RepairPlan



5156
5157
5158
# File 'lib/json5/generated_parser.rb', line 5156

def runtime_plan
  @runtime_plan
end