<commit_before>import os
import sys

from rmathics.parser import parse, WaitInputError
from rmathics.evaluation import evaluate
from rmathics.definitions import Definitions


def run(fp):
    program_contents = ""
    while True:
        read = os.read(fp, 4096)
        if len(read) == 0:
            break
        program_contents += read
    os.close(fp)

    definitions = Definitions()
    lines = iter(program_contents.split('\n'))
    for line in lines:
        new_messages = []
        while True:
            try:
                expr, messages = parse(line, definitions)
                break
            except WaitInputError:
                pass
            try:
                line = line + next(lines)
            except StopIteration:
                expr, messages = None, [('Syntax', 'sntup')]
                break
        for message in messages:
            print(message)
        if expr is None:
            continue
        result, messages = evaluate(expr, definitions)
        for message in messages:
            print(message)
        print(">>> " + line)
        print(result.repr())

def entry_point(argv):
    try:
        filename = argv[1]
    except IndexError:
        print("You must supply a filename")
        return 1
    run(os.open(filename, os.O_RDONLY, 0o777))
    return 0


def target(*args):
    return entry_point, None


if __name__ == "__main__":
    entry_point(sys.argv)<commit_msg>move input printing before parsing messages<commit_after>import os
import sys

from rmathics.parser import parse, WaitInputError
from rmathics.evaluation import evaluate
from rmathics.definitions import Definitions


def run(fp):
    program_contents = ""
    while True:
        read = os.read(fp, 4096)
        if len(read) == 0:
            break
        program_contents += read
    os.close(fp)

    definitions = Definitions()
    lines = iter(program_contents.split('\n'))
    for line in lines:
        new_messages = []
        while True:
            try:
                expr, messages = parse(line, definitions)
                break
            except WaitInputError:
                pass
            try:
                line = line + next(lines)
            except StopIteration:
                expr, messages = None, [('Syntax', 'sntup')]
                break
        print(">>> " + line)
        for message in messages:
            print(message)
        if expr is None:
            continue
        result, messages = evaluate(expr, definitions)
        for message in messages:
            print(message)
        print(result.repr())

def entry_point(argv):
    try:
        filename = argv[1]
    except IndexError:
        print("You must supply a filename")
        return 1
    run(os.open(filename, os.O_RDONLY, 0o777))
    return 0


def target(*args):
    return entry_point, None


if __name__ == "__main__":
    entry_point(sys.argv)
{'fraction_non_alphanumeric': 0.08896551724137931, 'fraction_numerical': 0.008275862068965517, 'mean_word_length': 1.866600790513834, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, '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': '2412430', 'n_tokens_mistral': 819, 'n_tokens_neox': 786, 'n_words': 232}