def run(file_path, code, debug=False): if debug: logger.set_verbosity(logger.Verbosity.ALL) if file_path: data = get_file_contents(file_path) else: data = None code = HTMLParser().unescape(code) logger.debug('Input:\n%s' % data) logger.debug('Code:\n\t\t\t%s\n' % code) tokens = lexer.parse(code) logger.debug('Lexer output:') for i, t in enumerate(tokens): logger.debug('\t%d: %s' % (i, t)) logger.debug('') pyser_assert(tokens[0].type is Type.COMMAND.SELECT, LexerError('Incorrect type of first token: %s' % tokens[0])) node = parser.build_tree(tokens) assert isinstance(node, Node) logger.debug('Parser output:\n\n%s' % node) result = interpreter.run(result=data, node=node) return result.get_values()
def main(run_test=None): keep_run = True while keep_run: if run_test != None: keep_run = False text = run_test else: text = input('kode> ') if text == "exit": break if text.strip() == '': continue _, error = run('<stdin>', text) if error: print(error.as_string())
def run_pansy_file(filepath): _ret, _exc = run('<stdin>', 'run("{}")'.format(filepath))
from lib.interpreter import run while True: text = input('Pansy> ') if text == "exit": break if text.strip() == '': continue result, error = run('<stdin>', text) if error: print(error.as_string()) elif result: """ if len(result.elements) == 1: print(repr(result.elements[0])) else: print(repr(result)) """