def eval_token(cls, token, use_decimal=False):
token_type = token.type
token_text = token.string
if token_type == NUMBER:
try:
return int(token_text)
except ValueError:
if use_decimal:
return Decimal(token_text)
return float(token_text)
elif token_type == NAME:
return ParserHelper.from_word(token_text)
else:
raise Exception('unknown token type')
评论列表
文章目录