aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mako/ast.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-11-18 23:28:34 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-11-18 23:28:34 +0000
commit28ac05dddd2953e83f9702a80b690905f52c4d75 (patch)
treec395a89ef152388120161e47420440c6a93421ec /lib/mako/ast.py
parent8a4da70560a23b80e6dd0e343c8b3edc2659fcd4 (diff)
downloadexternal_python_mako-28ac05dddd2953e83f9702a80b690905f52c4d75.tar.gz
external_python_mako-28ac05dddd2953e83f9702a80b690905f52c4d75.tar.bz2
external_python_mako-28ac05dddd2953e83f9702a80b690905f52c4d75.zip
got something running
Diffstat (limited to 'lib/mako/ast.py')
-rw-r--r--lib/mako/ast.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/mako/ast.py b/lib/mako/ast.py
index c630e21..f8ffc28 100644
--- a/lib/mako/ast.py
+++ b/lib/mako/ast.py
@@ -12,7 +12,15 @@ class PythonCode(object):
self.declared_identifiers = util.Set()
self.undeclared_identifiers = util.Set()
- expr = parse(code, "exec")
+ # note that using AST to parse instead of using code.co_varnames, code.co_names has several advantages:
+ # - we can locate an identifier as "undeclared" even if its declared later in the same block of code
+ # - AST is less likely to break with version changes (for example, the behavior of co_names changed a little bit
+ # in python version 2.5)
+ if isinstance(code, basestring):
+ expr = parse(code, "exec")
+ else:
+ expr = code
+
class FindIdentifiers(object):
def visitAssName(s, node, *args):
if node.name not in self.undeclared_identifiers:
@@ -78,7 +86,6 @@ class FunctionDecl(object):
"""function declaration"""
def __init__(self, code, lineno, pos):
self.code = code
-
expr = parse(code, "exec")
class ParseFunc(object):
def visitFunction(s, node, *args):