Class: Ibex::Runtime::SyntaxRepairEdit
- Inherits:
-
Object
- Object
- Ibex::Runtime::SyntaxRepairEdit
- Defined in:
- lib/json5/generated_parser.rb
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 ⇒ Object readonly
- #end_byte ⇒ Object readonly
- #kind ⇒ Object readonly
- #original_text ⇒ Object readonly
- #position ⇒ Object readonly
- #replacement_text ⇒ Object readonly
- #start_byte ⇒ Object readonly
- #token_id ⇒ Object readonly
- #token_name ⇒ Object 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 ⇒ Object
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
5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 |
# File 'lib/json5/generated_parser.rb', line 5101 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 ⇒ Object (readonly)
5092 5093 5094 |
# File 'lib/json5/generated_parser.rb', line 5092 def cost @cost end |
#end_byte ⇒ Object (readonly)
5094 5095 5096 |
# File 'lib/json5/generated_parser.rb', line 5094 def end_byte @end_byte end |
#kind ⇒ Object (readonly)
5088 5089 5090 |
# File 'lib/json5/generated_parser.rb', line 5088 def kind @kind end |
#original_text ⇒ Object (readonly)
5095 5096 5097 |
# File 'lib/json5/generated_parser.rb', line 5095 def original_text @original_text end |
#position ⇒ Object (readonly)
5089 5090 5091 |
# File 'lib/json5/generated_parser.rb', line 5089 def position @position end |
#replacement_text ⇒ Object (readonly)
5096 5097 5098 |
# File 'lib/json5/generated_parser.rb', line 5096 def replacement_text @replacement_text end |
#start_byte ⇒ Object (readonly)
5093 5094 5095 |
# File 'lib/json5/generated_parser.rb', line 5093 def start_byte @start_byte end |
#token_id ⇒ Object (readonly)
5090 5091 5092 |
# File 'lib/json5/generated_parser.rb', line 5090 def token_id @token_id end |
#token_name ⇒ Object (readonly)
5091 5092 5093 |
# File 'lib/json5/generated_parser.rb', line 5091 def token_name @token_name end |
Instance Method Details
#to_h ⇒ Object
5144 5145 5146 5147 5148 5149 5150 5151 |
# File 'lib/json5/generated_parser.rb', line 5144 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 |