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): class Reader(object):
def __init__(self): def __init__(self, prompt, banner=None):
pass self.prompt = prompt
self.banner = banner
def __iter__(self): def __iter__(self):
if self.banner:
print self.banner
return self return self
def __next__(self):
return self.next()
def next(self): def next(self):
try: try:
return raw_input(">> ") return raw_input(self.prompt)
except KeyboardInterrupt:
return None
except EOFError: except EOFError:
raise StopIteration() raise StopIteration()
if __name__ == "__main__": if __name__ == "__main__":
for line in Reader(): for line in Reader(">> ", banner="WASP %s" % wasp.VERSION):
ptree = parser.parse(line) if line == "" or line is None:
continue
try:
ptree = wasp.parser.parse(line)
except ValueError, e:
print e.message
continue
print " ^ %s" % ptree print " ^ %s" % ptree
ast = ptree.ast() ast = ptree.ast()
print "%r" % ast print "%r" % ast

View file

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