<commit_before>#!/usr/bin/python
import sys
import rollparse
import os
if 'posix' == os.name:
    import readline

def main():
    if 'posix' == os.name:
        readline.parse_and_bind('set editing-mode vi')
    while True:
        try:
            eqn_str = raw_input("Roll it! ('q' to quit): ")
        except EOFError:
            break
        
        if '' == eqn_str:
            continue

        if 'q' == eqn_str[0]:
            break

        try:
            const_strings = []
            ans_str = []
            answers = None
            is_separated, const_strings, (ans_str, answers) = rollparse.solve_roll(eqn_str)
        except Exception as e:
            print e
            print sys.exc_traceback.tb_lineno
            continue

        if 0 < len(const_strings) and not is_separated:
            print "Calculated constants:"
            i = 1
            for c in const_strings:
                print "  {0}: {1}".format(i, c)
                i += 1

        if is_separated:
            print "Rolls:"
            for i in range(0,len(ans_str)):
                const_counter = 1
                for const_str in const_strings[i]:
                    print "    [{0}: {1}]".format(const_counter, const_str)
                    const_counter += 1
                print "  {0}: {1} = {2}".format(i+1, ans_str[i], answers[i])
        else:
            print "{0} = {1}".format(ans_str, answers)

    return 0

if __name__ == "__main__":
    sys.exit(main())
<commit_msg>Small patch to make exception handling more explicit and easier to read.<commit_after>#!/usr/bin/python
import traceback
import sys
import rollparse
import os
if 'posix' == os.name:
    import readline

def main():
    if 'posix' == os.name:
        readline.parse_and_bind('set editing-mode vi')
    while True:
        try:
            eqn_str = raw_input("Roll it! ('q' to quit): ")
        except EOFError:
            break
        
        if '' == eqn_str:
            continue

        if 'q' == eqn_str[0]:
            break

        try:
            const_strings = []
            ans_str = []
            answers = None
            is_separated, const_strings, (ans_str, answers) = rollparse.solve_roll(eqn_str)
        except Exception as e:
            print e
            #print sys.exc_traceback.tb_lineno
            for frame in traceback.extract_tb(sys.exc_info()[2]):
                fname,lineno,fn,text = frame
                print "Error in %s on line %d" % (fname, lineno)
            continue

        if 0 < len(const_strings) and not is_separated:
            print "Calculated constants:"
            i = 1
            for c in const_strings:
                print "  {0}: {1}".format(i, c)
                i += 1

        if is_separated:
            print "Rolls:"
            for i in range(0,len(ans_str)):
                const_counter = 1
                for const_str in const_strings[i]:
                    print "    [{0}: {1}]".format(const_counter, const_str)
                    const_counter += 1
                print "  {0}: {1} = {2}".format(i+1, ans_str[i], answers[i])
        else:
            print "{0} = {1}".format(ans_str, answers)

    return 0

if __name__ == "__main__":
    sys.exit(main())

{'fraction_non_alphanumeric': 0.110699969164354, 'fraction_numerical': 0.011409189022510022, 'mean_word_length': 1.538341158059468, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '2792930', 'n_tokens_mistral': 1015, 'n_tokens_neox': 966, 'n_words': 260}