mirror of
https://github.com/lloeki/wasp.git
synced 2025-12-06 10:44:39 +01:00
eval + basic stdlib
This commit is contained in:
parent
5bb94d2dda
commit
b6560c6484
5 changed files with 115 additions and 17 deletions
16
repl.py
16
repl.py
|
|
@ -1,5 +1,4 @@
|
|||
import wasp
|
||||
import wasp.parser
|
||||
import readline
|
||||
|
||||
|
||||
|
|
@ -29,21 +28,20 @@ if __name__ == "__main__":
|
|||
# http://stackoverflow.com/questions/5637124
|
||||
#readline.set_completer(complete)
|
||||
|
||||
context = wasp.Context()
|
||||
|
||||
for line in Reader(">> ", banner="WASP %s" % wasp.VERSION):
|
||||
if line == "" or line is None:
|
||||
continue
|
||||
|
||||
try:
|
||||
ptree = wasp.parser.parse(line)
|
||||
except ValueError, e:
|
||||
ast = context['read'](line)
|
||||
except wasp.lib.ReadError, e:
|
||||
print "Parse error:", e.message
|
||||
continue
|
||||
|
||||
print " ^ %s" % ptree
|
||||
try:
|
||||
ast = ptree.ast()
|
||||
except ValueError, e:
|
||||
print "AST error:", e.message
|
||||
print context['eval'](ast, context)
|
||||
except wasp.SymbolError, e:
|
||||
print "Undefined symbol:", e.message
|
||||
continue
|
||||
print " ‡ %r" % ast
|
||||
#ast.eval()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue