Class: Campa::Repl
- Inherits:
-
Object
- Object
- Campa::Repl
- Defined in:
- lib/campa/repl.rb
Instance Method Summary collapse
-
#initialize(evaler, context, reader: Reader) ⇒ Repl
constructor
A new instance of Repl.
-
#run(input, output) ⇒ Object
rubocop: disable Metrics/MethodLength.
Constructor Details
#initialize(evaler, context, reader: Reader) ⇒ Repl
Returns a new instance of Repl.
3 4 5 6 7 8 9 |
# File 'lib/campa/repl.rb', line 3 def initialize(evaler, context, reader: Reader) @reader = reader @evaler = evaler @context = context @environment = @context.push(Context.new) @printer = Printer.new end |
Instance Method Details
#run(input, output) ⇒ Object
rubocop: disable Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/campa/repl.rb', line 12 def run(input, output) output.print "=> " reader = @reader.new(input) loop do begin token = reader.next break if token.nil? show(output, evaler.call(token, environment)) rescue ExecutionError => e handle_exec_error(output, e) rescue StandardError => e handle_standard_error(output, e) end output.print "=> " end rescue Interrupt output.puts "see you soon" end |