本文整理汇总了Python中token.RSQB属性的典型用法代码示例。如果您正苦于以下问题:Python token.RSQB属性的具体用法?Python token.RSQB怎么用?Python token.RSQB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类token
的用法示例。
在下文中一共展示了token.RSQB属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: atom_lsqb
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def atom_lsqb(self, nodelist):
if nodelist[1][0] == token.RSQB:
return List((), lineno=nodelist[0][2])
return self.com_list_constructor(nodelist[1])
示例2: com_assign
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def com_assign(self, node, assigning):
# return a node suitable for use as an "lvalue"
# loop to avoid trivial recursion
while 1:
t = node[0]
if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_comp):
if len(node) > 2:
return self.com_assign_tuple(node, assigning)
node = node[1]
elif t in _assign_types:
if len(node) > 2:
raise SyntaxError, "can't assign to operator"
node = node[1]
elif t == symbol.power:
if node[1][0] != symbol.atom:
raise SyntaxError, "can't assign to operator"
if len(node) > 2:
primary = self.com_node(node[1])
for i in range(2, len(node)-1):
ch = node[i]
if ch[0] == token.DOUBLESTAR:
raise SyntaxError, "can't assign to operator"
primary = self.com_apply_trailer(primary, ch)
return self.com_assign_trailer(primary, node[-1],
assigning)
node = node[1]
elif t == symbol.atom:
t = node[1][0]
if t == token.LPAR:
node = node[2]
if node[0] == token.RPAR:
raise SyntaxError, "can't assign to ()"
elif t == token.LSQB:
node = node[2]
if node[0] == token.RSQB:
raise SyntaxError, "can't assign to []"
return self.com_assign_list(node, assigning)
elif t == token.NAME:
return self.com_assign_name(node[1], assigning)
else:
raise SyntaxError, "can't assign to literal"
else:
raise SyntaxError, "bad assignment (%s)" % t
示例3: test_exact_type
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def test_exact_type(self):
self.assertExactTypeEqual('()', token.LPAR, token.RPAR)
self.assertExactTypeEqual('[]', token.LSQB, token.RSQB)
self.assertExactTypeEqual(':', token.COLON)
self.assertExactTypeEqual(',', token.COMMA)
self.assertExactTypeEqual(';', token.SEMI)
self.assertExactTypeEqual('+', token.PLUS)
self.assertExactTypeEqual('-', token.MINUS)
self.assertExactTypeEqual('*', token.STAR)
self.assertExactTypeEqual('/', token.SLASH)
self.assertExactTypeEqual('|', token.VBAR)
self.assertExactTypeEqual('&', token.AMPER)
self.assertExactTypeEqual('<', token.LESS)
self.assertExactTypeEqual('>', token.GREATER)
self.assertExactTypeEqual('=', token.EQUAL)
self.assertExactTypeEqual('.', token.DOT)
self.assertExactTypeEqual('%', token.PERCENT)
self.assertExactTypeEqual('{}', token.LBRACE, token.RBRACE)
self.assertExactTypeEqual('==', token.EQEQUAL)
self.assertExactTypeEqual('!=', token.NOTEQUAL)
self.assertExactTypeEqual('<=', token.LESSEQUAL)
self.assertExactTypeEqual('>=', token.GREATEREQUAL)
self.assertExactTypeEqual('~', token.TILDE)
self.assertExactTypeEqual('^', token.CIRCUMFLEX)
self.assertExactTypeEqual('<<', token.LEFTSHIFT)
self.assertExactTypeEqual('>>', token.RIGHTSHIFT)
self.assertExactTypeEqual('**', token.DOUBLESTAR)
self.assertExactTypeEqual('+=', token.PLUSEQUAL)
self.assertExactTypeEqual('-=', token.MINEQUAL)
self.assertExactTypeEqual('*=', token.STAREQUAL)
self.assertExactTypeEqual('/=', token.SLASHEQUAL)
self.assertExactTypeEqual('%=', token.PERCENTEQUAL)
self.assertExactTypeEqual('&=', token.AMPEREQUAL)
self.assertExactTypeEqual('|=', token.VBAREQUAL)
self.assertExactTypeEqual('^=', token.CIRCUMFLEXEQUAL)
self.assertExactTypeEqual('^=', token.CIRCUMFLEXEQUAL)
self.assertExactTypeEqual('<<=', token.LEFTSHIFTEQUAL)
self.assertExactTypeEqual('>>=', token.RIGHTSHIFTEQUAL)
self.assertExactTypeEqual('**=', token.DOUBLESTAREQUAL)
self.assertExactTypeEqual('//', token.DOUBLESLASH)
self.assertExactTypeEqual('//=', token.DOUBLESLASHEQUAL)
self.assertExactTypeEqual('@', token.AT)
self.assertExactTypeEqual('@=', token.ATEQUAL)
self.assertExactTypeEqual('a**2+b**2==c**2',
NAME, token.DOUBLESTAR, NUMBER,
token.PLUS,
NAME, token.DOUBLESTAR, NUMBER,
token.EQEQUAL,
NAME, token.DOUBLESTAR, NUMBER)
self.assertExactTypeEqual('{1, 2, 3}',
token.LBRACE,
token.NUMBER, token.COMMA,
token.NUMBER, token.COMMA,
token.NUMBER,
token.RBRACE)
self.assertExactTypeEqual('^(x & 0x1)',
token.CIRCUMFLEX,
token.LPAR,
token.NAME, token.AMPER, token.NUMBER,
token.RPAR)
示例4: test_exact_type
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def test_exact_type(self):
self.assertExactTypeEqual('()', token.LPAR, token.RPAR)
self.assertExactTypeEqual('[]', token.LSQB, token.RSQB)
self.assertExactTypeEqual(':', token.COLON)
self.assertExactTypeEqual(',', token.COMMA)
self.assertExactTypeEqual(';', token.SEMI)
self.assertExactTypeEqual('+', token.PLUS)
self.assertExactTypeEqual('-', token.MINUS)
self.assertExactTypeEqual('*', token.STAR)
self.assertExactTypeEqual('/', token.SLASH)
self.assertExactTypeEqual('|', token.VBAR)
self.assertExactTypeEqual('&', token.AMPER)
self.assertExactTypeEqual('<', token.LESS)
self.assertExactTypeEqual('>', token.GREATER)
self.assertExactTypeEqual('=', token.EQUAL)
self.assertExactTypeEqual('.', token.DOT)
self.assertExactTypeEqual('%', token.PERCENT)
self.assertExactTypeEqual('{}', token.LBRACE, token.RBRACE)
self.assertExactTypeEqual('==', token.EQEQUAL)
self.assertExactTypeEqual('!=', token.NOTEQUAL)
self.assertExactTypeEqual('<=', token.LESSEQUAL)
self.assertExactTypeEqual('>=', token.GREATEREQUAL)
self.assertExactTypeEqual('~', token.TILDE)
self.assertExactTypeEqual('^', token.CIRCUMFLEX)
self.assertExactTypeEqual('<<', token.LEFTSHIFT)
self.assertExactTypeEqual('>>', token.RIGHTSHIFT)
self.assertExactTypeEqual('**', token.DOUBLESTAR)
self.assertExactTypeEqual('+=', token.PLUSEQUAL)
self.assertExactTypeEqual('-=', token.MINEQUAL)
self.assertExactTypeEqual('*=', token.STAREQUAL)
self.assertExactTypeEqual('/=', token.SLASHEQUAL)
self.assertExactTypeEqual('%=', token.PERCENTEQUAL)
self.assertExactTypeEqual('&=', token.AMPEREQUAL)
self.assertExactTypeEqual('|=', token.VBAREQUAL)
self.assertExactTypeEqual('^=', token.CIRCUMFLEXEQUAL)
self.assertExactTypeEqual('^=', token.CIRCUMFLEXEQUAL)
self.assertExactTypeEqual('<<=', token.LEFTSHIFTEQUAL)
self.assertExactTypeEqual('>>=', token.RIGHTSHIFTEQUAL)
self.assertExactTypeEqual('**=', token.DOUBLESTAREQUAL)
self.assertExactTypeEqual('//', token.DOUBLESLASH)
self.assertExactTypeEqual('//=', token.DOUBLESLASHEQUAL)
self.assertExactTypeEqual('@', token.AT)
self.assertExactTypeEqual('a**2+b**2==c**2',
NAME, token.DOUBLESTAR, NUMBER,
token.PLUS,
NAME, token.DOUBLESTAR, NUMBER,
token.EQEQUAL,
NAME, token.DOUBLESTAR, NUMBER)
self.assertExactTypeEqual('{1, 2, 3}',
token.LBRACE,
token.NUMBER, token.COMMA,
token.NUMBER, token.COMMA,
token.NUMBER,
token.RBRACE)
self.assertExactTypeEqual('^(x & 0x1)',
token.CIRCUMFLEX,
token.LPAR,
token.NAME, token.AMPER, token.NUMBER,
token.RPAR)
示例5: com_assign
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def com_assign(self, node, assigning):
# return a node suitable for use as an "lvalue"
# loop to avoid trivial recursion
while 1:
t = node[0]
if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp):
if len(node) > 2:
return self.com_assign_tuple(node, assigning)
node = node[1]
elif t in _assign_types:
if len(node) > 2:
raise SyntaxError, "can't assign to operator"
node = node[1]
elif t == symbol.power:
if node[1][0] != symbol.atom:
raise SyntaxError, "can't assign to operator"
if len(node) > 2:
primary = self.com_node(node[1])
for i in range(2, len(node)-1):
ch = node[i]
if ch[0] == token.DOUBLESTAR:
raise SyntaxError, "can't assign to operator"
primary = self.com_apply_trailer(primary, ch)
return self.com_assign_trailer(primary, node[-1],
assigning)
node = node[1]
elif t == symbol.atom:
t = node[1][0]
if t == token.LPAR:
node = node[2]
if node[0] == token.RPAR:
raise SyntaxError, "can't assign to ()"
elif t == token.LSQB:
node = node[2]
if node[0] == token.RSQB:
raise SyntaxError, "can't assign to []"
return self.com_assign_list(node, assigning)
elif t == token.NAME:
return self.com_assign_name(node[1], assigning)
else:
raise SyntaxError, "can't assign to literal"
else:
raise SyntaxError, "bad assignment (%s)" % t
示例6: _parse
# 需要导入模块: import token [as 别名]
# 或者: from token import RSQB [as 别名]
def _parse(self):
tok = self.current
if tok.exact_type in (token.ENDMARKER, token.COMMA):
return # TODO
if tok.exact_type == token.STRING:
self.next()
return AstLiteral(tok.string[1:-1])
if tok.exact_type == token.NUMBER:
self.next()
try:
value = int(tok.string)
except ValueError:
value = float(tok.string)
return AstLiteral(value)
if tok.exact_type == token.NAME:
state = AstContext(tok.string)
while True:
tok = self.next()
if tok.exact_type == token.DOT:
tok = self.next()
if tok.exact_type != token.NAME:
raise SyntaxError(f"Invalid attr lookup: {tok}")
state = AstAttr(state, tok.string)
elif tok.exact_type == token.LSQB:
self.next()
right = self._parse()
state = AstLookup(state, right)
if self.current.exact_type != token.RSQB:
raise SyntaxError(f"Expected ] but found {self.current}")
elif tok.exact_type == token.LPAR:
state = AstCall(state)
self.next()
while self.current.exact_type != token.RPAR:
arg = self._parse()
state.add_arg(arg)
if self.current.exact_type != token.COMMA:
break
self.next()
if self.current.exact_type != token.RPAR:
raise SyntaxError(f"Expected ( but found {self.current}")
self.next()
else:
break
return state
raise SyntaxError(
f"Error parsing expression {tok.line !r}: Unexpected token {tok.string!r} at position {tok.start[0]}."
)