mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:45:06 +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
7 changed files with 39 additions and 12 deletions
|
@ -70,8 +70,8 @@ Value FunctionConstructor::construct(Interpreter& interpreter)
|
|||
auto parser = Parser(Lexer(source));
|
||||
auto function_expression = parser.parse_function_node<FunctionExpression>();
|
||||
if (parser.has_errors()) {
|
||||
// FIXME: The parser should expose parsing error strings rather than just fprintf()'ing them
|
||||
interpreter.throw_exception<SyntaxError>("");
|
||||
auto error = parser.errors()[0];
|
||||
interpreter.throw_exception<SyntaxError>(error.to_string());
|
||||
return {};
|
||||
}
|
||||
return function_expression->execute(interpreter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue