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


Python Lexer.match_paren方法代码示例

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


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

示例1: make_func_bodies

# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import match_paren [as 别名]
	def make_func_bodies(self):
		"""Extracts bodies of lambda functions
		(as opposed to their headers). These bodies
		will then be translated to a series of function
		calls.
		"""
		for name in self.func_dict:
			tok = Lexer(self.func_dict[name]).get_tokens()
			end = tok.match_paren(0)
			header_end = tok.match_paren(2)

			if tok[header_end+2] == '(': #Function returns another function
				start = body.match_paren(header_end+2)+3
			else: #Function returns a concrete type
				start = header_end+3
			
			self.func_bodies[name] = tok[start:end].get_joined()

		self.func_bodies['main'] = self.main
开发者ID:plusgood,项目名称:lithp,代码行数:21,代码来源:converter.py

示例2: make_func_declarations

# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import match_paren [as 别名]
	def make_func_declarations(self):
		"""Creates function declarations with parameter
		types and return types. Higher order functions
		are supported. Function declarations are also
		used as function signatures.

		Precondition: make_func_dict must have been called
		"""

		for name in self.func_dict:
			body = Lexer(self.func_dict[name]).get_tokens()
			i = body.index('\\')  + 1 #Start of parameters
			j = body.match_paren(i)
			param_tokens = body[i + 1: j] #Stuff inside parentheses
			#			print "param list:", param_tokens

			params = self.split_params(param_tokens)
			params = map(lambda n: n.split(':'), params)
			#params is now [[<name>,<type>],...]
			c_types = map(lambda n: self.convert_type(*n), params)
			#			print c_types

			return_type = ''
			#     +2 to skip over ")" and ":"
			if body[j+2] == '(': #Function returns another function
				#                                  +3 for [")","->","<type>"]
				for x in xrange(j+2, body.match_paren(j+2)+3):
					return_type += body[x]
			else: #Function returns a concrete type
				return_type = body[j+2] #+2 to skip over ")" and ":"

			func_type = self.convert_type(name, return_type)
			#			print "params", params
			#			print "c_types", c_types
			#while True:exec raw_input() in globals(), locals()
			self.cpp_declarations[name] = func_type + '(' + ', '.join(c_types) + ')'

		self.cpp_declarations['main'] = 'int main()' #actually this isn't used
开发者ID:plusgood,项目名称:lithp,代码行数:40,代码来源:converter.py


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