Class: Ibex::Runtime::SyntaxRepairEdit
- Inherits:
-
Object
- Object
- Ibex::Runtime::SyntaxRepairEdit
- Defined in:
- lib/ibex/runtime/syntax_repair.rb,
sig/ibex/runtime/syntax_repair.rbs
Overview
One syntax-only projection of a runtime repair edit. It intentionally carries source bytes and token identity, never an application value.
Instance Attribute Summary collapse
- #cost ⇒ Integer readonly
- #end_byte ⇒ Integer readonly
- #kind ⇒ Symbol readonly
- #original_text ⇒ String readonly
- #position ⇒ Integer readonly
- #replacement_text ⇒ String? readonly
- #start_byte ⇒ Integer readonly
- #token_id ⇒ Integer readonly
- #token_name ⇒ String readonly
Instance Method Summary collapse
-
#initialize(kind:, position:, token_id:, token_name:, cost:, start_byte:, end_byte:, original_text:, replacement_text:) ⇒ SyntaxRepairEdit
constructor
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #to_h ⇒ syntax_edit_document
Constructor Details
#initialize(kind:, position:, token_id:, token_name:, cost:, start_byte:, end_byte:, original_text:, replacement_text:) ⇒ SyntaxRepairEdit
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 35 def initialize(kind:, position:, token_id:, token_name:, cost:, start_byte:, end_byte:, original_text:, replacement_text:) raise ArgumentError, "unknown syntax repair edit #{kind.inspect}" unless RepairEdit::KINDS.include?(kind) unless position.is_a?(Integer) && position >= 0 raise ArgumentError, "syntax repair edit position must be nonnegative" end unless token_id.is_a?(Integer) && token_id >= 0 raise ArgumentError, "syntax repair token id must be nonnegative" end unless token_name.is_a?(String) && !token_name.empty? raise ArgumentError, "syntax repair token name must be a nonempty String" end raise ArgumentError, "syntax repair edit cost must be positive" unless cost.is_a?(Integer) && cost.positive? unless start_byte.is_a?(Integer) && end_byte.is_a?(Integer) && start_byte >= 0 && end_byte >= start_byte raise ArgumentError, "syntax repair byte range is invalid" end unless original_text.is_a?(String) && (replacement_text.nil? || replacement_text.is_a?(String)) raise ArgumentError, "syntax repair edit text must be String values" end if kind == :insert && (start_byte != end_byte || !original_text.empty?) raise ArgumentError, "syntax insertion must have an empty source range" end if kind == :delete && replacement_text != "" raise ArgumentError, "syntax deletion must have an empty replacement" end unless original_text.bytesize == end_byte - start_byte raise ArgumentError, "syntax repair original text does not match its byte range" end @kind = kind @position = position @token_id = token_id @token_name = token_name.dup.freeze @cost = cost @start_byte = start_byte @end_byte = end_byte @original_text = original_text.b.freeze @replacement_text = replacement_text&.b&.freeze freeze end |
Instance Attribute Details
#cost ⇒ Integer (readonly)
26 27 28 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 26 def cost @cost end |
#end_byte ⇒ Integer (readonly)
28 29 30 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 28 def end_byte @end_byte end |
#kind ⇒ Symbol (readonly)
22 23 24 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 22 def kind @kind end |
#original_text ⇒ String (readonly)
29 30 31 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 29 def original_text @original_text end |
#position ⇒ Integer (readonly)
23 24 25 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 23 def position @position end |
#replacement_text ⇒ String? (readonly)
30 31 32 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 30 def replacement_text @replacement_text end |
#start_byte ⇒ Integer (readonly)
27 28 29 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 27 def start_byte @start_byte end |
#token_id ⇒ Integer (readonly)
24 25 26 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 24 def token_id @token_id end |
#token_name ⇒ String (readonly)
25 26 27 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 25 def token_name @token_name end |
Instance Method Details
#to_h ⇒ syntax_edit_document
78 79 80 81 82 83 84 85 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 78 def to_h value = { kind: @kind, position: @position, token_id: @token_id, token_name: @token_name, cost: @cost, start_byte: @start_byte, end_byte: @end_byte, original_text: @original_text, replacement_text: @replacement_text } # @type var value: syntax_edit_document value.freeze end |