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


Python Node.leaf方法代码示例

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


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

示例1: component

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [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

示例2: import_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def import_dcl(self, pt):
		ast = Node(None, None, source = pt)
		ast.type = "cimport" #pt.leaf
		"""
		if pt.leaf == 'import':
			#imported_scope
			child = pt.the('imported_scope').children[0]
		elif pt.leaf == 'cimport':
			child = pt.the('anglequoted_scope').children[0]
		"""
		
		child = pt.children[0].children[0]
		assert child is not None
		
			
		
		if child.type == 'string_literal':
			ast.leaf = child.leaf
		elif child.type == 'scoped_name':
			ast.leaf = self.scoped_name(child)
		elif child.type == 'anglequoted_string_literal':
			ast.leaf = child.leaf
		else:
			ast = Node(None, child, source = pt)
			ast.type = 'import'
		return ast
开发者ID:BruceYi,项目名称:okl4,代码行数:28,代码来源:astgen.py

示例3: create_instance_list

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def create_instance_list(self, ast, typeref, declarators):
		instance_list = []
		for child in declarators:
			instance = Node(ast, 'type_instance', None, source = child)
			
			if child.children[0].type == 'simple_declarator':
				instance.leaf = child.children[0].leaf
				instance.add_child(typeref)
			else: #complex_declarator
				newtype = TypeNode(ast, source = pt)
				newtype.add_attribute('meta_type','array')
				
				array_dcl = child.the('complex_declarator').the('array_declarator')
				array_dim = []
				for dimension in array_dcl.children:
					exp_node = dimension.the('positive_int_const').the('const_exp')
					expr = self.getExpression(ast, exp_node)
					array_dim.append(expr.leaf)
					'''
					if res != None:
						array_dcl.append(str(res))
					else:
						array_dcl.append(exp_str)
					'''
				newtype.add_attribute('shape',array_dim)
				newtype.add_child(typeref)
				
				instance.add_child(newtype)
				instance.leaf = array_dcl.leaf
			instance_list.append(instance)
		return instance_list
开发者ID:BruceYi,项目名称:okl4,代码行数:33,代码来源:astgen.py

示例4: value_inheritance_spec

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def value_inheritance_spec(self, ast, pt):
		if pt.children[0].type == 'value_value_inheritance_spec':
			inh_node = Node(ast, 'inheritance', None, source = pt.children[0])
			inh_node.add_attribute('relation', 'value')
			if pt.children[0].the('value_value_inheritance_spec') != None:
				inh_node.add_attribute('modifier', pt.children[0].the('value_value_inheritance_spec').leaf)
			name_list = []
			target_list = []
			for name in pt.the('value_value_inheritance_spec')['value_name']:
				newname = self.scoped_name(name.the('scoped_name'))
				name_list.append(newname)
				target_list.append(getTypenode(newname, ast))
			inh_node.leaf = name_list
			inh_node.add_attribute('target_scope_list',target_list)
			return inh_node
		elif pt.children[0].type == 'value_interface_inheritance_spec':
			inh_node = Node(ast, 'inheritance', None, source = pt.children[0])
			inh_node.add_attribute('relation', 'interface')
			name_list = []
			target_list = []
			for name in pt.the('value_interface_inheritance_spec')['interface_name']:
				newname = self.scoped_name(name.the('scoped_name'))
				name_list.append(newname)
				target_list.append(getTypenode(newname, ast))
			inh_node.add_attribute('target_scope_list',target_list)
			inh_node.leaf = name_list
			return inh_node
		else:
			return UnknownNode(None, pt, source = pt)
开发者ID:BruceYi,项目名称:okl4,代码行数:31,代码来源:astgen.py

示例5: op_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [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

示例6: attr_raises_expr

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def attr_raises_expr(self, pt):
		raisesnode = Node(None, None, source = pt)
		for child in pt.children:
			if child.type == 'get_excep_expr':
				raisesnode.leaf = 'getraises'
				exception_list = self.exception_list(child.the('exception_list'))
				raisesnode.add_attribute('exception_list', exception_list)
			elif child.type == 'set_excep_expr':
				raisesnode.leaf = 'setraises'
				exception_list = self.exception_list(child.the('exception_list'))
				raisesnode.add_attribute('exception_list', exception_list)
			else:
				raisesnode = UnknownNode(None, child, source = pt)
		return raisesnode
开发者ID:BruceYi,项目名称:okl4,代码行数:16,代码来源:astgen.py

示例7: param_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def param_dcl(self, ast, pt):
		"""
		Param decls look like constant declarations: refer to "const_dcl".
		1.	parameter blah  (3)
			+- meta_type = ['param']
		    +- direction = ['in']
			+- indirection = ['*']
			+- target = [<Node object type:unsigned int>]
		"""
		param_ast = Node(ast, 'parameter', None, source = pt)

		# Add direction
		param_ast.add_attribute('direction', pt.leaf)

		for child in pt.children:
			if child.type == 'param_type_spec':
				#param_ast.add_attribute('target',self.param_type_spec(ast, child))
				target_type, is_new_type = self._get_target_type(param_ast, child,
						defining_scope = param_ast)
				param_ast.add_child(target_type)
			elif child.type == 'allow_indirection':
				indirection_list = [child.leaf]
				for indirection in child['allow_indirection']:
					indirection_list.append(indirection.leaf)
				param_ast.add_attribute('indirection', indirection_list)
			elif child.type == 'simple_declarator':
				param_ast.leaf = child.leaf
			else:
				param_ast.add_child(UnkownNode(None, child, source = pt))

		# Check we're not passing raw void parameters.
		if not self.is_valid_parameter_spec(param_ast):
			raise InvalidTypeUsageError(target_type.the('type').leaf, child)
		return param_ast
开发者ID:BruceYi,项目名称:okl4,代码行数:36,代码来源:astgen.py

示例8: type_id_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def type_id_dcl(self, ast, pt, decorators):
		assert not decorators
		type_id = Node(ast, name='typeid', source = pt)
		type_id.leaf = self.scoped_name(ast, pt.the('scoped_name'))
		type_id.add_attribute('value', pt.the('string_literal').leaf)
		ast.add_child(type_id)
		self._dupes_check(type_id)
开发者ID:BruceYi,项目名称:okl4,代码行数:9,代码来源:astgen.py

示例9: except_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [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

示例10: structure

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
 def structure(self):    
     s = None
     
     f = None
     try:      ## for error handling
         pass
         s = Node(None, "structure")
         f = self.LT(1)
         self.match(ATOM)
         s.leaf = f.getText()
         self.match(LBRACKET)
         la1 = self.LA(1)
         if False:
             pass
         elif la1 and la1 in [ATOM,VARIABLE,NUMBER,LCURLY,LSQUARE]:
             pass
             t=self.termlist()
             s.children.extend(t)
         elif la1 and la1 in [RBRACKET]:
             pass
         else:
                 raise antlr.NoViableAltException(self.LT(1), self.getFilename())
             
         self.match(RBRACKET)
     
     except antlr.RecognitionException, ex:
         self.reportError(ex)
         self.consume()
         self.consumeUntil(_tokenSet_3)
开发者ID:BruceYi,项目名称:okl4,代码行数:31,代码来源:PrologParser.py

示例11: create_special_C

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
def create_special_C(arch_info, ast):
	type_list = ast.children
	struct_t = TypeNode(ast, source_file = '<builtin>')
	struct_t.leaf = 'idl4_server_environment'
	struct_t.add_attribute('meta_type','struct')
	members = Node(struct_t, 'members')
	typeinst = Node(struct_t, 'type_instance')
	typeinst.leaf = '_action'
	index = [element.leaf for element in type_list].index('signed int')
	typeinst.add_attribute('target_type',type_list[index] )
	members.add_child(typeinst)
	typeinst = Node(struct_t, 'type_instance')
	typeinst.leaf = '_data'
	index = [element.leaf for element in type_list].index('void')
	typeinst.add_attribute('target_type',type_list[index] )
	members.add_child(typeinst)

	# Create IDL4 scope for giggles.
	idl4 = Node(ast, 'type', leaf = 'idl4', source_file = '<builtin>')
	idl4.add_attribute('meta_type', 'private')
	pagefault = Node(idl4, 'type', leaf = 'pagefault')
	idl4.add_child(pagefault)
	ast.add_child(idl4)
	
	#FIXME: CORBA-C Type-Hack!!!
	aliases = ( ('Object', 'signed int'),
			('any', 'signed int'),
			('ValueBase', 'signed int'),
			('Word', 'signed int')
	)

	# Create aliases to C nodes.
	for alias, name in aliases:
		newType = TypeNode(ast, source_file = '<builtin>')
		newType.leaf = alias
		newType.add_attribute('meta_type', 'alias') 
		type_list = ast.children
		index = [element.leaf for element in type_list].index(name)
		target_node = Node(newType, 'target')
		target_node.add_child(type_list[index])
		newType.add_child(target_node)

		ast.add_child(newType)
	
	# Explicitly add the IDL4 mapitem struct, yuck yuck
	mapitem = _make_struct(ast, 'idl4_mapitem', ('unsigned long int', 'base'), ('unsigned long int', 'fpage'))
	ast.add_child(mapitem)
开发者ID:BruceYi,项目名称:okl4,代码行数:49,代码来源:builtin.py

示例12: finder_dcl

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [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

示例13: component_body

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def component_body(self, ast, pt):
		exp_list = []
		for exp in pt.children:
			exp_node = Node(ast, 'export', source = exp)
			if exp.children[0].type == 'provides_dcl':
				exp_node.add_attribute('type', 'provides')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				if exp.children[0].the('interface_type').the('scoped_name') != None:
					scopedname = self.scoped_name(exp.children[0].the('interface_type').the('scoped_name'))
					exp_node.add_attribute('name', scopedname)
				else:
					exp_node.add_attribute('name', 'Object')
			elif exp.children[0].type == 'uses_dcl':
				typestr = ''
				for child in exp.children[0]['uses_dcl']:
					typestr += child.leaf
				exp_node.add_attribute('type', typestr)
				exp_node.leaf = exp.children[0].the('identifier').leaf
				if exp.children[0].the('interface_type').the('scoped_name') != None:
					scopedname = self.scoped_name(exp.children[0].the('interface_type').the('scoped_name'))
					exp_node.add_attribute('name', scopedname)
				else:
					exp_node.add_attribute('name', 'Object')
			elif exp.children[0].type == 'emits_dcl':
				exp_node.add_attribute('type', 'emits')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'publishes_dcl':
				exp_node.add_attribute('type', 'publishes')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'consumes_dcl':
				exp_node.add_attribute('type', 'consumes')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'attr_dcl':
				# FIXME: Not used?
				self.attr_dcl(exp_node, exp.children[0])
			else:
				exp_list.append(UnknownChild(None, exp))
			exp_list.append(exp_node)
		return exp_list
开发者ID:BruceYi,项目名称:okl4,代码行数:47,代码来源:astgen.py

示例14: decorator_element

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [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

示例15: attr_declarator

# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import leaf [as 别名]
	def attr_declarator(self, ast, pt):
		decl = Node(ast, 'declarator', None, source = pt)
		decl.leaf = []
		for child in pt.children:
			if child.type == 'simple_declarator':
				decl.leaf.append(child.leaf)
			elif child.type == 'attr_raises_expr':
				decl.add_child(self.attr_raises_expr(decl, child))
			else:
				decl.add_child(UnkownNode(None, child, source = pt))
		return decl
开发者ID:BruceYi,项目名称:okl4,代码行数:13,代码来源:astgen.py


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