Class: Lrama::OptionParser
- Inherits:
-
Object
- Object
- Lrama::OptionParser
- Defined in:
- lib/lrama/option_parser.rb
Overview
Handle option parsing for the command line interface.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse(argv) ⇒ Object
Constructor Details
#initialize ⇒ OptionParser
Returns a new instance of OptionParser.
21 22 23 24 25 26 |
# File 'lib/lrama/option_parser.rb', line 21 def initialize = 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) .trace_opts = validate_trace(@trace) .report_opts = validate_report(@report) .profile_opts = validate_profile(@profile) .grammar_file = argv.shift unless .grammar_file abort "File should be specified\n" end if .grammar_file == '-' .grammar_file = argv.shift or abort "File name for STDIN should be specified\n" else .y = File.open(.grammar_file, 'r') end if !@report.empty? && .report_file.nil? && .grammar_file .report_file = File.dirname(.grammar_file) + "/" + File.basename(.grammar_file, ".*") + ".output" end if !.header_file && .header case when .outfile .header_file = File.dirname(.outfile) + "/" + File.basename(.outfile, ".*") + ".h" when .grammar_file .header_file = File.dirname(.grammar_file) + "/" + File.basename(.grammar_file, ".*") + ".h" end end end |