# File lib/rexical/rexcmd.rb, line 63 63: def initialize 64: @status = 2 65: @cmd = File.basename($0, ".rb") 66: tmp = OPTIONS.collect do |line| 67: next if /\A\s*\z/ === line 68: disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5) 69: a = [] 70: a.push lopt unless lopt == '-' 71: a.push sopt unless sopt == '-' 72: a.push takearg == '-' ? 73: GetoptLong::NO_ARGUMENT : GetoptLong::REQUIRED_ARGUMENT 74: a 75: end 76: getopt = GetoptLong.new(*tmp.compact) 77: getopt.quiet = true 78: 79: @opt = {} 80: begin 81: getopt.each do |name, arg| 82: raise GetoptLong::InvalidOption, 83: "#{@cmd}: #{name} given twice" if @opt.key? name 84: @opt[name] = arg.empty? ? true : arg 85: end 86: rescue GetoptLong::AmbigousOption, GetoptLong::InvalidOption, 87: GetoptLong::MissingArgument, GetoptLong::NeedlessArgument 88: usage $!.message 89: end 90: 91: usage if @opt['--help'] 92: 93: if @opt['--version'] 94: puts "#{@cmd} version #{Rexical::Version}" 95: exit 0 96: end 97: if @opt['--copyright'] 98: puts "#{@cmd} version #{Rexical::Version}" 99: puts "#{Rexical::Copyright} <#{Rexical::Mailto}>" 100: exit 0 101: end 102: end
# File lib/rexical/rexcmd.rb, line 32 32: def run 33: @status = 1 34: usage 'no grammar file given' if ARGV.empty? 35: usage 'too many grammar files given' if ARGV.size > 1 36: filename = ARGV[0] 37: 38: rex = Rexical::Generator.new(@opt) 39: begin 40: rex.grammar_file = filename 41: rex.read_grammar 42: rex.parse 43: if @opt['--check-only'] 44: $stderr.puts "syntax ok" 45: return 0 46: end 47: rex.write_scanner 48: @status = 0 49: 50: rescue Rexical::ParseError, Errno::ENOENT 51: msg = $!.to_s 52: unless /\A\d/ === msg 53: msg[0,0] = ' ' 54: end 55: $stderr.puts "#{@cmd}:#{rex.grammar_file}:#{rex.lineno}:#{msg}" 56: 57: ensure 58: exit @status 59: 60: end 61: end
# File lib/rexical/rexcmd.rb, line 104 104: def usage( msg=nil ) 105: f = $stderr 106: f.puts "#{@cmd}: #{msg}" if msg 107: f.print Usage: #{@cmd} [options] <grammar file>Options: 108: 109: OPTIONS.each do |line| 110: next if line.strip.empty? 111: if /\A\s*\z/ === line 112: f.puts 113: next 114: end 115: 116: disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5) 117: if disp == 'o' 118: sopt = nil if sopt == '-' 119: lopt = nil if lopt == '-' 120: opt = [sopt, lopt].compact.join(',') 121: 122: takearg = nil if takearg == '-' 123: opt = [opt, takearg].compact.join(' ') 124: 125: f.printf "%-27s %s\n", opt, doc 126: end 127: end 128: 129: exit @status 130: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.