Class: ANTLR3::Rewrite::Replace

Inherits:
RewriteOperation show all
Defined in:
lib/antlr3/streams/rewrite.rb

Overview

Represents rewrite operation:

add text op.text to the rewrite buffer in lieu of the text of tokens indexed within the range op.index .. op.last_index

Direct Known Subclasses

Delete

Instance Attribute Summary

Attributes inherited from RewriteOperation

#location, #stream, #text

Instance Method Summary collapse

Methods inherited from RewriteOperation

#inspect, #name

Constructor Details

#initialize(stream, location, text) ⇒ Replace

Returns a new instance of Replace.


122
123
124
125
# File 'lib/antlr3/streams/rewrite.rb', line 122

def initialize( stream, location, text )
  super( stream, nil, text )
  self.location = location
end

Instance Method Details

#execute(buffer) ⇒ Object


136
137
138
139
# File 'lib/antlr3/streams/rewrite.rb', line 136

def execute( buffer )
  buffer << text.to_s unless text.nil?
  return( location.end + 1 )
end

#indexObject


141
142
143
# File 'lib/antlr3/streams/rewrite.rb', line 141

def index
  location.first
end

#location=(val) ⇒ Object


127
128
129
130
131
132
133
134
# File 'lib/antlr3/streams/rewrite.rb', line 127

def location=( val )
  case val
  when Range then super( val )
  else
    val = val.to_i
    super( val..val )
  end
end