def create_argument_parser(lexer, parser): argument_parser = ArgumentParser() command, flags = argument_parser.create_argument_parser() if not command or command == 'repl': Repl('>>> ', lexer, parser) elif command == 'help': print("Showing help") else: ExecuteScript(command, error=ArgumentParserException, lexer=lexer, parser=parser)
class TestEvaluator(unittest.TestCase): def setUp(self): # multiple forms in a single test share mutable global env self.r = Repl() def checkForm(self, form, expected): try: ival = self.r.evalForm(form) val, err = getVal(ival), getErr(ival) self.assertTrue(val == expected, "%s => (%s, %s)"%(to_string(form), val, err)) except Exception, why: self.fail("%s => %s"%(form, why))
def main(args): if DEBUG: #test_parser() #test_parser2() test_parser3() parser = Parser() program = ASTProgram() evaluator = Evaluator() repl = Repl(parser=parser, program=program, evaluator=evaluator) if args: filename = open(args[0], "r") source = filename.read() repl.execute_file(source=source) else: repl.loop()
self.tok = next_char next_char = '' # If a token has been found, reset the buffer if out: self.buffer = '' # If the buffer is only spaces, clear it when a word is added if self.buffer.isspace() and not next_char.isspace(): self.buffer = next_char else: self.buffer += next_char # Return the found token if out: return out # If we're here, we got nothing but EOF. raise StopIteration ########NEW FILE######## __FILENAME__ = __main__ from repl import Repl if __name__ == "__main__": repl = Repl() repl.cmdloop() ########NEW FILE########
def main(): """A prompt-read-eval loop.""" repl = Repl('.autocomplete.mat') repl.run_repl()
from repl import Repl if __name__ == "__main__": print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") print("!!! CONTACTS !!!") print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") repl = Repl()
def test_constructor(): r = Repl(True) assert r.interactive == True
def test_constructor2(): r = Repl(False) assert r.interactive == False
import sys from repl import Repl interactive = len(sys.argv) == 1 script = None if len(sys.argv) == 1 else sys.argv[1] repl = Repl(interactive) repl.run(script)
if cout: self.tok = next_char next_char = '' # If a token has been found, reset the buffer if out: self.buffer = '' # If the buffer is only spaces, clear it when a word is added if self.buffer.isspace() and not next_char.isspace(): self.buffer = next_char else: self.buffer += next_char # Return the found token if out: return out # If we're here, we got nothing but EOF. raise StopIteration ########NEW FILE######## __FILENAME__ = __main__ from repl import Repl if __name__ == "__main__": repl = Repl() repl.cmdloop() ########NEW FILE########
def setUp(self): # multiple forms in a single test share mutable global env self.r = Repl()
statements = Parser(tokens).parse() Interpreter().interpret(statements) def init_argparse() -> argparse.ArgumentParser: argparser = argparse.ArgumentParser() argparser.add_argument('--debug', action='store_true') argparser.add_argument('script', nargs='?') return argparser if __name__ == '__main__': if not sys.stdin.isatty(): exit(1) argparser = init_argparse() args_ns = argparser.parse_args(sys.argv[1:]) if args_ns.script: try: interpret_script(args_ns.script) except FileNotFoundError: print(f"Error: no file {args_ns.script} found") exit(0) try: Repl(debug=args_ns.debug).interact() exit(0) except KeyboardInterrupt: print(GOODBYE)