Sha256: 259f51707fc150c11fbafc72a1e839f9034b312ca762c2f77a0dc0263b55a270
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
# encoding: utf-8 require 'readline' module Rouge::REPL def self.run!(options = {:backtrace => true}) puts "Rouge #{Rouge::VERSION}" repl_error = lambda do |e| STDOUT.puts "!! #{e.class}: #{e.message}" if options[:backtrace] STDOUT.puts "#{e.backtrace.join "\n"}" end end context = Rouge::Context.new(Rouge[:user]) count = 0 chaining = false while true if !chaining prompt = "#{context.ns.name}=> " input = Readline.readline(prompt, true) else prompt = "#{" " * [0, context.ns.name.length - 2].max}#_=> " input << "\n" + Readline.readline(prompt, true) end if input.nil? STDOUT.print "\n" break end begin form = context.ns.read(input) rescue Rouge::Reader::EOFError next rescue Rouge::Reader::EndOfDataError chaining = true next rescue Rouge::Reader::UnexpectedCharacterError => reader_err repl_error.call reader_err rescue Rouge::Reader::NumberFormatError => reader_err repl_error.call reader_err end chaining = false begin form = Rouge::Compiler.compile( context.ns, Set[*context.lexical_keys], form ) result = context.eval(form) Rouge.print(result, STDOUT) STDOUT.puts count += 1 if count < 10 count.downto(2) do |i| context.set_here :"*#{i}", context[:"*#{i - 1}"] end context.set_here :"*1", result rescue Rouge::Context::ChangeContextException => cce context = cce.context count = 0 rescue => e repl_error.call e end end end end # vim: set sw=2 et cc=80:
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rouge-lang-0.0.11 | lib/rouge/repl.rb |
rouge-lang-0.0.10 | lib/rouge/repl.rb |
rouge-lang-0.0.9 | lib/rouge/repl.rb |