Class: Mirah::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mirah/commands/base.rb

Direct Known Subclasses

Compile, Parse, Run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
30
# File 'lib/mirah/commands/base.rb', line 24

def initialize(args)
  Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
  @state = Mirah::Util::CompilationState.new
  @state.command = command_name
  @args = args
  @argument_processor = Mirah::Util::ArgumentProcessor.new(@state, @args)
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



32
33
34
# File 'lib/mirah/commands/base.rb', line 32

def args
  @args
end

#argument_processorObject

Returns the value of attribute argument_processor.



32
33
34
# File 'lib/mirah/commands/base.rb', line 32

def argument_processor
  @argument_processor
end

#stateObject

Returns the value of attribute state.



32
33
34
# File 'lib/mirah/commands/base.rb', line 32

def state
  @state
end

Instance Method Details

#execute_baseObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mirah/commands/base.rb', line 34

def execute_base
  # because MirahCommand is a JRuby Java class, SystemExit bubbles through and makes noise
  # so we use a catch/throw to early exit instead
  # see process_errors.rb
  catch(:exit) do
    begin
      argument_processor.process
      yield
    rescue Mirah::InternalCompilerError => ice
      Mirah.print_error(ice.message, ice.position) if ice.node
      raise ice.cause if (ice.cause && state.verbose)
      raise ice
    rescue Mirah::MirahError => ex
      Mirah.print_error(ex.message, ex.position)
      puts ex.backtrace if state.verbose
    end
  end
end