<commit_before>from viper.lexer import lex_line

import cmd


class InteractiveLexerException(Exception):
    def __init__(self, output: str):
        self.output = output


class InteractiveLexer(cmd.Cmd):  # pragma: no cover
    prompt = 'viper_lex> '

    def default(self, line):
        lexemes = lex_line(line)
        print(lexemes)

    def do_exit(self, arg):
        """Exit the interactive lexer."""
        raise InteractiveLexerException(output='exit')

    def do_quit(self, arg):
        """Quit the interactive lexer."""
        raise InteractiveLexerException(output='quit')

    def cmdloop(self, intro=None):
        try:
            super().cmdloop(intro=intro)
        except InteractiveLexerException:
            return
        except KeyboardInterrupt:
            print('\b\bexit')
            return<commit_msg>Amend error handling in interactive lexer<commit_after>import viper.lexer as vl

import cmd


class InteractiveLexerException(Exception):
    def __init__(self, output: str):
        self.output = output


class InteractiveLexer(cmd.Cmd):  # pragma: no cover
    prompt = 'viper_lex> '

    def default(self, line):
        lexemes = vl.lex_line(line)
        print(lexemes)

    def do_exit(self, arg):
        """Exit the interactive lexer."""
        raise InteractiveLexerException(output='exit')

    def do_quit(self, arg):
        """Quit the interactive lexer."""
        raise InteractiveLexerException(output='quit')

    def cmdloop(self, intro=None):
        try:
            super().cmdloop(intro=intro)
        except vl.LexerError as e:
            print(e)
            self.cmdloop(intro=intro)
        except InteractiveLexerException:
            return
        except KeyboardInterrupt:
            print('\b\bexit')
            return
{'fraction_non_alphanumeric': 0.09994416527079844, 'fraction_numerical': 0.0, 'mean_word_length': 2.520628683693517, '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': '6689024', 'n_tokens_mistral': 552, 'n_tokens_neox': 504, 'n_words': 124}