diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-02-04 18:47:07 +0100 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:01 +0200 |
commit | 001739a6a93cceeb29f81ea2281ade0bef1a8645 (patch) | |
tree | 814a0890841ab55799329c76452ba25ce693caca /monkey/util.py | |
parent | 6a104bf8e2baea162d7f9f1d439dd8f671ddd413 (diff) |
Move monkey.prolog to root module
Diffstat (limited to 'monkey/util.py')
-rw-r--r-- | monkey/util.py | 27 |
1 files changed, 0 insertions, 27 deletions
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') |