more improvements to repl

This commit is contained in:
Loic Nageleisen 2014-01-24 23:34:49 +01:00
parent edb56203ce
commit a2f0a836d1
2 changed files with 24 additions and 9 deletions

32
repl.py
View file

@ -1,26 +1,40 @@
import wasp.parser as parser
import wasp
import wasp.parser
import readline
readline.parse_and_bind("tab: complete")
class Reader(object):
def __init__(self):
pass
def __init__(self, prompt, banner=None):
self.prompt = prompt
self.banner = banner
def __iter__(self):
if self.banner:
print self.banner
return self
def __next__(self):
return self.next()
def next(self):
try:
return raw_input(">> ")
return raw_input(self.prompt)
except KeyboardInterrupt:
return None
except EOFError:
raise StopIteration()
if __name__ == "__main__":
for line in Reader():
ptree = parser.parse(line)
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:
print e.message
continue
print " ^ %s" % ptree
ast = ptree.ast()
print "%r" % ast

View file

@ -0,0 +1 @@
VERSION = '0.0.1'