[pypy-svn] r12111 - pypy/dist/pypy/module/recparser
ludal at codespeak.net
ludal at codespeak.net
Mon May 9 16:20:42 CEST 2005
Author: ludal
Date: Mon May 9 16:20:42 2005
New Revision: 12111
Modified:
pypy/dist/pypy/module/recparser/pyparser.py
pypy/dist/pypy/module/recparser/syntaxtree.py
Log:
* generates line numbers in totuple
Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py (original)
+++ pypy/dist/pypy/module/recparser/pyparser.py Mon May 9 16:20:42 2005
@@ -24,23 +24,23 @@
self.space = space
self.node = syntaxnode
- def totuple (self, line_info = 0):
+ def totuple (self, line_info = False ):
"""STType.totuple()
Convert the ST object into a tuple representation.
"""
# lineinfo is ignored for now
- return self.node.totuple()
+ return self.node.totuple( line_info )
- def descr_totuple(self, line_info = 0):
+ def descr_totuple(self, line_info = False):
return self.space.wrap(self.totuple(line_info))
descr_totuple.unwrap_spec=['self', int]
- def tolist (self, line_info = 0):
+ def tolist (self, line_info = False):
"""STType.tolist()
Convert the ST object into a list representation.
"""
- return self.node.tolist()
+ return self.node.tolist( line_info )
def isexpr (self):
"""STType.isexpr()
Modified: pypy/dist/pypy/module/recparser/syntaxtree.py
==============================================================================
--- pypy/dist/pypy/module/recparser/syntaxtree.py (original)
+++ pypy/dist/pypy/module/recparser/syntaxtree.py Mon May 9 16:20:42 2005
@@ -61,7 +61,12 @@
"|=" : token.VBAREQUAL,
}
-
+SYMBOLS = {}
+# copies the numerical mapping between symbol name and symbol value
+# into SYMBOLS
+for k,v in symbol.__dict__.items():
+ if type(v)==int:
+ SYMBOLS[k] = v
class SyntaxNode(object):
@@ -108,8 +113,9 @@
def expand(self):
return [ self ]
- def totuple(self):
- l = [getattr(symbol, self.name, (0,self.name) )]
+ def totuple(self, lineno=False ):
+ symvalue = SYMBOLS.get( self.name, (0,self.name) )
+ l = [ symvalue ]
l += [node.totuple() for node in self.nodes]
return tuple(l)
@@ -137,7 +143,7 @@
else:
return "<%s!>" % (self.name,)
- def totuple(self):
+ def totuple(self, lineno=False):
num = TOKEN_MAP.get(self.name, -1)
if num == -1:
print "Unknown", self.name, self.value
@@ -148,4 +154,7 @@
val = self.name
else:
val = self.value or ''
- return (num, val)
+ if lineno:
+ return (num, val, self.lineno)
+ else:
+ return (num, val)
More information about the Pypy-commit
mailing list