Module: ANTLR3::Main::Options

Included in:
Main
Defined in:
lib/antlr3/main.rb

Overview

Defines command-line options and attribute mappings shared by all types of Main classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debug_socketObject

Returns the value of attribute debug_socket


65
66
67
# File 'lib/antlr3/main.rb', line 65

def debug_socket
  @debug_socket
end

#encodingObject

the input encoding type; defaults to nil (currently, not used)


57
58
59
# File 'lib/antlr3/main.rb', line 57

def encoding
  @encoding
end

#inputObject

the input stream used by the Main script; defaults to $stdin


59
60
61
# File 'lib/antlr3/main.rb', line 59

def input
  @input
end

#interactiveObject

a boolean flag indicating whether or not to run the Main script in interactive mode; defaults to false


62
63
64
# File 'lib/antlr3/main.rb', line 62

def interactive
  @interactive
end

#no_outputObject

Returns the value of attribute no_output


63
64
65
# File 'lib/antlr3/main.rb', line 63

def no_output
  @no_output
end

#profileObject

Returns the value of attribute profile


64
65
66
# File 'lib/antlr3/main.rb', line 64

def profile
  @profile
end

#ruby_profObject

Returns the value of attribute ruby_prof


66
67
68
# File 'lib/antlr3/main.rb', line 66

def ruby_prof
  @ruby_prof
end

Instance Method Details

#initialize(options = {}) ⇒ Object


68
69
70
71
72
73
74
75
76
# File 'lib/antlr3/main.rb', line 68

def initialize( options = {} )
  @no_output    = options.fetch( :no_output, false )
  @profile      = options.fetch( :profile, false )
  @debug_socket = options.fetch( :debug_socket, false )
  @ruby_prof    = options.fetch( :ruby_prof, false )
  @encoding     = options.fetch( :encoding, nil )
  @interactive  = options.fetch( :interactive, false )
  @input        = options.fetch( :input, $stdin )
end

#parse_options(argv = ARGV) ⇒ Object

constructs an OptionParser and parses the argument list provided by argv


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/antlr3/main.rb', line 79

def parse_options( argv = ARGV )
  oparser = OptionParser.new do | o |
    o.separator 'Input Options:'
    
    o.on( '-i', '-e', '--input "text to process"', doc( <<-END ) ) { |val| @input = val }
    | a string to use as direct input to the recognizer
    END
    
    o.on( '-I', '--interactive', doc( <<-END ) ) { @interactive = true }
    | run an interactive session with the recognizer
    END
  end
  
  setup_options( oparser )
  return oparser.parse( argv )
end