From bc2556da4da437a10346c876e556b6961cb380cc Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 24 Jan 2014 23:16:25 +0100 Subject: [PATCH] better repl reader --- repl.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/repl.py b/repl.py index c47fa4e..4daadfe 100644 --- a/repl.py +++ b/repl.py @@ -1,10 +1,27 @@ import wasp.parser as parser -line = raw_input(">> ") -while line != "": - ptree = parser.parse(line) - print " ^ %s" % ptree - ast = ptree.ast() - print " ‡ %r" % ast - #tree.eval() - line = raw_input(">> ") + +class Reader(object): + def __init__(self): + pass + + def __iter__(self): + return self + + def __next__(self): + return self.next() + + def next(self): + try: + return raw_input(">> ") + except EOFError: + raise StopIteration() + + +if __name__ == "__main__": + for line in Reader(): + ptree = parser.parse(line) + print " ^ %s" % ptree + ast = ptree.ast() + print " ‡ %r" % ast + #ast.eval()