DRY fragments.py preorder code

pysource.py: doc typo
This commit is contained in:
rocky
2016-10-11 22:23:15 -04:00
parent 9ef670c872
commit fe072d8b57
2 changed files with 2 additions and 29 deletions

View File

@@ -172,35 +172,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.last_finish = finish
def preorder(self, node=None):
if node is None:
node = self.ast
start = len(self.f.getvalue())
try:
name = 'n_' + self.typestring(node)
if hasattr(self, name):
func = getattr(self, name)
func(node)
else:
self.default(node)
except GenericASTTraversalPruningException:
# All leaf nodes, those with the offset method among others
# seems to fit under this exception. If this is not true
# we would need to dupllicate the below code before the
# return outside of this block
self.set_pos_info(node, start, len(self.f.getvalue()))
# print self.f.getvalue()[start:]
return
for kid in node:
self.preorder(kid)
name = name + '_exit'
if hasattr(self, name):
func = getattr(self, name)
func(node)
super(pysource.SourceWalker, self).preorder(node)
self.set_pos_info(node, start, len(self.f.getvalue()))
return

View File

@@ -16,7 +16,7 @@ Semantic action rules for nonterminal symbols can be specified here by
creating a method prefaced with "n_" for that nonterminal. For
example, "n_exec_stmt" handles the semantic actions for the
"exec_smnt" nonterminal symbol. Similarly if a method with the name
of the nontermail is suffixed with "_exit" it will be called after
of the nonterminal is suffixed with "_exit" it will be called after
all of its children are called.
Another other way to specify a semantic rule for a nonterminal is via