diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2020-04-05 02:34:03 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-05 12:43:39 +0200 |
commit | dd112421b4de94c4203f9b7551cbb74e35c2c81b (patch) | |
tree | 300c14b79cfad93db9c32120deaf39c9f9f29399 /Libraries/LibJS/Parser.cpp | |
parent | 4f200def9c735c97a0a2a2571ad455d3af644aa9 (diff) | |
download | serenity-dd112421b4de94c4203f9b7551cbb74e35c2c81b.zip |
LibJS: Plumb line and column information through Lexer / Parser
While debugging test failures, it's pretty frustrating to have to go do
printf debugging to figure out what test is failing right now. While
watching your JS Raytracer stream it seemed like this was pretty
furstrating as well. So I wanted to start working on improving the
diagnostics here.
In the future I hope we can eventually be able to plumb the info down
to the Error classes so any thrown exceptions will contain enough
metadata to know where they came from.
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 4b074eb7e5..3f91503421 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -967,7 +967,12 @@ Token Parser::consume(TokenType type) { if (m_parser_state.m_current_token.type() != type) { m_parser_state.m_has_errors = true; - fprintf(stderr, "Error: Unexpected token %s. Expected %s\n", m_parser_state.m_current_token.name(), Token::name(type)); + auto& current_token = m_parser_state.m_current_token; + fprintf(stderr, "Error: Unexpected token %s. Expected %s (line: %zu, column: %zu))\n", + current_token.name(), + Token::name(type), + current_token.line_number(), + current_token.line_column()); } return consume(); } @@ -975,7 +980,12 @@ Token Parser::consume(TokenType type) void Parser::expected(const char* what) { m_parser_state.m_has_errors = true; - fprintf(stderr, "Error: Unexpected token %s. Expected %s\n", m_parser_state.m_current_token.name(), what); + auto& current_token = m_parser_state.m_current_token; + fprintf(stderr, "Error: Unexpected token %s. Expected %s (line: %zu, column: %zu)\n", + current_token.name(), + what, + current_token.line_number(), + current_token.line_column()); } void Parser::save_state() |