def process(self): self.response.headers['Content-Type'] = 'text/plain' waa = SlimCore() # register required modules ping = Ping() ping.waa = waa waa.register(ping, "mPing") lang = Lang() lang.waa = waa waa.register(lang, "mLang") str_stream = antlr3.ANTLRStringStream(self.request.get('code')) lexer = slimLexer(str_stream) tokens = antlr3.CommonTokenStream(lexer) parser = slimParser(tokens) parser.core = waa old_stdout = sys.stdout sys.stdout = myout = StringIO() parser.start() sys.stdout = old_stdout self.response.out.write(myout.getvalue())
def test(): waa = SlimCore() # register required modules ping = Ping() ping.waa = waa waa.register(ping, "mPing") lang = Lang() lang.waa = waa waa.register(lang, "mLang") if len(sys.argv) > 1: f = open(sys.argv[1], 'r') file_stream = antlr3.ANTLRInputStream(f) parse(file_stream, waa) else: # launch the interpreter prompt command = "" while (True): print "\n# ", command = sys.stdin.readline() # Exit the interpreter if command.startswith("exit"): break # Dump the structure elif command.startswith("dump"): waa.slim.dump() # Read command else: char_stream = antlr3.ANTLRStringStream(command) parse(char_stream, waa.slim)