class ANTLR3::Main::LexerMain

A class which implements a handy test script which is executed whenever an ANTLR generated lexer file is run directly from the command line.

Public Class Methods

new( lexer_class, options = {} ) click to toggle source
Calls superclass method ANTLR3::Main::Main::new
# File lib/antlr3/main.rb, line 313
def initialize( lexer_class, options = {} )
  super( options )
  @lexer_class = lexer_class
end

Public Instance Methods

display_token( token ) click to toggle source
# File lib/antlr3/main.rb, line 334
def display_token( token )
  case token.channel
  when ANTLR3::DEFAULT_CHANNEL
    prefix = '-->'
    suffix = ''
  when ANTLR3::HIDDEN_CHANNEL
    prefix = '#  '
    suffix = ' (hidden)'
  else
    prefix = '~~>'
    suffix = ' (channel %p)' % token.channel
  end
  
  printf( "%s %-15s %-15p @ line %-3i col %-3i%s\n",
         prefix, token.name, token.text,
         token.line, token.column, suffix )
end
recognize( in_stream ) click to toggle source
# File lib/antlr3/main.rb, line 318
def recognize( in_stream )
  lexer = @lexer_class.new( in_stream )
  
  loop do
    begin
      token = lexer.next_token
      if token.nil? || token.type == ANTLR3::EOF then break
      else display_token( token )
      end
    rescue ANTLR3::RecognitionError => error
      report_error( error )
      break
    end
  end
end