def _literal_terminal_to_python_val(literal_terminal):
"""
Use the table of "coercer" functions to convert a terminal node from the
parse tree to a Python value.
"""
token_type = literal_terminal.getSymbol().type
token_text = literal_terminal.getText()
if token_type in _TOKEN_TYPE_COERCERS:
coercer = _TOKEN_TYPE_COERCERS[token_type]
try:
python_value = coercer(token_text)
except Exception as e:
six.raise_from(MatcherException(u"Invalid {}: {}".format(
STIXPatternParser.symbolicNames[token_type], token_text
)), e)
else:
raise MatcherInternalError(u"Unsupported literal type: {}".format(
STIXPatternParser.symbolicNames[token_type]))
return python_value
评论列表
文章目录