allow making REPL using preloaded interpreter
This commit is contained in:
parent
603a1627df
commit
f74a8d8e45
1 changed files with 5 additions and 2 deletions
7
bin/rpl
7
bin/rpl
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue