Class: Parser::Source::TreeRewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rdl/typecheck.rb

Instance Method Summary collapse

Instance Method Details

#align_combine(range, offset, attributes) ⇒ Object



2179
2180
2181
2182
2183
2184
2185
2186
2187
# File 'lib/rdl/typecheck.rb', line 2179

def align_combine(range, offset, attributes)
  if range.length > @source_buffer.source.size ## these are expected to be equal since buffer should be created from range source.
    raise IndexError, "The range #{range} is outside the bounds of the source of size #{@source_buffer.source.size}"
  end
  dummy_range = Parser::Source::Range.new(@source_buffer, range.begin_pos - offset, range.end_pos - offset)
  action = TreeRewriter::Action.new(dummy_range, @enforcer, attributes)
  @action_root = @action_root.combine(action)
  self
end

#align_replace(range, offset, content) ⇒ Object

Had to add some methods to the parser. Specifically, wanted to use ‘replace` for not just method being called, but allso for its receiver and args. Doing so requires aligning the `range` being replaced with the `buffer` containing the string that is being rewritten, in a way that the Parser did not support.



2175
2176
2177
# File 'lib/rdl/typecheck.rb', line 2175

def align_replace(range, offset, content)
  align_combine(range, offset, replacement: content)
end