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' require 'rpl'
class RplRepl class RplRepl
def initialize def initialize( interpreter )
@interpreter = Rpl.new interpreter ||= Rpl.new
@interpreter = interpreter
end end
def run def run
print_stack unless @interpreter.stack.empty?
Readline.completion_proc = proc do |s| Readline.completion_proc = proc do |s|
( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/) ( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/)
end end