From 001739a6a93cceeb29f81ea2281ade0bef1a8645 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 4 Feb 2015 18:47:07 +0100 Subject: Move monkey.prolog to root module --- monkey/util.py | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'monkey/util.py') diff --git a/monkey/util.py b/monkey/util.py index b8be2bb..6d57d29 100644 --- a/monkey/util.py +++ b/monkey/util.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -from collections import namedtuple from heapq import heappush, heappop import itertools @@ -43,32 +42,6 @@ class PQueue(object): def __len__(self): return self.size -# Stores a token's type and value, and optionally the position of the first -# character in the lexed stream. -class Token(namedtuple('Token', ['type', 'val', 'pos'])): - __slots__ = () - - # Custom constructor to support default parameters. - def __new__(cls, type, val='', pos=None): - return super(Token, cls).__new__(cls, type, val, pos) - - def __str__(self): - return self.val - - # Ignore position when comparing tokens. There is probably a cleaner way of - # doing these. - __eq__ = lambda x, y: x[0] == y[0] and x[1] == y[1] - __ne__ = lambda x, y: x[0] != y[0] or x[1] != y[1] - __lt__ = lambda x, y: tuple.__lt__(x[0:2], y[0:2]) - __le__ = lambda x, y: tuple.__le__(x[0:2], y[0:2]) - __ge__ = lambda x, y: tuple.__ge__(x[0:2], y[0:2]) - __gt__ = lambda x, y: tuple.__gt__(x[0:2], y[0:2]) - - # Only hash token's value (we don't care about position, and types are - # determined by values). - def __hash__(self): - return hash(self[1]) - # Return [n]th line in [text]. def get_line(text, n): lines = text.split('\n') -- cgit v1.2.1