本文整理汇总了Python中scanner.Scanner.require_token方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.require_token方法的具体用法?Python Scanner.require_token怎么用?Python Scanner.require_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scanner.Scanner
的用法示例。
在下文中一共展示了Scanner.require_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kwargs
# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import require_token [as 别名]
#.........这里部分代码省略.........
try:
result = self.__parse_elements()
except UnexpectedTokenException:
pass
self.__advance_requiring(TokenType.rsquare)
return result
def __parse_members(self):
"""
Parses members of potential object
:return: dictionary with members
"""
result = {}
while True:
try:
name, value = self.__parse_pair()
if self.simple_value is False:
result[name] = JSONValueModel(name, value, predict_references=self.predict_references)
else:
result[name] = value
except UnexpectedTokenException:
raise UnexpectedTokenException
try:
self.__advance_requiring(TokenType.comma)
if self.scanner.peek(1) == u'}':
raise MalformedObjectException("Malformed object: got comma and rbrace")
except UnexpectedTokenException:
return result
def __parse_pair(self):
"""
Parses pair of string: value
:return: name and value
"""
name = self.__parse_string()
self.__advance_requiring(TokenType.colon)
try:
value = self.__parse_value()
except TokenMismatchException as e:
raise e
return name, value
def __parse_elements(self):
"""
Parses elements of potential array
:return: list filled with elements
"""
array = []
while True:
try:
array.append(self.__parse_value())
self.__advance_requiring(TokenType.comma)
if self.scanner.peek(1) == u']':
raise MalformedArrayException("Malformed array: got comma and rsquare instead of value")
except UnexpectedTokenException:
return array
def __parse_string(self):
self.__advance_requiring(TokenType.string)
return self.scanner.token.value[1:-1] # removes enclosing quotes
def __parse_number(self):
self.__advance_requiring(TokenType.number)
try:
return int(self.scanner.token.value)
except ValueError:
pass
try:
return float(self.scanner.token.value)
except ValueError:
raise TokenMismatchException
def __parse_bool(self):
try:
self.__advance_requiring(TokenType.true)
return True
except UnexpectedTokenException:
pass
try:
self.__advance_requiring(TokenType.false)
return False
except UnexpectedTokenException as e:
raise e
def __parse_null(self):
try:
self.__advance_requiring(TokenType.null)
return None
except UnexpectedTokenException as e:
raise e
def __advance_requiring(self, token_type):
#print "Requiring: {0}".format(token_type)
self.scanner.advance()
self.scanner.require_token(token_type)
self.parsed_string += self.scanner.token.value