LibJS: Include source location hint in Parser::print_errors()

This commit is contained in:
Linus Groh 2020-12-06 14:50:39 +00:00 committed by Andreas Kling
parent 28552f3f36
commit abd49c174a
Notes: sideshowbarker 2024-07-19 01:01:26 +09:00
2 changed files with 8 additions and 2 deletions

View file

@ -40,6 +40,8 @@ public:
Token next();
const StringView& source() const { return m_source; };
private:
void consume();
bool consume_exponent();

View file

@ -143,8 +143,12 @@ public:
const Vector<Error>& errors() const { return m_parser_state.m_errors; }
void print_errors() const
{
for (auto& error : m_parser_state.m_errors)
fprintf(stderr, "SyntaxError: %s\n", error.to_string().characters());
for (auto& error : m_parser_state.m_errors) {
auto hint = error.source_location_hint(m_parser_state.m_lexer.source());
if (!hint.is_empty())
warnln("{}", hint);
warnln("SyntaxError: {}", error.to_string());
}
}
private: