Class: Ibex::Runtime::RepairPolicy

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

Overview

Explicit bounded cost and search policy for automatic token repair.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(insert_cost: 1, delete_cost: 1, replace_cost: 2, max_cost: 3, max_configurations: 5_000, max_lookahead: 8, success_shifts: 3, max_stack: 256) ⇒ RepairPolicy

Returns a new instance of RepairPolicy.

RBS:

  • (?insert_cost: Integer, ?delete_cost: Integer, ?replace_cost: Integer, ?max_cost: Integer, ?max_configurations: Integer, ?max_lookahead: Integer, ?success_shifts: Integer, ?max_stack: Integer) -> void

Raises:

  • (ArgumentError)


4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
# File 'lib/json5/generated_parser.rb', line 4487

def initialize(insert_cost: 1, delete_cost: 1, replace_cost: 2, max_cost: 3, max_configurations: 5_000,
               max_lookahead: 8, success_shifts: 3, max_stack: 256)
  values = {
    insert_cost: insert_cost,
    delete_cost: delete_cost,
    replace_cost: replace_cost,
    max_cost: max_cost,
    max_configurations: max_configurations,
    max_lookahead: max_lookahead,
    success_shifts: success_shifts,
    max_stack: max_stack
  }
  invalid = values.find { |_name, value| !value.is_a?(Integer) || !value.positive? }
  raise ArgumentError, "#{invalid.first} must be a positive integer" if invalid
  raise ArgumentError, "success_shifts must not exceed max_lookahead" if success_shifts > max_lookahead

  values.each { |name, value| instance_variable_set(:"@#{name}", value) }
  freeze
end

Instance Attribute Details

#delete_costObject (readonly)

Signature:

  • Integer



4476
4477
4478
# File 'lib/json5/generated_parser.rb', line 4476

def delete_cost
  @delete_cost
end

#insert_costObject (readonly)

Signature:

  • Integer



4475
4476
4477
# File 'lib/json5/generated_parser.rb', line 4475

def insert_cost
  @insert_cost
end

#max_configurationsObject (readonly)

Signature:

  • Integer



4479
4480
4481
# File 'lib/json5/generated_parser.rb', line 4479

def max_configurations
  @max_configurations
end

#max_costObject (readonly)

Signature:

  • Integer



4478
4479
4480
# File 'lib/json5/generated_parser.rb', line 4478

def max_cost
  @max_cost
end

#max_lookaheadObject (readonly)

Signature:

  • Integer



4480
4481
4482
# File 'lib/json5/generated_parser.rb', line 4480

def max_lookahead
  @max_lookahead
end

#max_stackObject (readonly)

Signature:

  • Integer



4482
4483
4484
# File 'lib/json5/generated_parser.rb', line 4482

def max_stack
  @max_stack
end

#replace_costObject (readonly)

Signature:

  • Integer



4477
4478
4479
# File 'lib/json5/generated_parser.rb', line 4477

def replace_cost
  @replace_cost
end

#success_shiftsObject (readonly)

Signature:

  • Integer



4481
4482
4483
# File 'lib/json5/generated_parser.rb', line 4481

def success_shifts
  @success_shifts
end