You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
DRY fragments.py preorder code
pysource.py: doc typo
This commit is contained in:
@@ -172,35 +172,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
self.last_finish = finish
|
self.last_finish = finish
|
||||||
|
|
||||||
def preorder(self, node=None):
|
def preorder(self, node=None):
|
||||||
|
|
||||||
if node is None:
|
|
||||||
node = self.ast
|
|
||||||
|
|
||||||
start = len(self.f.getvalue())
|
start = len(self.f.getvalue())
|
||||||
|
super(pysource.SourceWalker, self).preorder(node)
|
||||||
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)
|
|
||||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@@ -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
|
creating a method prefaced with "n_" for that nonterminal. For
|
||||||
example, "n_exec_stmt" handles the semantic actions for the
|
example, "n_exec_stmt" handles the semantic actions for the
|
||||||
"exec_smnt" nonterminal symbol. Similarly if a method with the name
|
"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.
|
all of its children are called.
|
||||||
|
|
||||||
Another other way to specify a semantic rule for a nonterminal is via
|
Another other way to specify a semantic rule for a nonterminal is via
|
||||||
|
Reference in New Issue
Block a user