Class: Python::REPL
- Inherits:
-
Object
- Object
- Python::REPL
- Defined in:
- lib/python/repl.rb
Constant Summary collapse
- ParsingError =
Class.new(RuntimeError)
Instance Method Summary collapse
- #eval(exp) ⇒ Object
-
#initialize(output) ⇒ REPL
constructor
A new instance of REPL.
- #print(obj) ⇒ Object
- #prompt ⇒ Object
- #read(code) ⇒ Object
- #read_eval_print(code) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(output) ⇒ REPL
Returns a new instance of REPL.
8 9 10 11 |
# File 'lib/python/repl.rb', line 8 def initialize(output) @output = output @env = Environment.new end |
Instance Method Details
#eval(exp) ⇒ Object
31 32 33 |
# File 'lib/python/repl.rb', line 31 def eval(exp) exp.eval(@env) end |
#print(obj) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/python/repl.rb', line 35 def print(obj) if obj == nil @output.print "" else @output.puts obj.inspect end end |
#prompt ⇒ Object
43 44 45 |
# File 'lib/python/repl.rb', line 43 def prompt @output.print "python.rb> " end |
#read(code) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/python/repl.rb', line 21 def read(code) parser = Parser::StatementParser.stmt_list result = parser.parse(code) if result.is_a?(Parser::Succeeded) && result.rest.chomp == "" result.parsed else raise ParsingError.new end end |
#read_eval_print(code) ⇒ Object
17 18 19 |
# File 'lib/python/repl.rb', line 17 def read_eval_print(code) print(eval(read(code))) end |
#start ⇒ Object
13 14 15 |
# File 'lib/python/repl.rb', line 13 def start prompt end |