class ANTLR3::Debug::RemoteEventSocketListener

A debugging event listener which intercepts debug event messages sent by a EventSocketProxy over an IP socket.

Constants

ESCAPE_MAP

Attributes

host[R]
port[R]

Public Class Methods

new( options = {} ) { |read_event| ... } click to toggle source
Calls superclass method
# File lib/antlr3/debug/socket.rb, line 274
def initialize( options = {} )
  @listener = listener
  @host = options.fetch( :host, 'localhost' )
  @port = options.fetch( :port, DEFAULT_PORT )
  @buffer = StringIO.new
  super do
    connect do
      handshake
      loop do
        yield( read_event )
      end
    end
  end
end

Private Instance Methods

ack() click to toggle source
# File lib/antlr3/debug/socket.rb, line 297
def ack
  @socket.puts( "ack" )
  @socket.flush
end
connect() { || ... } click to toggle source
# File lib/antlr3/debug/socket.rb, line 328
def connect
  TCPSocket.open( @host, @port ) do |socket|
    @socket = socket
    yield
  end
end
handshake() click to toggle source
# File lib/antlr3/debug/socket.rb, line 291
def handshake
  @version = @socket.readline.split( "\t" )[ -1 ]
  @grammar_file = @socket.readline.split( "\t" )[ -1 ]
  ack
end
parse_string( string ) click to toggle source
# File lib/antlr3/debug/socket.rb, line 335
def parse_string( string )
  @buffer.string = string
  @buffer.rewind
  out = ''
  until @buffer.eof?
    case c = @buffer.getc
    when ?\\                    # escape
      nc = @buffer.getc
      out << 
        if nc.between?( ?0, ?9 )  # octal integer
          @buffer.ungetc( nc )
          @buffer.read( 3 ).to_i( 8 ).chr
        elsif nc == ?x
          @buffer.read( 2 ).to_i( 16 ).chr
        else
          ESCAPE_MAP[ nc ]
        end
    else
      out << c
    end
  end
  return out
end
read_event() click to toggle source
# File lib/antlr3/debug/socket.rb, line 322
def read_event
  event = @socket.readline or raise( StopIteration )
  ack
  return unpack_event( event )
end
unpack_event( event ) click to toggle source
# File lib/antlr3/debug/socket.rb, line 302
def unpack_event( event )
  event.nil? and raise( StopIteration )
  event.chomp!
  name, *elements = event.split( "\t",-1 )
  name = name.to_sym
  name == :terminate and raise StopIteration
  elements.map! do |elem|
    elem.empty? and next( nil )
    case elem
    when /^\d+$/ then Integer( elem )
    when /^\d+\.\d+$/ then Float( elem )
    when /^true$/ then true
    when /^false$/ then false
    when /^"(.*)"$/ then parse_string( $1 )
    end
  end
  elements.unshift( name )
  return( elements )
end