<commit_before>from plisp.interpreter import PLispInterpreter

if __name__ == '__main__':
    interpreter = PLispInterpreter()
    while True:
        try:
            line = str(input("> "))
        except (KeyboardInterrupt, EOFError):
            break
        interpreter.load_string(line)
        try:
            res = interpreter.execute()
            print(res)
        except Exception as e:
            print(str(type(e)) + ": " + str(e))
<commit_msg>add source execution from files<commit_after>import argparse
import sys

from plisp.interpreter import PLispInterpreter


def setup_args(parser):
    parser.add_argument('file', type=str, nargs='?', default=None, help="the source file to run")

def repl(interpreter):
    while True:
        try:
            line = str(input("> "))
        except (KeyboardInterrupt, EOFError):
            break
        interpreter.load_string(line)
        try:
            res = interpreter.execute()
            print(res)
        except Exception as e:
            print(str(type(e)) + ": " + str(e), file=sys.stderr)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    setup_args(parser)
    args = parser.parse_args()

    interpreter = PLispInterpreter()
    filename = args.file

    if filename is not None:
        try:
            with open(filename, 'r') as source:
                program = source.read()
        except Exception as e:
            print(str(e), filename=sys.stderr)
        interpreter.load_string(program)
        try:
            interpreter.execute()
        except Exception as e:
            print(str(type(e)) + ": " + str(e), file=sys.stderr)
    else:
        repl(interpreter)

    

{'fraction_non_alphanumeric': 0.11025489033787789, 'fraction_numerical': 0.0, 'mean_word_length': 2.1789077212806025, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3466633', 'n_tokens_mistral': 491, 'n_tokens_neox': 500, 'n_words': 118}