本文整理匯總了Python中token.DOT屬性的典型用法代碼示例。如果您正苦於以下問題:Python token.DOT屬性的具體用法?Python token.DOT怎麽用?Python token.DOT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類token
的用法示例。
在下文中一共展示了token.DOT屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Annotate
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def Annotate(cls, nodes):
if not nodes:
return None
if nodes[0].type != symbol.atom:
return None
if not nodes[0].children or nodes[0].children[0].type != token.NAME:
return None
for i in xrange(1, len(nodes)):
if not nodes:
break
if nodes[i].type != symbol.trailer:
break
if len(nodes[i].children) != 2:
break
if (nodes[i].children[0].type != token.DOT or
nodes[i].children[1].type != token.NAME):
break
else:
i = len(nodes)
return [cls(nodes[:i])] + nodes[i:]
示例2: value
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def value(self, value):
value_parts = value.split('.')
# If we have too many children, cut the list down to size.
# pylint: disable=attribute-defined-outside-init
self._children = self._children[:len(value_parts)]
# Update child nodes.
for child, value_part in itertools.izip_longest(
self._children, value_parts):
if child:
# Modify existing children. This helps preserve comments and spaces.
child.children[-1].value = value_part
else:
# Add children as needed.
token_snippets = [
snippet.TokenSnippet.Create(token.DOT, '.'),
snippet.TokenSnippet.Create(token.NAME, value_part),
]
self._children.append(snippet.Symbol(symbol.trailer, token_snippets))
示例3: value
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def value(self, value):
value_parts = value.split('.')
for value_part in value_parts:
if keyword.iskeyword(value_part):
raise ValueError('%s is a reserved keyword.' % value_part)
# If we have too many children, cut the list down to size.
# pylint: disable=attribute-defined-outside-init
self._children = self._children[:len(value_parts)*2-1]
# Update child nodes.
for child, value_part in itertools.izip_longest(
self._children[::2], value_parts):
if child:
# Modify existing children. This helps preserve comments and spaces.
child.value = value_part
else:
# Add children as needed.
self._children.append(snippet.TokenSnippet.Create(token.DOT, '.'))
self._children.append(
snippet.TokenSnippet.Create(token.NAME, value_part))
示例4: clean
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def clean(ast_tuple):
"""
reverse ast tuple to a list of tokens
merge sequences (token.NAME, token.DOT, token.NAME)
"""
result = []
last = None
for couple in _clean(ast_tuple):
if couple[0] == token.NAME and last == token.DOT:
result[-1][1] += couple[1]
elif couple[0] == token.DOT and last == token.NAME:
result[-1][1] += couple[1]
else:
result.append(couple)
last = couple[0]
return result
示例5: decorator_name
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def decorator_name(self, nodelist):
listlen = len(nodelist)
assert listlen >= 1 and listlen % 2 == 1
item = self.atom_name(nodelist)
i = 1
while i < listlen:
assert nodelist[i][0] == token.DOT
assert nodelist[i + 1][0] == token.NAME
item = Getattr(item, nodelist[i + 1][1])
i += 2
return item
示例6: com_assign_trailer
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def com_assign_trailer(self, primary, node, assigning):
t = node[1][0]
if t == token.DOT:
return self.com_assign_attr(primary, node[2], assigning)
if t == token.LSQB:
return self.com_subscriptlist(primary, node[2], assigning)
if t == token.LPAR:
raise SyntaxError, "can't assign to function call"
raise SyntaxError, "unknown trailer type: %s" % t
示例7: com_apply_trailer
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def com_apply_trailer(self, primaryNode, nodelist):
t = nodelist[1][0]
if t == token.LPAR:
return self.com_call_function(primaryNode, nodelist[2])
if t == token.DOT:
return self.com_select_member(primaryNode, nodelist[2])
if t == token.LSQB:
return self.com_subscriptlist(primaryNode, nodelist[2], OP_APPLY)
raise SyntaxError, 'unknown node type: %s' % t
示例8: com_subscript
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def com_subscript(self, node):
# slice_item: expression | proper_slice | ellipsis
ch = node[1]
t = ch[0]
if t == token.DOT and node[2][0] == token.DOT:
return Ellipsis()
if t == token.COLON or len(node) > 2:
return self.com_sliceobj(node)
return self.com_node(ch)
示例9: __init__
# 需要導入模塊: import token [as 別名]
# 或者: from token import DOT [as 別名]
def __init__(self, token_type, tokens):
# For operators and delimiters, the TokenSnippet's type may be more specific
# than the type of the constituent token. E.g. the TokenSnippet type is
# token.DOT, but the token type is token.OP. This is because the parser
# has more context than the tokenizer.
self._type = token_type
self._tokens = tokens
self._modified = False