| 1 |
""" |
| 2 |
A CPython inspired RPython parser. |
| 3 |
""" |
| 4 |
|
| 5 |
class TokenASTBase(object): |
| 6 |
_attrs_ = [] |
| 7 |
|
| 8 |
class Token(TokenASTBase): |
| 9 |
def __init__(self, token_type, value, lineno, column, line, end_lineno=-1, end_column=-1, level=0): |
| 10 |
self.token_type = token_type |
| 11 |
self.value = value |
| 12 |
self.lineno = lineno |
| 13 |
|
| 14 |
self.column = column |
| 15 |
self.line = line |
| 16 |
self.end_lineno = end_lineno |
| 17 |
self.end_column = end_column |
| 18 |
self.level = level |
| 19 |
|
| 20 |
def __repr__(self): |
| 21 |
from pypy.interpreter.pyparser.pytoken import token_names |
| 22 |
return "Token(%s, %s)" % (token_names.get(self.token_type, self.token_type), self.value) |
| 23 |
|
| 24 |
def __eq__(self, other): |
| 25 |
|
| 26 |
return ( |
| 27 |
self.token_type == other.token_type and |
| 28 |
self.value == other.value and |
| 29 |
self.lineno == other.lineno and |
| 30 |
self.column == other.column and |
| 31 |
self.line == other.line and |
| 32 |
self.end_lineno == other.end_lineno and |
| 33 |
self.end_column == other.end_column |
| 34 |
) |
| 35 |
|
| 36 |
def __ne__(self, other): |
| 37 |
return not self == other |