Class: Riml::Repl
- Inherits:
-
Object
- Object
- Riml::Repl
- Defined in:
- lib/repl.rb
Constant Summary collapse
- COMPILE_ON =
%w(compile c)
- RELOAD_ON =
%w(reload r)
- EXIT_ON =
%w(quit q)
- HELP_MSG =
<<msg compile riml line(s): #{COMPILE_ON.join(', ')} clear previous class definitions: #{RELOAD_ON.join(', ')} exit repl: #{EXIT_ON.join(', ')} msg
Instance Attribute Summary collapse
-
#compiler_options ⇒ Object
readonly
Returns the value of attribute compiler_options.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
-
#initialize(vi_readline = false, compile_options = {}) ⇒ Repl
constructor
A new instance of Repl.
- #run ⇒ Object
Constructor Details
#initialize(vi_readline = false, compile_options = {}) ⇒ Repl
Returns a new instance of Repl.
25 26 27 28 29 30 31 32 |
# File 'lib/repl.rb', line 25 def initialize(vi_readline = false, = {}) @indent_amount = 0 @line = nil @compiler_options = DEFAULT_COMPILE_OPTIONS.merge() prepare_new_context Readline.vi_editing_mode if vi_readline trap(:INT) { reset!; puts } end |
Instance Attribute Details
#compiler_options ⇒ Object (readonly)
Returns the value of attribute compiler_options.
12 13 14 |
# File 'lib/repl.rb', line 12 def @compiler_options end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
11 12 13 |
# File 'lib/repl.rb', line 11 def line @line end |
Instance Method Details
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/repl.rb', line 34 def run puts HELP_MSG, "\n" while @line = Readline.readline(current_indent, true) line.strip! next if line.empty? line_dc = line.downcase if COMPILE_ON.include?(line_dc) next if current_compilation_unit.empty? compile_unit! elsif RELOAD_ON.include?(line_dc) reload! puts "reloaded" elsif EXIT_ON.include?(line_dc) exit_repl else current_compilation_unit << line check_indents end end end |