本文整理汇总了Python中magpieparsers.parser_common.Node.add_front方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_front方法的具体用法?Python Node.add_front怎么用?Python Node.add_front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类magpieparsers.parser_common.Node
的用法示例。
在下文中一共展示了Node.add_front方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pop_and_add
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_front [as 别名]
def pop_and_add(scope_ast, oper, operands):
# Pop and create new tree
node = Node(None, 'expression')
node.leaf = OPER_NAMES[oper]
for count in range(get_arity(oper)):
node.add_front(operands.pop())
# Work out the type for the resulting expression.
type_ast = get_expr_type(node.children[0])
for new_type_expr in node.children[1:]:
new_type_ast = get_expr_type(new_type_expr)
if infogripper.can_coerce_expr(new_type_expr, type_ast):
type_ast = new_type_ast
else:
raise error.CannotReconcileTypesError(new_type_ast.leaf, type_ast.leaf, scope_ast)
# Store a value, if we can. This over-rides the above discovered type.
# FIXME: This is a cheesy hack.
if type_ast.has_attribute('smallest') and type_ast.has_attribute('largest'):
# It's a scalar type, we can play with it.
if len(node.children) > 1:
result = oper.join(['(%s)' % (child.attribute('value')) for child in node.children])
else:
# FIXME: Even cheesier
result = "%s%s" % (PYTHON_UNARY[oper] , node.children[0].attribute('value'))
try:
result = eval(result)
node.add_attribute('value', result)
except:
pass
smallest_type_name = smallest_type_hack(result)
if smallest_type_name:
type_ast = infogripper.getNode(smallest_type_name, scope_ast, 'type')
node.add_child(type_ast)
operands.append(node)