def main(mode): if mode == "l-test": testFramework = lexerTests.LexerTests() testFramework.TestNextToken() elif mode == "p-test": testFramework = parserTests.ParserTests() testFramework.TestStatements() elif mode == "a-test": testFramework = astTests.AstTests() testFramework.TestString() elif mode == "repl": print("Starting repl") repl = rp.Repl() else: print(f"Unknown mode: {mode}")
def do_repl(config): #print(mk_green("Welcome to the ")+mk_bold(mk_yellow("Espresso"))+mk_green(" Language!")) # alt. could replace this with a 'communicate' code that tells repl to run its full self.code block # initialize the repl if config.infile is not None: if not os.path.isfile(config.infile): u.r(f'file {config.infile} not found') exit(1) the_repl = repl.Repl(config) for line in prelude: the_repl.run_code([line]) the_repl.update_banner() print("Boot time: {:.3f}".format(time.time() - _start_time)) # This is the important core loop! u.y(f'PID: {os.getpid()}') while True: #readline.write_history_file(histfile) #print("hist len: {} last item: {}".format(readline.get_current_history_length(), readline.get_history_item(readline.get_current_history_length()))) try: line = the_repl.get_input() u.reload_modules(verbose=the_repl.verbose_exceptions) #print(the_repl.line_idx) #the_repl = repl.Repl(repl=the_repl) # updates repl to a new version. This must be done outside of the Repl itself bc otherwise changes to methods won't be included. #print(the_repl.line_idx) the_repl.next(line) except u.VerbatimExc as e: print(e) if the_repl.context.compile: sys.exit(1) except Exception as e: #the program will never crash!!! It catches and prints exceptions and then continues in the while loop! print( u.format_exception(e, u.src_path, verbose=the_repl.verbose_exceptions)) if the_repl.context.compile: sys.exit(1)
def startRepl(self): import repl self.repl = repl.Repl() repl.locals_dir['cb'] = self.callbacks repl.banner = self.getConsoleBanner() self.repl.run()
def main(): user = os.geteuid print('user id is {}',user) repl.Repl().start(sys.stdin,sys.stdout)
import sys, re, time, repl, subprocess, random import os.path sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) import commands #TODO: kban, fkban, voice, unvoice, stab, unstab, unban, invite r = repl.Repl() @commands.add_cmd def kickme(args, user="", hostmask="", extra={}): """kickme - Kick urself {"category":"op"}""" extra["ircsock"].kickuser(extra["channel"], user, "You asked for it!") return "" @commands.add_cmd def rawunban(args, user="", hostmask="", extra={}): """rawunban <nick|nicks|regex> channel - Unban a raw hostmask {"category":"op","permLevel":50,"threaded":false}""" channel = extra["channel"] if len(args.split(" ")) >= 2: channel = args.lstirp().rstrip().split(" ")[-1] args = args.split(channel)[0].lstrip().rstrip() extra["ircsock"].unban(channel, args) return ""
import asyncio import repl async def run_cmd(r, cmd): print(cmd, end='') await r.write(cmd) await r.print_until_idle() async def server_lines(r, loop): await run_cmd(r, '1+2\n') await run_cmd(r, 'show 12342\n') if __name__ == '__main__': loop = asyncio.get_event_loop() r = repl.Repl(loop, 'haskell') r.start() try: loop.run_until_complete(server_lines(r, loop)) except KeyboardInterrupt as e: pass r.close() loop.close()