本文整理汇总了Python中lexer.Lexer.index方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.index方法的具体用法?Python Lexer.index怎么用?Python Lexer.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_func_declarations
# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import index [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
示例2: start
# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import index [as 别名]
def start(name):
print('%s %s' % (name, '-'*(60-(len(name)+1))))
return (name, time.time())
def stop(s):
o = "%sms" % (int((time.time() - s[1]) * 1000))
print('%s: %s %s' % (s[0], o, '-'*(60-(len(o)+len(s[0])+1))))
# start timer
s = start('Indexing')
sources = os.listdir('sources')
for file in sources:
if file.endswith('.txt'):
print("Indexing [%s/%s]" % (sources.index(file)+1, len(sources)+1))
l.index('sources/'+file)
else:
print("Skipped non-source: %s" % (file))
# Stop timer
stop(s)
print("\n")
s = start('Statistics')
print("\tTokens: %s" % (len(l.tokens)))
print("\tDocuments: %s" % (len(l.documents)))
range = (0,5)
print("\n")
print("Finding %s-%s most seen tokens" % (range[0], range[1]))