Class: Lrama::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lrama/option_parser.rb

Overview

Handle option parsing for the command line interface.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionParser

Returns a new instance of OptionParser.



21
22
23
24
25
26
# File 'lib/lrama/option_parser.rb', line 21

def initialize
  @options = Options.new
  @trace = []
  @report = []
  @profile = []
end

Class Method Details

.parse(argv) ⇒ Object



16
17
18
# File 'lib/lrama/option_parser.rb', line 16

def self.parse(argv)
  new.parse(argv)
end

Instance Method Details

#parse(argv) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lrama/option_parser.rb', line 29

def parse(argv)
  parse_by_option_parser(argv)

  @options.trace_opts = validate_trace(@trace)
  @options.report_opts = validate_report(@report)
  @options.profile_opts = validate_profile(@profile)
  @options.grammar_file = argv.shift

  unless @options.grammar_file
    abort "File should be specified\n"
  end

  if @options.grammar_file == '-'
    @options.grammar_file = argv.shift or abort "File name for STDIN should be specified\n"
  else
    @options.y = File.open(@options.grammar_file, 'r')
  end

  if !@report.empty? && @options.report_file.nil? && @options.grammar_file
    @options.report_file = File.dirname(@options.grammar_file) + "/" + File.basename(@options.grammar_file, ".*") + ".output"
  end

  if !@options.header_file && @options.header
    case
    when @options.outfile
      @options.header_file = File.dirname(@options.outfile) + "/" + File.basename(@options.outfile, ".*") + ".h"
    when @options.grammar_file
      @options.header_file = File.dirname(@options.grammar_file) + "/" + File.basename(@options.grammar_file, ".*") + ".h"
    end
  end

  @options
end