lib/qlang/exec.rb in qlang-0.0.27000000 vs lib/qlang/exec.rb in qlang-0.0.27100000
- old
+ new
@@ -3,13 +3,15 @@
class Compiler
def initialize(args)
@args = args
end
- def parse!
- ch_compile_type(ARGV.shift)
- parse
+ def output!
+ ch_compile_type(@args.first)
+ parse_string = parse(@args[1])
+ write!(@args[2], parse_string)
+
rescue Exception => e
raise e if @options[:trace] || e.is_a?(SystemExit)
print "#{e.class}: " unless e.class == RuntimeError
puts "#{e.message}"
@@ -26,20 +28,24 @@
when '-Ruby'
Qlang.to_ruby
when '-R'
Qlang.to_r
else
- print 'Q support Ruby and R now.'
+ print 'Q support only Ruby and R now.'
end
end
- def parse
- raise '#{@args[0]} is unsupported option' unless @args[0] == '-q'
- filename = @args[1]
- file = open_file(filename)
- string = read_file(file)
- print(Kconv.tosjis(Qlang.compile(string)), '\n')
+ def parse(file_path)
+ file = open_file(file_path)
+ input_string = read_file(file)
file.close
+ Kconv.tosjis(Qlang.compile(input_string))
+ end
+
+ def write!(output_path, string)
+ open(output_path, 'w') do |f|
+ f.puts string
+ end
end
def open_file(filename, flag = 'r')
return if filename.nil?
File.open(filename, flag)