mirror of
https://github.com/lloeki/wasp.git
synced 2025-12-06 10:44:39 +01:00
more improvements to repl
This commit is contained in:
parent
edb56203ce
commit
a2f0a836d1
2 changed files with 24 additions and 9 deletions
32
repl.py
32
repl.py
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
VERSION = '0.0.1'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue