allow making REPL using preloaded interpreter

This commit is contained in:
Gwenhael Le Moine 2022-02-16 16:22:52 +01:00
parent 603a1627df
commit f74a8d8e45
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -6,11 +6,14 @@ require 'readline'
require 'rpl'
class RplRepl
def initialize
@interpreter = Rpl.new
def initialize( interpreter )
interpreter ||= Rpl.new
@interpreter = interpreter
end
def run
print_stack unless @interpreter.stack.empty?
Readline.completion_proc = proc do |s|
( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/)
end