diff options
author | Linus Groh <mail@linusgroh.de> | 2020-12-06 14:50:39 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-06 18:52:52 +0100 |
commit | abd49c174a65547aa4a48008a31886608e7ffcb9 (patch) | |
tree | 969b6cdf732b209d2c6fe0e6561b197a64f51f07 | |
parent | 28552f3f367d45d3a97c5442936f0d02f331a3c6 (diff) | |
download | serenity-abd49c174a65547aa4a48008a31886608e7ffcb9.zip |
LibJS: Include source location hint in Parser::print_errors()
-rw-r--r-- | Libraries/LibJS/Lexer.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Parser.h | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/Libraries/LibJS/Lexer.h b/Libraries/LibJS/Lexer.h index 24a4fe9d04..3efe290aa8 100644 --- a/Libraries/LibJS/Lexer.h +++ b/Libraries/LibJS/Lexer.h @@ -40,6 +40,8 @@ public: Token next(); + const StringView& source() const { return m_source; }; + private: void consume(); bool consume_exponent(); diff --git a/Libraries/LibJS/Parser.h b/Libraries/LibJS/Parser.h index 2672eca4d8..6b7a1554af 100644 --- a/Libraries/LibJS/Parser.h +++ b/Libraries/LibJS/Parser.h @@ -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: |