mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
AK: Make "foo"_string infallible
Stop worrying about tiny OOMs. Work towards #20405.
This commit is contained in:
parent
db2a8725c6
commit
34344120f2
181 changed files with 626 additions and 630 deletions
|
@ -174,7 +174,7 @@ RefPtr<AST::Node> Parser::parse()
|
|||
auto error_start = push_start();
|
||||
while (!at_end())
|
||||
consume();
|
||||
auto syntax_error_node = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Unexpected tokens past the end"_string));
|
||||
auto syntax_error_node = create<AST::SyntaxError>("Unexpected tokens past the end"_string);
|
||||
if (!toplevel)
|
||||
toplevel = move(syntax_error_node);
|
||||
else if (!toplevel->is_syntax_error())
|
||||
|
@ -368,7 +368,7 @@ RefPtr<AST::Node> Parser::parse_variable_decls()
|
|||
if (!command)
|
||||
restore_to(*start);
|
||||
else if (!expect(')'))
|
||||
command->set_is_syntax_error(*create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a terminating close paren"_string), true));
|
||||
command->set_is_syntax_error(*create<AST::SyntaxError>("Expected a terminating close paren"_string, true));
|
||||
expression = command;
|
||||
}
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ RefPtr<AST::Node> Parser::parse_function_decl()
|
|||
RefPtr<AST::Node> syntax_error;
|
||||
{
|
||||
auto obrace_error_start = push_start();
|
||||
syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start a function body"_string), true);
|
||||
syntax_error = create<AST::SyntaxError>("Expected an open brace '{' to start a function body"_string, true);
|
||||
}
|
||||
if (!expect('{')) {
|
||||
return create<AST::FunctionDeclaration>(
|
||||
|
@ -461,7 +461,7 @@ RefPtr<AST::Node> Parser::parse_function_decl()
|
|||
RefPtr<AST::SyntaxError> syntax_error;
|
||||
{
|
||||
auto cbrace_error_start = push_start();
|
||||
syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a function body"_string), true);
|
||||
syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end a function body"_string, true);
|
||||
}
|
||||
if (!expect('}')) {
|
||||
if (body)
|
||||
|
@ -502,7 +502,7 @@ RefPtr<AST::Node> Parser::parse_or_logical_sequence()
|
|||
|
||||
auto right_and_sequence = parse_and_logical_sequence();
|
||||
if (!right_and_sequence)
|
||||
right_and_sequence = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an expression after '||'"_string), true);
|
||||
right_and_sequence = create<AST::SyntaxError>("Expected an expression after '||'"_string, true);
|
||||
|
||||
return create<AST::Or>(
|
||||
and_sequence.release_nonnull(),
|
||||
|
@ -526,7 +526,7 @@ RefPtr<AST::Node> Parser::parse_and_logical_sequence()
|
|||
|
||||
auto right_and_sequence = parse_and_logical_sequence();
|
||||
if (!right_and_sequence)
|
||||
right_and_sequence = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an expression after '&&'"_string), true);
|
||||
right_and_sequence = create<AST::SyntaxError>("Expected an expression after '&&'"_string, true);
|
||||
|
||||
return create<AST::And>(
|
||||
pipe_sequence.release_nonnull(),
|
||||
|
@ -708,7 +708,7 @@ RefPtr<AST::Node> Parser::parse_for_loop()
|
|||
consume_while(is_whitespace);
|
||||
auto in_error_start = push_start();
|
||||
if (!expect("in"sv)) {
|
||||
auto syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected 'in' after a variable name in a 'for' loop"_string), true);
|
||||
auto syntax_error = create<AST::SyntaxError>("Expected 'in' after a variable name in a 'for' loop"_string, true);
|
||||
return create<AST::ForLoop>(move(variable_name), move(index_variable_name), move(syntax_error), nullptr); // ForLoop Var Iterated Block
|
||||
}
|
||||
in_start_position = AST::Position { in_error_start->offset, m_offset, in_error_start->line, line() };
|
||||
|
@ -720,14 +720,14 @@ RefPtr<AST::Node> Parser::parse_for_loop()
|
|||
auto iter_error_start = push_start();
|
||||
iterated_expression = parse_expression();
|
||||
if (!iterated_expression)
|
||||
iterated_expression = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an expression in 'for' loop"_string), true);
|
||||
iterated_expression = create<AST::SyntaxError>("Expected an expression in 'for' loop"_string, true);
|
||||
}
|
||||
|
||||
consume_while(is_any_of(" \t\n"sv));
|
||||
{
|
||||
auto obrace_error_start = push_start();
|
||||
if (!expect('{')) {
|
||||
auto syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start a 'for' loop body"_string), true);
|
||||
auto syntax_error = create<AST::SyntaxError>("Expected an open brace '{' to start a 'for' loop body"_string, true);
|
||||
return create<AST::ForLoop>(move(variable_name), move(index_variable_name), move(iterated_expression), move(syntax_error), move(in_start_position), move(index_start_position)); // ForLoop Var Iterated Block
|
||||
}
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ RefPtr<AST::Node> Parser::parse_for_loop()
|
|||
auto cbrace_error_start = push_start();
|
||||
if (!expect('}')) {
|
||||
auto error_start = push_start();
|
||||
auto syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a 'for' loop body"_string), true);
|
||||
auto syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end a 'for' loop body"_string, true);
|
||||
if (body)
|
||||
body->set_is_syntax_error(*syntax_error);
|
||||
else
|
||||
|
@ -764,7 +764,7 @@ RefPtr<AST::Node> Parser::parse_loop_loop()
|
|||
{
|
||||
auto obrace_error_start = push_start();
|
||||
if (!expect('{')) {
|
||||
auto syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start a 'loop' loop body"_string), true);
|
||||
auto syntax_error = create<AST::SyntaxError>("Expected an open brace '{' to start a 'loop' loop body"_string, true);
|
||||
return create<AST::ForLoop>(AST::NameWithPosition {}, AST::NameWithPosition {}, nullptr, move(syntax_error)); // ForLoop null null Block
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ RefPtr<AST::Node> Parser::parse_loop_loop()
|
|||
auto cbrace_error_start = push_start();
|
||||
if (!expect('}')) {
|
||||
auto error_start = push_start();
|
||||
auto syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a 'loop' loop body"_string), true);
|
||||
auto syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end a 'loop' loop body"_string, true);
|
||||
if (body)
|
||||
body->set_is_syntax_error(*syntax_error);
|
||||
else
|
||||
|
@ -803,7 +803,7 @@ RefPtr<AST::Node> Parser::parse_if_expr()
|
|||
auto cond_error_start = push_start();
|
||||
condition = parse_or_logical_sequence();
|
||||
if (!condition)
|
||||
condition = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a logical sequence after 'if'"_string), true);
|
||||
condition = create<AST::SyntaxError>("Expected a logical sequence after 'if'"_string, true);
|
||||
}
|
||||
|
||||
auto parse_braced_toplevel = [&]() -> RefPtr<AST::Node> {
|
||||
|
@ -811,7 +811,7 @@ RefPtr<AST::Node> Parser::parse_if_expr()
|
|||
{
|
||||
auto obrace_error_start = push_start();
|
||||
if (!expect('{')) {
|
||||
body = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start an 'if' true branch"_string), true);
|
||||
body = create<AST::SyntaxError>("Expected an open brace '{' to start an 'if' true branch"_string, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -822,7 +822,7 @@ RefPtr<AST::Node> Parser::parse_if_expr()
|
|||
auto cbrace_error_start = push_start();
|
||||
if (!expect('}')) {
|
||||
auto error_start = push_start();
|
||||
RefPtr<AST::SyntaxError> syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end an 'if' true branch"_string), true);
|
||||
RefPtr<AST::SyntaxError> syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end an 'if' true branch"_string, true);
|
||||
if (body)
|
||||
body->set_is_syntax_error(*syntax_error);
|
||||
else
|
||||
|
@ -874,7 +874,7 @@ RefPtr<AST::Node> Parser::parse_subshell()
|
|||
auto cbrace_error_start = push_start();
|
||||
if (!expect('}')) {
|
||||
auto error_start = push_start();
|
||||
RefPtr<AST::SyntaxError> syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a subshell"_string), true);
|
||||
RefPtr<AST::SyntaxError> syntax_error = create<AST::SyntaxError>("Expected a close brace '}' to end a subshell"_string, true);
|
||||
if (body)
|
||||
body->set_is_syntax_error(*syntax_error);
|
||||
else
|
||||
|
@ -899,7 +899,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
|
|||
auto match_expression = parse_expression();
|
||||
if (!match_expression) {
|
||||
return create<AST::MatchExpr>(
|
||||
create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an expression after 'match'"_string), true),
|
||||
create<AST::SyntaxError>("Expected an expression after 'match'"_string, true),
|
||||
String {}, Optional<AST::Position> {}, Vector<AST::MatchEntry> {});
|
||||
}
|
||||
|
||||
|
@ -916,7 +916,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
|
|||
auto node = create<AST::MatchExpr>(
|
||||
match_expression.release_nonnull(),
|
||||
String {}, move(as_position), Vector<AST::MatchEntry> {});
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected whitespace after 'as' in 'match'"_string), true));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected whitespace after 'as' in 'match'"_string, true));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -925,7 +925,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
|
|||
auto node = create<AST::MatchExpr>(
|
||||
match_expression.release_nonnull(),
|
||||
String {}, move(as_position), Vector<AST::MatchEntry> {});
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an identifier after 'as' in 'match'"_string), true));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected an identifier after 'as' in 'match'"_string, true));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
@ -936,7 +936,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
|
|||
auto node = create<AST::MatchExpr>(
|
||||
match_expression.release_nonnull(),
|
||||
move(match_name), move(as_position), Vector<AST::MatchEntry> {});
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start a 'match' entry list"_string), true));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected an open brace '{' to start a 'match' entry list"_string, true));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -958,7 +958,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
|
|||
auto node = create<AST::MatchExpr>(
|
||||
match_expression.release_nonnull(),
|
||||
move(match_name), move(as_position), move(entries));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a 'match' entry list"_string), true));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected a close brace '}' to end a 'match' entry list"_string, true));
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -991,7 +991,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
} else {
|
||||
auto glob_pattern = parse_match_pattern();
|
||||
if (!glob_pattern)
|
||||
return { Vector<NonnullRefPtr<AST::Node>> {}, {}, {}, {}, create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a pattern in 'match' body"_string), true) };
|
||||
return { Vector<NonnullRefPtr<AST::Node>> {}, {}, {}, {}, create<AST::SyntaxError>("Expected a pattern in 'match' body"_string, true) };
|
||||
|
||||
pattern_kind = Glob;
|
||||
patterns.append(glob_pattern.release_nonnull());
|
||||
|
@ -1009,7 +1009,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
case Regex: {
|
||||
auto pattern = parse_regex_pattern();
|
||||
if (!pattern.has_value()) {
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a regex pattern to follow '|' in 'match' body"_string), true);
|
||||
error = create<AST::SyntaxError>("Expected a regex pattern to follow '|' in 'match' body"_string, true);
|
||||
break;
|
||||
}
|
||||
regexps.append(pattern.release_value());
|
||||
|
@ -1018,7 +1018,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
case Glob: {
|
||||
auto pattern = parse_match_pattern();
|
||||
if (!pattern) {
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a pattern to follow '|' in 'match' body"_string), true);
|
||||
error = create<AST::SyntaxError>("Expected a pattern to follow '|' in 'match' body"_string, true);
|
||||
break;
|
||||
}
|
||||
patterns.append(pattern.release_nonnull());
|
||||
|
@ -1041,7 +1041,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
consume_while(is_any_of(" \t\n"sv));
|
||||
if (!expect('(')) {
|
||||
if (!error)
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an explicit list of identifiers after a pattern 'as'"_string));
|
||||
error = create<AST::SyntaxError>("Expected an explicit list of identifiers after a pattern 'as'"_string);
|
||||
} else {
|
||||
match_names = Vector<String>();
|
||||
for (;;) {
|
||||
|
@ -1057,7 +1057,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
|
||||
if (!expect(')')) {
|
||||
if (!error)
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close paren ')' to end the identifier list of pattern 'as'"_string), true);
|
||||
error = create<AST::SyntaxError>("Expected a close paren ')' to end the identifier list of pattern 'as'"_string, true);
|
||||
}
|
||||
}
|
||||
consume_while(is_any_of(" \t\n"sv));
|
||||
|
@ -1085,7 +1085,7 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
|
||||
if (names[index] != name.view()) {
|
||||
if (!error)
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Alternative regex patterns must have the same capture groups"_string), false);
|
||||
error = create<AST::SyntaxError>("Alternative regex patterns must have the same capture groups"_string, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1096,14 +1096,14 @@ AST::MatchEntry Parser::parse_match_entry()
|
|||
|
||||
if (!expect('{')) {
|
||||
if (!error)
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an open brace '{' to start a match entry body"_string), true);
|
||||
error = create<AST::SyntaxError>("Expected an open brace '{' to start a match entry body"_string, true);
|
||||
}
|
||||
|
||||
auto body = parse_toplevel();
|
||||
|
||||
if (!expect('}')) {
|
||||
if (!error)
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a match entry body"_string), true);
|
||||
error = create<AST::SyntaxError>("Expected a close brace '}' to end a match entry body"_string, true);
|
||||
}
|
||||
|
||||
if (body && error)
|
||||
|
@ -1182,7 +1182,7 @@ RefPtr<AST::Node> Parser::parse_redirection()
|
|||
// Eat a character and hope the problem goes away
|
||||
consume();
|
||||
}
|
||||
path = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a path after redirection"_string), true);
|
||||
path = create<AST::SyntaxError>("Expected a path after redirection"_string, true);
|
||||
}
|
||||
return create<AST::WriteAppendRedirection>(pipe_fd, path.release_nonnull()); // Redirection WriteAppend
|
||||
}
|
||||
|
@ -1205,7 +1205,7 @@ RefPtr<AST::Node> Parser::parse_redirection()
|
|||
}
|
||||
auto redir = create<AST::Fd2FdRedirection>(pipe_fd, dest_pipe_fd); // Redirection Fd2Fd
|
||||
if (dest_pipe_fd == -1)
|
||||
redir->set_is_syntax_error(*create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a file descriptor"_string)));
|
||||
redir->set_is_syntax_error(*create<AST::SyntaxError>("Expected a file descriptor"_string));
|
||||
return redir;
|
||||
}
|
||||
consume_while(is_whitespace);
|
||||
|
@ -1216,7 +1216,7 @@ RefPtr<AST::Node> Parser::parse_redirection()
|
|||
// Eat a character and hope the problem goes away
|
||||
consume();
|
||||
}
|
||||
path = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a path after redirection"_string), true);
|
||||
path = create<AST::SyntaxError>("Expected a path after redirection"_string, true);
|
||||
}
|
||||
return create<AST::WriteRedirection>(pipe_fd, path.release_nonnull()); // Redirection Write
|
||||
}
|
||||
|
@ -1240,7 +1240,7 @@ RefPtr<AST::Node> Parser::parse_redirection()
|
|||
// Eat a character and hope the problem goes away
|
||||
consume();
|
||||
}
|
||||
path = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a path after redirection"_string), true);
|
||||
path = create<AST::SyntaxError>("Expected a path after redirection"_string, true);
|
||||
}
|
||||
if (mode == Read)
|
||||
return create<AST::ReadRedirection>(pipe_fd, path.release_nonnull()); // Redirection Read
|
||||
|
@ -1413,10 +1413,10 @@ RefPtr<AST::Node> Parser::parse_string()
|
|||
consume();
|
||||
auto inner = parse_string_inner(StringEndCondition::DoubleQuote);
|
||||
if (!inner)
|
||||
inner = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Unexpected EOF in string"_string), true);
|
||||
inner = create<AST::SyntaxError>("Unexpected EOF in string"_string, true);
|
||||
if (!expect('"')) {
|
||||
inner = create<AST::DoubleQuotedString>(move(inner));
|
||||
inner->set_is_syntax_error(*create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a terminating double quote"_string), true));
|
||||
inner->set_is_syntax_error(*create<AST::SyntaxError>("Expected a terminating double quote"_string, true));
|
||||
return inner;
|
||||
}
|
||||
return create<AST::DoubleQuotedString>(move(inner)); // Double Quoted String
|
||||
|
@ -1430,7 +1430,7 @@ RefPtr<AST::Node> Parser::parse_string()
|
|||
is_error = true;
|
||||
auto result = create<AST::StringLiteral>(TRY_OR_THROW_PARSE_ERROR(String::from_utf8(text)), AST::StringLiteral::EnclosureType::SingleQuotes); // String Literal
|
||||
if (is_error)
|
||||
result->set_is_syntax_error(*create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a terminating single quote"_string), true));
|
||||
result->set_is_syntax_error(*create<AST::SyntaxError>("Expected a terminating single quote"_string, true));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1599,7 +1599,7 @@ RefPtr<AST::Slice> Parser::parse_slice()
|
|||
RefPtr<AST::SyntaxError> error;
|
||||
|
||||
if (peek() != ']')
|
||||
error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close bracket ']' to end a variable slice"_string));
|
||||
error = create<AST::SyntaxError>("Expected a close bracket ']' to end a variable slice"_string);
|
||||
else
|
||||
consume();
|
||||
|
||||
|
@ -1607,7 +1607,7 @@ RefPtr<AST::Slice> Parser::parse_slice()
|
|||
if (error)
|
||||
spec = move(error);
|
||||
else
|
||||
spec = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected either a range, or a comma-seprated list of selectors"_string));
|
||||
spec = create<AST::SyntaxError>("Expected either a range, or a comma-seprated list of selectors"_string);
|
||||
}
|
||||
|
||||
auto node = create<AST::Slice>(spec.release_nonnull());
|
||||
|
@ -1630,16 +1630,16 @@ RefPtr<AST::Node> Parser::parse_evaluate()
|
|||
consume();
|
||||
auto inner = parse_pipe_sequence();
|
||||
if (!inner)
|
||||
inner = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Unexpected EOF in list"_string), true);
|
||||
inner = create<AST::SyntaxError>("Unexpected EOF in list"_string, true);
|
||||
if (!expect(')'))
|
||||
inner->set_is_syntax_error(*create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a terminating close paren"_string), true));
|
||||
inner->set_is_syntax_error(*create<AST::SyntaxError>("Expected a terminating close paren"_string, true));
|
||||
|
||||
return create<AST::Execute>(inner.release_nonnull(), true);
|
||||
}
|
||||
auto inner = parse_expression();
|
||||
|
||||
if (!inner) {
|
||||
inner = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a command"_string), true);
|
||||
inner = create<AST::SyntaxError>("Expected a command"_string, true);
|
||||
} else {
|
||||
if (inner->is_list()) {
|
||||
auto execute_inner = create<AST::Execute>(inner.release_nonnull(), true);
|
||||
|
@ -1715,9 +1715,9 @@ RefPtr<AST::Node> Parser::parse_immediate_expression()
|
|||
ending_brace_position);
|
||||
|
||||
if (!ending_brace_position.has_value())
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a closing brace '}' to end an immediate expression"_string), true));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected a closing brace '}' to end an immediate expression"_string, true));
|
||||
else if (node->function_name().is_empty())
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an immediate function name"_string)));
|
||||
node->set_is_syntax_error(create<AST::SyntaxError>("Expected an immediate function name"_string));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -1795,7 +1795,7 @@ RefPtr<AST::Node> Parser::parse_history_designator()
|
|||
if (number != 0)
|
||||
selector.event.index = number - 1;
|
||||
else
|
||||
syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("History entry index value invalid or out of range"_string));
|
||||
syntax_error = create<AST::SyntaxError>("History entry index value invalid or out of range"_string);
|
||||
}
|
||||
if (":^$*"sv.contains(peek())) {
|
||||
is_word_selector = true;
|
||||
|
@ -1855,7 +1855,7 @@ RefPtr<AST::Node> Parser::parse_history_designator()
|
|||
auto first_char = peek();
|
||||
if (!(is_digit(first_char) || "^$-*"sv.contains(first_char))) {
|
||||
if (!syntax_error)
|
||||
syntax_error = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a word selector after ':' in a history event designator"_string), true);
|
||||
syntax_error = create<AST::SyntaxError>("Expected a word selector after ':' in a history event designator"_string, true);
|
||||
} else if (first_char == '*') {
|
||||
consume();
|
||||
selector.word_selector_range.start = make_word_selector(AST::HistorySelector::WordSelectorKind::Index, 1);
|
||||
|
@ -2055,7 +2055,7 @@ RefPtr<AST::Node> Parser::parse_brace_expansion()
|
|||
|
||||
if (auto spec = parse_brace_expansion_spec()) {
|
||||
if (!expect('}'))
|
||||
spec->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a close brace '}' to end a brace expansion"_string), true));
|
||||
spec->set_is_syntax_error(create<AST::SyntaxError>("Expected a close brace '}' to end a brace expansion"_string, true));
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
@ -2083,12 +2083,12 @@ RefPtr<AST::Node> Parser::parse_brace_expansion_spec()
|
|||
if (expect(".."sv)) {
|
||||
if (auto end_expr = parse_expression()) {
|
||||
if (end_expr->position().start_offset != start_expr->position().end_offset + 2)
|
||||
end_expr->set_is_syntax_error(create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected no whitespace between '..' and the following expression in brace expansion"_string)));
|
||||
end_expr->set_is_syntax_error(create<AST::SyntaxError>("Expected no whitespace between '..' and the following expression in brace expansion"_string));
|
||||
|
||||
return create<AST::Range>(start_expr.release_nonnull(), end_expr.release_nonnull());
|
||||
}
|
||||
|
||||
return create<AST::Range>(start_expr.release_nonnull(), create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected an expression to end range brace expansion with"_string), true));
|
||||
return create<AST::Range>(start_expr.release_nonnull(), create<AST::SyntaxError>("Expected an expression to end range brace expansion with"_string, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2123,7 +2123,7 @@ RefPtr<AST::Node> Parser::parse_heredoc_initiation_record()
|
|||
consume();
|
||||
|
||||
HeredocInitiationRecord record;
|
||||
record.end = TRY_OR_THROW_PARSE_ERROR("<error>"_string);
|
||||
record.end = "<error>"_string;
|
||||
|
||||
RefPtr<AST::SyntaxError> syntax_error_node;
|
||||
|
||||
|
@ -2161,12 +2161,12 @@ RefPtr<AST::Node> Parser::parse_heredoc_initiation_record()
|
|||
if (!expect('\''))
|
||||
is_error = true;
|
||||
if (is_error)
|
||||
syntax_error_node = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a terminating single quote"_string), true);
|
||||
syntax_error_node = create<AST::SyntaxError>("Expected a terminating single quote"_string, true);
|
||||
|
||||
record.end = TRY_OR_THROW_PARSE_ERROR(String::from_utf8(text));
|
||||
record.interpolate = false;
|
||||
} else {
|
||||
syntax_error_node = create<AST::SyntaxError>(TRY_OR_RESOLVE_TO_ERROR_STRING("Expected a bareword or a single-quoted string literal for heredoc end key"_string), true);
|
||||
syntax_error_node = create<AST::SyntaxError>("Expected a bareword or a single-quoted string literal for heredoc end key"_string, true);
|
||||
}
|
||||
|
||||
auto node = create<AST::Heredoc>(record.end, record.interpolate, record.deindent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue