Sha256: 93257900f2ce9eca862e0e4c13ffa30105832dbc7f3960e210aabbe0029cd48d

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module Mirah
  module AST
    java_import 'mirah.impl.MirahParser'
    java_import 'mirah.lang.ast.StringCodeSource'
    java_import 'org.mirah.macros.Macro'
    java_import 'org.mirah.util.SimpleDiagnostics'

    def parse(src, filename='dash_e', raise_errors=false, transformer=nil)
      raise ArgumentError unless transformer
      parse_ruby(transformer, src, filename)
    end
    module_function :parse

    def parse_ruby(transformer, src, filename='-')
      raise ArgumentError if src.nil?
      #filename = transformer.tag_filename(src, filename)
      parser = MirahParser.new
      source = StringCodeSource.new(filename, src)
      parser.diagnostics = SimpleDiagnostics.new(true)
      begin
        ast = parser.parse(source)
        if parser.diagnostics.error_count > 0
          puts "#{parser.diagnostics.error_count} errors, exiting"
          throw :exit, 1
        end
        return ast
      rescue NativeException => ex
        ex.cause.printStackTrace
        raise ex
      rescue => ex
        # if ex.cause.kind_of? Java::OrgMirahMmeta::SyntaxError
        #   ex = SyntaxError.wrap ex.cause, nil
        # end

        if ex.respond_to? :position
          position = ex.cause.position
          Mirah.print_error(ex.cause.message, position)
        end
        raise ex
      end
    end
    module_function :parse_ruby
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mirah-0.1.4-java lib/mirah/transform/ast_ext.rb
mirah-0.1.3-java lib/mirah/transform/ast_ext.rb
mirah-0.1.2-java lib/mirah/transform/ast_ext.rb
mirah-0.1.1-java lib/mirah/transform/ast_ext.rb
mirah-0.1.0-java lib/mirah/transform/ast_ext.rb