当前位置: 首页>>代码示例>>Python>>正文


Python Node.add_children方法代码示例

本文整理汇总了Python中magpieparsers.parser_common.Node.add_children方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_children方法的具体用法?Python Node.add_children怎么用?Python Node.add_children使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在magpieparsers.parser_common.Node的用法示例。


在下文中一共展示了Node.add_children方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: except_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def except_dcl(self, ast, pt, decorators):
		excep_node = Node(ast, 'exception', None, source = pt)
		excep_node.leaf = pt.the('identifier').leaf
		if pt.the('opt_member_list') != None:
			excep_node.add_children(self.member_list(ast, pt.the('opt_member_list')))
		ast.add(excep_node)
		self._dupes_check(excep_node)
开发者ID:BruceYi,项目名称:okl4,代码行数:9,代码来源:astgen.py

示例2: component

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def component(self,ast, pt, decorators):
		assert not decorators
		component = Node(ast, 'component', None, source = pt)
		component.leaf = pt.the('identifier').leaf
		dcl = pt.the('component_dcl')
		if  dcl != None:
			inh = dcl.the('component_inheritance_spec')
			if inh != None:
				inher_node = Node(component, 'inherits', leaf = self.scoped_name(interface, scope_name), source = dcl)
				component.add_child(inher_ndoe)
				inher_node.add_child(infogripper.find_scope(interface, inher))
			
			sup = dcl.the('supported_interface_spec')
			if sup != None:
				supnode = Node(component, 'support', source = sup)
				name_list = []
				for name in sup['scoped_name']:
					newname = self.scoped_name(name)
					name_list.append(newname)
					target_list.append(getTypenode(newname, component))
				supnode.leaf = name_list
				supnode.add_attribute('target_scope_list', target_list)
				component.add_child(supnode)
			
			bod = dcl.the('component_body')
			if bod != None:
				exp_list = self.component_body(component, bod)
				if exp_list != []:
					component.add_children(exp_list)

		ast.add_child(component)
开发者ID:BruceYi,项目名称:okl4,代码行数:33,代码来源:astgen.py

示例3: case_stmt_list

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def case_stmt_list(self, ast, pt):
		"""
		switch
		 case
		  expression
		  [expression...]
		  declarator
		 [case...]
		"""
		# Find the appropriate scope for resolving scoped names, if any are present in
		# the case statement list. Switches on enums are constrained to the scope of
		# the enum (I think).
		
		switch_ast = Node(ast, 'switch', source = pt)
		for case_pt in pt.children:
			case_ast = Node(switch_ast, 'case', source = case_pt)
			switch_ast.add_child(case_ast)

			for choice_pt in case_pt['const_exp']:
				expr_ast = self.getExpression(case_ast, choice_pt)
				case_ast.add_child(expr_ast)

			typeref, new_type = self.type_spec(case_ast, case_pt.the('element_spec').the('type_spec'))
			if new_type:
				case_ast.add_child(typeref)
			
			decl = case_pt.the('element_spec').the('declarator')

			inst_list = self.create_instance_list(case_ast, typeref, [decl])
			case_ast.add_children(inst_list)

		return switch_ast
开发者ID:BruceYi,项目名称:okl4,代码行数:34,代码来源:astgen.py

示例4: op_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def op_dcl(self,ast, pt):
		fcn = Node(ast, 'function', None, source = pt)
		ast.add_child(fcn)
		for child in pt.children:
			if child.type == 'decorator':
				#print child
				dec_children = self.decorator_elements(fcn, child)
				dec_node = Node(fcn, 'decorator', dec_children, source = child)
				fcn.add_child(dec_node)
			elif child.type == 'op_attribute':
				fcn.add_attribute('attribute', child.leaf)
			elif child.type == 'op_type_spec':
				#if child.leaf == 'void':
				#	target = getTypenode('void', fcn)
				#print 'trying to get typenode for: %s' %(child.the('param_type_spec'))
				#else:
				typenode = TypeNode(fcn, source = pt)
				typenode.name = 'return_type'
				fcn.add_child(typenode)
				target, new_type = self._get_target_type(typenode, child.the('param_type_spec'),
						defining_scope = typenode)
				# Add the target explicitly.
				typenode.add_child(target)
				if child.the('allow_indirection'):
					typenode.add_attribute('indirection', child.the('allow_indirection').leaf)
				elif child.the('ref_indirection'):
					typenode.add_attribute('indirection', ['*'])
			elif child.type == 'op_dcl':
				fcn.leaf = child.leaf
			elif child.type == 'parameter_dcls':
				fcn.add_children(self.parameter_dcls(fcn, child))
			elif child.type == 'raises_expr':
				raises = Node(fcn, name='raises', source = child)
				leaflist = []
				target_list = []
				for node in child.the('scoped_name_list').children:
					if node.type == 'scoped_name':
						newname = self.scoped_name(node)
						leaflist.append(newname)
						target_list.append(getTypenode(newname, fcn))
				raises.leaf = leaflist
				raises.add_attribute('target_scope_list', target_list)
				fcn.add_child(raises)
			elif child.type == 'context_expr':
				context = Node(fcn, name='context', source = child)
				leaflist = []
				for node in child.the('string_literal_list').children:
					if node.type == 'string_literal':
						leaflist.append(node.leaf)
				context.leaf = leaflist
				fcn.add_child(context)
			else:
				fcn = UnknownNode(None, child, source = child)

		# Add it and include its symbol.
		self._dupes_check(fcn)
开发者ID:BruceYi,项目名称:okl4,代码行数:58,代码来源:astgen.py

示例5: decorator_element

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def decorator_element(self, ast, pt):
		dec_node = Node(None, 'annotation', source = pt)
		for child in pt.children:
			if child.type == 'identifier':
				dec_node.leaf = child.leaf
			elif child.type == 'expr_list':
				dec_node.add_children(self.expr_list(ast, child, True))
			else:
				dec_node.add_child(UnknownNode(child, source = pt))
		return dec_node
开发者ID:BruceYi,项目名称:okl4,代码行数:12,代码来源:astgen.py

示例6: interf

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def interf(self,ast,  pt, decorators):
		# ... create the type
		interface = Node(ast, 'type', source = pt)
		interface.add_attribute('meta_type', 'interface')
		# ... add modifiers
		if pt.leaf == 'abstract' or pt.leaf == 'local':
			interface.add_attribute('modifier', pt.leaf)
		# ... set interface name
		interface.leaf = pt.the('identifier').leaf

		# If the interface already exists in incomplete form, use that instead.
		old_interfaces = infogripper.getAllNodes(interface.leaf, ast, 'type')
		if old_interfaces:
			# Found a previous declaration; use that.
			assert len(old_interfaces) == 1
			interface = old_interfaces[0]
		else:
			# Okay, it doesn't exist already: add it.
			ast.add_child(interface)

		# While we're building it, add the "incomplete" attribute.
		interface.add_attribute('incomplete', True)
		is_incomplete = True
		for child in pt.children:
			if child.type == 'interface_dcl':
				is_incomplete = False
				#print child
				if child.the('interface_header') != None:
					scope_list = child.the('interface_header').the('interface_inheritance_spec').the('scoped_name_list')
					for scope_name in scope_list['scoped_name']:
						inher_node = Node(interface, 'inherits', leaf = self.scoped_name(scope_name), source = child)
						inher_node.add_child(infogripper.find_scope(interface, inher_node.leaf))

						# Ensure we're not inheriting from the same class twice.
						self.check_not_inherited(interface, inher_node.children[0], error_infonode = scope_name)
						interface.add_child(inher_node)
						
						
				if child.the('interface_body') != None:
					for export_child in child.the('interface_body').children:
						self.export(interface, export_child)

		# Remove "incomplete" if the interface was fully-defined above.
		if not is_incomplete:
			interface.del_attributes('incomplete')

		interface.add_children(decorators)

		self._dupes_check(interface)
开发者ID:BruceYi,项目名称:okl4,代码行数:51,代码来源:astgen.py

示例7: member_list

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def member_list(self, ast, pt):
		members = Node(ast, None, source = pt)
		members.type = 'members'
		for child in pt.children:
			if child.type == 'member':
				typeref, new_type = self.type_spec(members, child.the('type_spec'))
				if new_type:
					if isinstance(typeref, str):
						pass
					else:
						members.add_child(typeref)
				members.add_children(self.create_instance_list(members, typeref, child.the('declarators').children))
			else:
				print 'memberlist_unknown' + child.type
		return [members]
开发者ID:BruceYi,项目名称:okl4,代码行数:17,代码来源:astgen.py

示例8: get_cast

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
def get_cast(scope_ast, pt, ast_gen):
    """
	Casts
	"""
    node = Node(scope_ast, "expression", leaf="cast", source=pt)

    type_ast = ast_gen.get_type(scope_ast, pt)
    assert type_ast is not None
    # Indirection stays the same
    indirection_ast = Node(scope_ast, "indirection", leaf=pt.leaf)
    # Expression is converted.
    expr_ast = get_expression(node, pt.get_child("expression"), ast_gen)

    # And we're done
    node.add_children([type_ast, indirection_ast, expr_ast])
    return node
开发者ID:berkus,项目名称:okl4,代码行数:18,代码来源:astexpr.py

示例9: finder_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_children [as 别名]
	def finder_dcl(self, ast, pt):
		fac_node = Node(ast, None, name = 'finder', source = pt)
		fac_node.leaf = pt.the('identifier').leaf
		fac_node.add_children(self.init_param_decls(fac_node, pt.the('init_param_decls')))
		if pt.the('raises_expr') != None:
			raises = Node(fac_node, name='raises', source = pt)
			leaflist = []
			target_list = []
			for node in child.the('scoped_name_list').children:
				if node.type == 'scoped_name':
					newname = self.scoped_name(node)
					target_list = getTypenode(newname, ast)
					leaflist.append(newname)
			raises.leaf = leaflist
			raises.add_attribute('target_scope_list', target_list)
			fac_node.add_child(raises)
		return fac_node
开发者ID:BruceYi,项目名称:okl4,代码行数:19,代码来源:astgen.py


注:本文中的magpieparsers.parser_common.Node.add_children方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。