eval + basic stdlib

This commit is contained in:
Loic Nageleisen 2014-01-26 18:56:03 +01:00
parent 5bb94d2dda
commit b6560c6484
5 changed files with 115 additions and 17 deletions

16
repl.py
View file

@ -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()