Class: Frepl::ReplCommand

Inherits:
SinglelineStatement show all
Defined in:
lib/frepl/statements/repl_command.rb

Constant Summary collapse

COMMANDS =
{
  'run' => {
    info: 'Run the current set of Fortran code',
    l: lambda { |file| file.run },
  },
  'toggle_debug' => {
    info: 'Toggle debug mode on/off',
    l: lambda { |file| Frepl.debug = !Frepl.debug },
  },
  'help' => {
    info: 'View this hopefully helpful help',
    l: lambda do |file|
      puts "Available Frepl commands:\n"
      COMMANDS.each do |k, v|
        puts "f:#{k} -- #{v[:info]}"
      end
    end
  },
  'z' => {
    info: 'Undo last statement',
    l: lambda do |file|
      file.undo_last!
    end
  }
}

Instance Attribute Summary

Attributes inherited from SinglelineStatement

#line

Instance Method Summary collapse

Methods inherited from SinglelineStatement

#incomplete?, #initialize, #output

Methods inherited from Statement

#incomplete?, #output

Constructor Details

This class inherits a constructor from Frepl::SinglelineStatement

Instance Method Details

#accept(visitor) ⇒ Object



29
30
31
# File 'lib/frepl/statements/repl_command.rb', line 29

def accept(visitor)
  visitor.visit_repl_command(self)
end

#cmdObject



42
43
44
# File 'lib/frepl/statements/repl_command.rb', line 42

def cmd
  @cmd ||= line.match(/f:(.+)/)[1]
end

#run(file) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/frepl/statements/repl_command.rb', line 33

def run(file)
  Frepl.log("running: #{cmd}")
  if COMMANDS.key?(cmd)
    COMMANDS[cmd][:l].call(file)
  else
    puts "Unknown command: `#{cmd}`. Type `f:help` for list of commands."
  end
end