本文整理匯總了Python中tracker.Tracker.next_token方法的典型用法代碼示例。如果您正苦於以下問題:Python Tracker.next_token方法的具體用法?Python Tracker.next_token怎麽用?Python Tracker.next_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tracker.Tracker
的用法示例。
在下文中一共展示了Tracker.next_token方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Tokeniser
# 需要導入模塊: from tracker import Tracker [as 別名]
# 或者: from tracker.Tracker import next_token [as 別名]
class Tokeniser(object):
"""Endpoint for tokenising a file"""
def __init__(self, default_kls='object', with_describe_attrs=True, import_tokens=None):
self.default_kls = default_kls
self.import_tokens = import_tokens
self.with_describe_attrs = with_describe_attrs
########################
### TRANSLATE
########################
def translate(self, readline, result=None, no_imports=None):
# Tracker to keep track of information as the file is processed
self.tokens = Tokens(self.default_kls)
self.tracker = Tracker(result, self.tokens)
# Add import stuff at the top of the file
if self.import_tokens and no_imports is not True:
self.tracker.add_tokens(self.import_tokens)
# Looking at all the tokens
with self.tracker.add_phase() as tracker:
for tokenum, value, (_, scol), _, _ in generate_tokens(readline):
self.tracker.next_token(tokenum, value, scol)
# Add attributes to our Describes so that the plugin can handle some nesting issues
# Where we have tests in upper level describes being run in lower level describes
if self.with_describe_attrs:
self.tracker.add_tokens(self.tracker.make_describe_attrs())
# Add lines to bottom of file to add __testname__ attributes
self.tracker.add_tokens(self.tracker.make_method_names())
# Return translated list of tokens
return self.tracker.result