<commit_before>import cmd
import sys
from parser import parse_calc_string, parse_mod_string, reduce_tree
import pyparsing
from calculator import do_calc


class CalcCmd(cmd.Cmd):
    calculations = []
    state = ""

    @staticmethod
    def _quit():
        sys.exit(0)

    def _add_calc_tree(self, ln):
        tree = parse_calc_string(ln)
        self.calculations.append(tree)

    def eval_calc(self, index=-1):
        print reduce_tree(self.calculations[index], do_calc, self.calculations)

    def print_calc(self, index=-1):
        if index > -1:
            print index, self.calculations[index][0]
        else:
            print self.calculations[index][0]

    def default(self, ln):
        try:
            self._add_calc_tree(ln)
        except pyparsing.ParseException:
            print "Don't understand that."
            return
        self.print_calc()
        self.eval_calc()

    def do_list(self, command):
        for idx, calc in enumerate(self.calculations):
            self.print_calc(idx)

    def do_set(self, command):
        print command

    def do_q(self, command):
        print command
        self._quit()

    def do_quit(self, command):
        print command
        self._quit()<commit_msg>Help text<commit_after>import cmd
import sys
from parser import parse_calc_string, parse_mod_string, reduce_tree
import pyparsing
from calculator import do_calc


class CalcCmd(cmd.Cmd):
    calculations = []
    state = ""

    @staticmethod
    def _quit():
        sys.exit(0)

    def _add_calc_tree(self, ln):
        tree = parse_calc_string(ln)
        self.calculations.append(tree)

    def eval_calc(self, index=-1):
        print reduce_tree(self.calculations[index], do_calc, self.calculations)

    def print_calc(self, index=-1):
        if index > -1:
            print index, self.calculations[index][0]
        else:
            print self.calculations[index][0]

    def default(self, ln):
        try:
            self._add_calc_tree(ln)
        except pyparsing.ParseException:
            print "Don't understand that."
            return
        self.print_calc()
        self.eval_calc()

    def do_list(self, command):
        """Lists all the calculations in the buffer"""
        for idx, calc in enumerate(self.calculations):
            self.print_calc(idx)

    def do_rep(self, command):
        """Replaces a value in a previous calculation with the new one"""
        print command

    def do_quit(self, command):
        """Quits so you can do something much more interesting"""
        print command
        self._quit()
{'fraction_non_alphanumeric': 0.09521973785659213, 'fraction_numerical': 0.004626060138781804, 'mean_word_length': 2.3657587548638133, 'pattern_counts': {'":': 0, '<': 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': '5035917', 'n_tokens_mistral': 802, 'n_tokens_neox': 767, 'n_words': 199}