本文整理汇总了Python中ast.Node.addkid方法的典型用法代码示例。如果您正苦于以下问题:Python Node.addkid方法的具体用法?Python Node.addkid怎么用?Python Node.addkid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ast.Node
的用法示例。
在下文中一共展示了Node.addkid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Start
# 需要导入模块: from ast import Node [as 别名]
# 或者: from ast.Node import addkid [as 别名]
def Start(self, nt, *kids):
'''
The production action for all productions in the grammar. The AST
which is built is actually the same as the Parse Tree. Therefore,
it is easy to have a generic action for all of the grammar rules.
'''
n = Node(nt.sym)
for kid in kids:
if isinstance(kid, Node): n.addkid(kid)
elif kid is None: continue
else: n.addkid(Node(kid.type).addkid(Node(kid.value)))
return n
示例2: __create
# 需要导入模块: from ast import Node [as 别名]
# 或者: from ast.Node import addkid [as 别名]
def __create(self, t):
#print type(t), help(t)
doc = self.__getattribute__(traceback.extract_stack()[-2][2]).__doc__
name = doc.split(':', 1)[0].strip()
node = Node(name)
for i, x in enumerate(t[1:]):
if isinstance(x, Node):
node.addkid(x)
else:
node.addkid(t.get(i+1).type)
return node