<commit_before>#!/usr/bin/env python

import re

class ParserError(Exception):
    """Raised when parsing input fails."""

class OpenParenError(ParserError):
    """Raised when there are too few opening parenthesis."""

    def __init__(self):
        ParserError.__init__(self, "too few opening parenthesis")

class CloseParenError(ParserError):
    """Raised when there are too few closing parenthesis."""

    def __init__(self):
        ParserError.__init__(self, "too few closing parenthesis")

class SymbolNotFoundError(Exception):
    """Raised when a symbol could not be found in an environment chain."""

    def __init__(self, symbol):
        Exception.__init__(self, "could not find " + str(symbol))

class IncorrectArgumentCountError(Exception):
    """Raised when a function is called with the wrong number of arguments."""

    def __init__(self, expected, actual):
        Exception.__init__(self, "expected " + str(expected) +
                ", got " + str(actual))

class ApplicationError(Exception):
    """Raised when a function could not be applied correctly."""

class Atom(object):
    """
    Represents anything that's not a list: numbers, strings, symbols, etc.
    """

    def __init__(self, value):
        self.value = value

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return self.__class__.__name__ + "(" + repr(self.value) + ")"

    @staticmethod
    def atomize(token):
        """
        Takes the given string token and returns an Atom representing that
        string in its most natural form (Boolean, String, Integer, etc.).
        """

        # integer
        try:
            return Integer(token)
        except ValueError:
            pass

        # float
        try:
            return Float(token)
        except ValueError:
            pass

        # boolean
        if token.lower() == Boolean.TRUE_TOKEN:
            return BoolTrue()
        elif token.lower() == Boolean.FALSE_TOKEN:
            return BoolFalse()

        # string
        elif token[0] == Tokens.STRING and token[-1] == token[0]:
            return String(token)

        # the base case for all tokens is a symbol
        return Symbol(token)

class List:
    """
    Represents a linear collection of Atom and List elements.
    """

    def __init__(self, *items):
        # save the given items
        self.items = list(items)

    def __str__(self):
        return "(" + " ".join(map(str, self.items)) + ")"

    def __repr__(self):
        return (self.__class__.__name__ +
                "(" + ", ".join(map(repr, self.items)) + ")")

    def __len__(self):
        return len(self.items)

    def __getitem__(self, index):
        return self.items[index]

    def __setitem__(self, index, value):
        self.items[index] = value

    def __getslice__(self, start=0, end=None):
        # set end to our length if not specified
        if end is None:
            end = len(self)

        # returns a List, not a list!
        return List(*self.items[start:end])

    def __iter__(self):
        return self.items.__iter__()

    def __reversed__(self):
        return reversed(self.items)

    def append(self, item):
        self.items.append(item)

    def extend(self, other_items):
        self.items.extend(other_items)

    def pop(self, index=None):
        if index is None:
            index = len(self) - 1

        self.items.pop(index)<commit_msg>made List's __reversed__ method return another List<commit_after>#!/usr/bin/env python

import re

class ParserError(Exception):
    """Raised when parsing input fails."""

class OpenParenError(ParserError):
    """Raised when there are too few opening parenthesis."""

    def __init__(self):
        ParserError.__init__(self, "too few opening parenthesis")

class CloseParenError(ParserError):
    """Raised when there are too few closing parenthesis."""

    def __init__(self):
        ParserError.__init__(self, "too few closing parenthesis")

class SymbolNotFoundError(Exception):
    """Raised when a symbol could not be found in an environment chain."""

    def __init__(self, symbol):
        Exception.__init__(self, "could not find " + str(symbol))

class IncorrectArgumentCountError(Exception):
    """Raised when a function is called with the wrong number of arguments."""

    def __init__(self, expected, actual):
        Exception.__init__(self, "expected " + str(expected) +
                ", got " + str(actual))

class ApplicationError(Exception):
    """Raised when a function could not be applied correctly."""

class Atom(object):
    """
    Represents anything that's not a list: numbers, strings, symbols, etc.
    """

    def __init__(self, value):
        self.value = value

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return self.__class__.__name__ + "(" + repr(self.value) + ")"

    @staticmethod
    def atomize(token):
        """
        Takes the given string token and returns an Atom representing that
        string in its most natural form (Boolean, String, Integer, etc.).
        """

        # integer
        try:
            return Integer(token)
        except ValueError:
            pass

        # float
        try:
            return Float(token)
        except ValueError:
            pass

        # boolean
        if token.lower() == Boolean.TRUE_TOKEN:
            return BoolTrue()
        elif token.lower() == Boolean.FALSE_TOKEN:
            return BoolFalse()

        # string
        elif token[0] == Tokens.STRING and token[-1] == token[0]:
            return String(token)

        # the base case for all tokens is a symbol
        return Symbol(token)

class List:
    """
    Represents a linear collection of Atom and List elements.
    """

    def __init__(self, *items):
        # save the given items
        self.items = list(items)

    def __str__(self):
        return "(" + " ".join(map(str, self.items)) + ")"

    def __repr__(self):
        return (self.__class__.__name__ +
                "(" + ", ".join(map(repr, self.items)) + ")")

    def __len__(self):
        return len(self.items)

    def __getitem__(self, index):
        return self.items[index]

    def __setitem__(self, index, value):
        self.items[index] = value

    def __getslice__(self, start=0, end=None):
        # set end to our length if not specified
        if end is None:
            end = len(self)

        # returns a List, not a list!
        return List(*self.items[start:end])

    def __iter__(self):
        return self.items.__iter__()

    def __reversed__(self):
        return List(*reversed(self.items))

    def append(self, item):
        self.items.append(item)

    def extend(self, other_items):
        self.items.extend(other_items)

    def pop(self, index=None):
        if index is None:
            index = len(self) - 1

        self.items.pop(index)
{'fraction_non_alphanumeric': 0.11026122095540482, 'fraction_numerical': 0.001443209698369173, 'mean_word_length': 2.3624454148471616, 'pattern_counts': {'":': 0, '<': 3, '<?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': '160524', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1900, 'n_words': 595}