mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibJS: Let parser keep track of errors
Rather than printing them to stderr directly the parser now keeps a Vector<Error>, which allows the "owner" of the parser to consume them individually after parsing. The Error struct has a message, line number, column number and a to_string() helper function to format this information into a meaningful error message. The Function() constructor will now include an error message when throwing a SyntaxError.
This commit is contained in:
parent
00b61a212f
commit
33defef267
Notes:
sideshowbarker
2024-07-19 06:38:47 +09:00
Author: https://github.com/linusg
Commit: 33defef267
Pull-request: https://github.com/SerenityOS/serenity/pull/2221
Reviewed-by: https://github.com/Dexesttp
7 changed files with 39 additions and 12 deletions
|
@ -29,7 +29,6 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -1385,12 +1384,11 @@ void Parser::expected(const char* what)
|
|||
|
||||
void Parser::syntax_error(const String& message, size_t line, size_t column)
|
||||
{
|
||||
m_parser_state.m_has_errors = true;
|
||||
if (line == 0 || column == 0) {
|
||||
line = m_parser_state.m_current_token.line_number();
|
||||
column = m_parser_state.m_current_token.line_column();
|
||||
}
|
||||
fprintf(stderr, "Syntax Error: %s (line: %zu, column: %zu)\n", message.characters(), line, column);
|
||||
m_parser_state.m_errors.append({ message, line, column });
|
||||
}
|
||||
|
||||
void Parser::save_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue