summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/pytree.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/pytree.py')
-rw-r--r--Lib/lib2to3/pytree.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py
index 6657144..713e007 100644
--- a/Lib/lib2to3/pytree.py
+++ b/Lib/lib2to3/pytree.py
@@ -14,6 +14,17 @@ __author__ = "Guido van Rossum <guido@python.org>"
HUGE = 0x7FFFFFFF # maximum repeat count, default max
+_type_reprs = {}
+def type_repr(type_num):
+ global _type_reprs
+ if not _type_reprs:
+ from .pygram import python_symbols
+ # printing tokens is possible but not as useful
+ # from .pgen2 import token // token.__dict__.items():
+ for name, val in python_symbols.__dict__.items():
+ if type(val) == int: _type_reprs[val] = name
+ return _type_reprs.setdefault(type_num, type_num)
+
class Base(object):
@@ -195,8 +206,8 @@ class Node(Base):
def __repr__(self):
"""Returns a canonical string representation."""
- return "%s(%r, %r)" % (self.__class__.__name__,
- self.type,
+ return "%s(%s, %r)" % (self.__class__.__name__,
+ type_repr(self.type),
self.children)
def __str__(self):
@@ -372,7 +383,7 @@ class BasePattern(object):
return object.__new__(cls)
def __repr__(self):
- args = [self.type, self.content, self.name]
+ args = [type_repr(self.type), self.content, self.name]
while args and args[-1] is None:
del args[-1]
return "%s(%s)" % (self.__class__.__name__, ", ".join(map(repr, args)))