<commit_before># -*- coding: utf-8 -*-

import os
from abc import ABCMeta, abstractmethod

import ply.lex as lex
import ply.yacc as yacc

"""
Base classes for parsers.

It contains some interfaces, along a base parser for the parsing library being
used.
"""

__author__ = '<NAME>'
__license__ = 'MIT'


class Parser(object, metaclass=ABCMeta):
    """
    Interface for implementing parsers.

    It just contains a single method, 'parse', which will receive a value
    and take care of parsing it into another.
    """

    def __init__(self):
        pass

    @abstractmethod
    def parse(self, value):
        raise NotImplementedError('The parse method must be implemented')


class PlyParser(Parser):
    """
    Base class for a lexer/parser that has the rules defined as methods.

    It makes use of Ply for the parsing.
    """

    tokens = ()
    precedence = ()

    def __init__(self, **kw):
        super(PlyParser, self).__init__()
        self.debug = kw.get('debug', 0)
        self.names = {}
        try:
            modname = os.path.split(os.path.splitext(__file__)[0])[
                          1] + "_" + self.__class__.__name__
        except:
            modname = "parser" + "_" + self.__class__.__name__<commit_msg>Defined exception being caught<commit_after># -*- coding: utf-8 -*-

import os
from abc import ABCMeta, abstractmethod

import ply.lex as lex
import ply.yacc as yacc

"""
Base classes for parsers.

It contains some interfaces, along a base parser for the parsing library being
used.
"""

__author__ = '<NAME>'
__license__ = 'MIT'


class Parser(object, metaclass=ABCMeta):
    """
    Interface for implementing parsers.

    It just contains a single method, 'parse', which will receive a value
    and take care of parsing it into another.
    """

    def __init__(self):
        pass

    @abstractmethod
    def parse(self, value):
        raise NotImplementedError('The parse method must be implemented')


class PlyParser(Parser):
    """
    Base class for a lexer/parser that has the rules defined as methods.

    It makes use of Ply for the parsing.
    """

    tokens = ()
    precedence = ()

    def __init__(self, **kw):
        super(PlyParser, self).__init__()
        self.debug = kw.get('debug', 0)
        self.names = {}
        try:
            modname = os.path.split(os.path.splitext(__file__)[0])[
                          1] + "_" + self.__class__.__name__
        except Exception:
            modname = "parser" + "_" + self.__class__.__name__
{'fraction_non_alphanumeric': 0.1055974593092497, 'fraction_numerical': 0.0031758634378721714, 'mean_word_length': 2.5343618513323984, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5083900', 'n_tokens_mistral': 770, 'n_tokens_neox': 727, 'n_words': 249}