Module: Mirah::AST

Defined in:
lib/mirah/transform/ast_ext.rb

Class Method Summary collapse

Class Method Details

.parse(src, filename = 'dash_e', raise_errors = false, transformer = nil) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/mirah/transform/ast_ext.rb', line 8

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

.parse_ruby(transformer, src, filename = '-') ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mirah/transform/ast_ext.rb', line 14

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)
  diagnostics = SimpleDiagnostics.new(true)
#     parser.diagnostics = diagnostics # Field "diagnostics" does not seem to exist in the current mirah/mmeta source code, but it did exist in an ancient mmeta.jar.
  begin
    ast = parser.parse(source)
    if 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