Module: ANTLR3::Rewrite

Included in:
TokenRewriteStream
Defined in:
lib/antlr3/streams/rewrite.rb

Defined Under Namespace

Classes: Delete, InsertBefore, Replace, RewriteOperation, RewriteProgram

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#programsObject (readonly)

Returns the value of attribute programs


353
354
355
# File 'lib/antlr3/streams/rewrite.rb', line 353

def programs
  @programs
end

Instance Method Details

#delete(*args) ⇒ Object


402
403
404
# File 'lib/antlr3/streams/rewrite.rb', line 402

def delete( *args )
  @programs[ 'default' ].delete( *args )
end

#delete_program(name = 'default') ⇒ Object


380
381
382
# File 'lib/antlr3/streams/rewrite.rb', line 380

def delete_program( name = 'default' )
  @programs.delete( name )
end

#insert_after(*args) ⇒ Object


394
395
396
# File 'lib/antlr3/streams/rewrite.rb', line 394

def insert_after( *args )
  @programs[ 'default' ].insert_after( *args )
end

#insert_before(*args) ⇒ Object


390
391
392
# File 'lib/antlr3/streams/rewrite.rb', line 390

def insert_before( *args )
  @programs[ 'default' ].insert_before( *args )
end

#original_string(start = 0, finish = size - 1) ⇒ Object


384
385
386
387
388
# File 'lib/antlr3/streams/rewrite.rb', line 384

def original_string( start = 0, finish = size - 1 )
  @position == -1 and fill_buffer
  
  return( self[ start..finish ].map { |t| t.text }.join( '' ) )
end

#program(name = 'default') ⇒ Object


376
377
378
# File 'lib/antlr3/streams/rewrite.rb', line 376

def program( name = 'default' )
  return @programs[ name ]
end

#render(*arguments) ⇒ Object


406
407
408
409
410
411
412
# File 'lib/antlr3/streams/rewrite.rb', line 406

def render( *arguments )
  case arguments.first
  when String, Symbol then name = arguments.shift.to_s
  else name = 'default'
  end
  @programs[ name ].execute( *arguments )
end

#replace(*args) ⇒ Object


398
399
400
# File 'lib/antlr3/streams/rewrite.rb', line 398

def replace( *args )
  @programs[ 'default' ].replace( *args )
end

#rewrite(program_name = 'default', range = nil) ⇒ Object


367
368
369
370
371
372
373
374
# File 'lib/antlr3/streams/rewrite.rb', line 367

def rewrite( program_name = 'default', range = nil )
  program = @programs[ program_name ]
  if block_given?
    yield( program )
    program.execute( range )
  else program
  end
end