Sha256: 15f841810a3cee4fac366d23e2853c8e9842bcfe0fd1ed7a52de61a8feae9c5a

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module Qlang
  module Exec
    class Compiler
      def initialize(args)
        @args = args
      end

      def parse!
        ch_compile_type(ARGV.shift)
        parse
      rescue Exception => e
        raise e if @options[:trace] || e.is_a?(SystemExit)

        print "#{e.class}: " unless e.class == RuntimeError
        puts "#{e.message}"
        puts "  Use --trace for backtrace."
        exit 1
      ensure
        exit 0
      end

      private

        def ch_compile_type(lang)
          case lang
          when '-Ruby'
            Qlang.to_ruby
          when '-R'
            Qlang.to_r
          else
            print 'Q support 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')
          file.close
        end

        def open_file(filename, flag = 'r')
          return if filename.nil?
          File.open(filename, flag)
        end

        def read_file(file)
          file.read
        end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qlang-0.0.27000000 lib/qlang/exec.rb
qlang-0.0.27 lib/qlang/exec.rb
qlang-0.0.14142135 lib/qlang/exec.rb
qlang-0.0.1414213 lib/qlang/exec.rb
qlang-0.0.141421 lib/qlang/exec.rb
qlang-0.0.14142 lib/qlang/exec.rb