<commit_before>"""
# ----------------------------------------------------------------------
# ast.py
#
# AST constructors for the Llama language
# http://courses.softlab.ntua.gr/compilers/2012a/llama2012.pdf
#
# Authors: <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#
# ----------------------------------------------------------------------
"""

# == INTERFACES OF AST NODES ==


class Node:
    lineno = None
    lexpos = None

    def __init__(self):
        raise NotImplementedError

    def __eq__(self, other):
        """
        Two nodes are equal if they are of the same type
        and have all attributes equal. Override as needed.
        """
        return type(self) == type(other) and all(
            getattr(self, attr) == getattr(other, attr)
            for attr in self.__dict__.keys()
            if attr not in ('lineno', 'lexpos')
        )

    def copy_pos(self, node):
        """Copy line info from another AST node."""
        self.lineno = node.lineno
        self.lexpos = node.lexpos

    def __repr__(self):
        attrs = [attr for attr in dir(self) if attr[0] != '_']
        values = [getattr(self, attr) for attr in attrs]
        safe_values = []
        for value in values:
            displayable_types = (int, float, bool, str, list, Type)
            if isinstance(value, displayable_types) or value is None:
                safe_values.append(str(value).replace("\n", "\n\t"))
            else:
                safe_values.append(
                    '(non-scalar of type %s)' % value.__class__.__name__
                )
        pairs = (
            "%s = '%s'" % (attr, value)
            for (attr, value) in zip(attrs, safe_values)
        )
        return "ASTNode:%s with attributes:\n\t* %s" \<commit_msg>AST: Add sub-Expression nodes to __repr__ for debuggability<commit_after>"""
# ----------------------------------------------------------------------
# ast.py
#
# AST constructors for the Llama language
# http://courses.softlab.ntua.gr/compilers/2012a/llama2012.pdf
#
# Authors: <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#
# ----------------------------------------------------------------------
"""

# == INTERFACES OF AST NODES ==


class Node:
    lineno = None
    lexpos = None

    def __init__(self):
        raise NotImplementedError

    def __eq__(self, other):
        """
        Two nodes are equal if they are of the same type
        and have all attributes equal. Override as needed.
        """
        return type(self) == type(other) and all(
            getattr(self, attr) == getattr(other, attr)
            for attr in self.__dict__.keys()
            if attr not in ('lineno', 'lexpos')
        )

    def copy_pos(self, node):
        """Copy line info from another AST node."""
        self.lineno = node.lineno
        self.lexpos = node.lexpos

    def __repr__(self):
        attrs = [attr for attr in dir(self) if attr[0] != '_']
        values = [getattr(self, attr) for attr in attrs]
        safe_values = []
        for value in values:
            displayable_types = (int, float, bool, str, list, Type, Expression)
            if isinstance(value, displayable_types) or value is None:
                safe_values.append(str(value).replace("\n", "\n\t"))
            else:
                safe_values.append(
                    '(non-scalar of type %s)' % value.__class__.__name__
                )
        pairs = (
            "%s = '%s'" % (attr, value)
            for (attr, value) in zip(attrs, safe_values)
        )
        return "ASTNode:%s with attributes:\n\t* %s" \
{'fraction_non_alphanumeric': 0.19379194630872484, 'fraction_numerical': 0.0050335570469798654, 'mean_word_length': 1.5586552217453504, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2432843', 'n_tokens_mistral': 1040, 'n_tokens_neox': 996, 'n_words': 296}