def parse(self, data, path=None):
"""
Args:
data (str): Raw specification text.
path (Optional[str]): Path to specification on filesystem. Only
used to tag tokens with the file they originated from.
"""
assert not self.exhausted, 'Must call get_parser() to reset state.'
self.path = path
parsed_data = self.yacc.parse(data, lexer=self.lexer, debug=self.debug)
# It generally makes sense for lexer errors to come first, because
# those can be the root of parser errors. Also, since we only show one
# error max right now, it's best to show the lexing one.
for err_msg, lineno in self.lexer.errors[::-1]:
self.errors.insert(0, (err_msg, lineno, self.path))
parsed_data.extend(self.anony_defs)
self.exhausted = True
return parsed_data
评论列表
文章目录