mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:57: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
|
@ -1418,7 +1418,7 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
|||
auto try_convert = [](StringView value, Type type) -> ErrorOr<Optional<RefPtr<AST::Value>>> {
|
||||
switch (type) {
|
||||
case Type::Bool:
|
||||
return AST::make_ref_counted<AST::StringValue>(TRY("true"_string));
|
||||
return AST::make_ref_counted<AST::StringValue>("true"_string);
|
||||
case Type::String:
|
||||
return AST::make_ref_counted<AST::StringValue>(TRY(String::from_utf8(value)));
|
||||
case Type::I32:
|
||||
|
@ -1602,7 +1602,7 @@ ErrorOr<int> Shell::builtin_argsparser_parse(Main::Arguments arguments)
|
|||
if (type == Type::Bool) {
|
||||
set_local_variable(
|
||||
current_variable,
|
||||
make_ref_counted<AST::StringValue>(MUST("false"_string)),
|
||||
make_ref_counted<AST::StringValue>("false"_string),
|
||||
true);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -81,7 +81,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
|
|||
// ImmediateExpression(length <mode_name> <entry>)
|
||||
resulting_nodes.unchecked_append(AST::make_ref_counted<AST::ImmediateExpression>(
|
||||
expr_node->position(),
|
||||
AST::NameWithPosition { TRY("length"_string), invoking_node.function_position() },
|
||||
AST::NameWithPosition { "length"_string, invoking_node.function_position() },
|
||||
Vector<NonnullRefPtr<AST::Node>> { Vector<NonnullRefPtr<AST::Node>> {
|
||||
static_cast<NonnullRefPtr<AST::Node>>(AST::make_ref_counted<AST::BarewordLiteral>(expr_node->position(), TRY(String::from_utf8(mode_name)))),
|
||||
AST::make_ref_counted<AST::SyntheticNode>(expr_node->position(), NonnullRefPtr<AST::Value>(entry)),
|
||||
|
@ -825,7 +825,7 @@ ErrorOr<Node> parse_assignment_expression(Span<Token>& tokens)
|
|||
if (auto op = token.get_pointer<Operator>(); op && is_assignment_operator(*op)) {
|
||||
if (!lhs.value.has<String>()) {
|
||||
return Node {
|
||||
make<ErrorNode>(TRY("Left-hand side of assignment must be a variable"_string))
|
||||
make<ErrorNode>("Left-hand side of assignment must be a variable"_string)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -851,7 +851,7 @@ ErrorOr<Node> parse_ternary_expression(Span<Token>& tokens)
|
|||
|
||||
if (!next_token_is_operator(tokens, Operator::TernaryColon)) {
|
||||
return Node {
|
||||
make<ErrorNode>(TRY("Expected ':' after true value in ternary expression"_string))
|
||||
make<ErrorNode>("Expected ':' after true value in ternary expression"_string)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -932,7 +932,7 @@ ErrorOr<Node> parse_unary_expression(Span<Token>& tokens)
|
|||
{
|
||||
if (tokens.is_empty()) {
|
||||
return Node {
|
||||
make<ErrorNode>(TRY("Expected expression, got end of input"_string))
|
||||
make<ErrorNode>("Expected expression, got end of input"_string)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -953,7 +953,7 @@ ErrorOr<Node> parse_unary_expression(Span<Token>& tokens)
|
|||
ErrorOr<Node> parse_primary_expression(Span<Token>& tokens)
|
||||
{
|
||||
if (tokens.is_empty())
|
||||
return Node { make<ErrorNode>(TRY("Expected expression, got end of input"_string)) };
|
||||
return Node { make<ErrorNode>("Expected expression, got end of input"_string) };
|
||||
|
||||
auto& token = tokens.first();
|
||||
return token.visit(
|
||||
|
@ -972,7 +972,7 @@ ErrorOr<Node> parse_primary_expression(Span<Token>& tokens)
|
|||
auto value = TRY(parse_expression(tokens));
|
||||
if (!next_token_is_operator(tokens, Operator::CloseParen)) {
|
||||
return Node {
|
||||
make<ErrorNode>(TRY("Expected ')' after expression in parentheses"_string))
|
||||
make<ErrorNode>("Expected ')' after expression in parentheses"_string)
|
||||
};
|
||||
}
|
||||
tokens = tokens.slice(1);
|
||||
|
@ -980,7 +980,7 @@ ErrorOr<Node> parse_primary_expression(Span<Token>& tokens)
|
|||
}
|
||||
default:
|
||||
return Node {
|
||||
make<ErrorNode>(TRY("Expected expression, got operator"_string))
|
||||
make<ErrorNode>("Expected expression, got operator"_string)
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -664,7 +664,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_complete_command()
|
|||
auto position = peek().position;
|
||||
auto syntax_error = make_ref_counted<AST::SyntaxError>(
|
||||
position.value_or(empty_position()),
|
||||
TRY("Extra tokens after complete command"_string));
|
||||
"Extra tokens after complete command"_string);
|
||||
|
||||
if (list)
|
||||
list->set_is_syntax_error(*syntax_error);
|
||||
|
@ -968,13 +968,13 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_while_clause()
|
|||
if (!condition)
|
||||
condition = make_ref_counted<AST::SyntaxError>(
|
||||
peek().position.value_or(empty_position()),
|
||||
TRY("Expected condition after 'while'"_string));
|
||||
"Expected condition after 'while'"_string);
|
||||
|
||||
auto do_group = TRY(parse_do_group());
|
||||
if (!do_group)
|
||||
do_group = make_ref_counted<AST::SyntaxError>(
|
||||
peek().position.value_or(empty_position()),
|
||||
TRY("Expected 'do' after 'while'"_string));
|
||||
"Expected 'do' after 'while'"_string);
|
||||
|
||||
// while foo; bar -> loop { if foo { bar } else { break } }
|
||||
auto position = start_position.with_end(peek().position.value_or(empty_position()));
|
||||
|
@ -1004,13 +1004,13 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_until_clause()
|
|||
if (!condition)
|
||||
condition = make_ref_counted<AST::SyntaxError>(
|
||||
peek().position.value_or(empty_position()),
|
||||
TRY("Expected condition after 'until'"_string));
|
||||
"Expected condition after 'until'"_string);
|
||||
|
||||
auto do_group = TRY(parse_do_group());
|
||||
if (!do_group)
|
||||
do_group = make_ref_counted<AST::SyntaxError>(
|
||||
peek().position.value_or(empty_position()),
|
||||
TRY("Expected 'do' after 'until'"_string));
|
||||
"Expected 'do' after 'until'"_string);
|
||||
|
||||
// until foo; bar -> loop { if foo { break } else { bar } }
|
||||
auto position = start_position.with_end(peek().position.value_or(empty_position()));
|
||||
|
@ -1214,7 +1214,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_if_clause()
|
|||
skip();
|
||||
auto main_condition = TRY(parse_compound_list());
|
||||
if (!main_condition)
|
||||
main_condition = make_ref_counted<AST::SyntaxError>(empty_position(), TRY("Expected compound list after 'if'"_string));
|
||||
main_condition = make_ref_counted<AST::SyntaxError>(empty_position(), "Expected compound list after 'if'"_string);
|
||||
|
||||
RefPtr<AST::SyntaxError> syntax_error;
|
||||
if (peek().type != Token::Type::Then) {
|
||||
|
@ -1227,7 +1227,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_if_clause()
|
|||
|
||||
auto main_consequence = TRY(parse_compound_list());
|
||||
if (!main_consequence)
|
||||
main_consequence = make_ref_counted<AST::SyntaxError>(empty_position(), TRY("Expected compound list after 'then'"_string));
|
||||
main_consequence = make_ref_counted<AST::SyntaxError>(empty_position(), "Expected compound list after 'then'"_string);
|
||||
|
||||
auto node = make_ref_counted<AST::IfCond>(start_position, Optional<AST::Position>(), main_condition.release_nonnull(), main_consequence.release_nonnull(), nullptr);
|
||||
auto active_node = node;
|
||||
|
@ -1236,7 +1236,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_if_clause()
|
|||
skip();
|
||||
auto condition = TRY(parse_compound_list());
|
||||
if (!condition)
|
||||
condition = make_ref_counted<AST::SyntaxError>(empty_position(), TRY("Expected compound list after 'elif'"_string));
|
||||
condition = make_ref_counted<AST::SyntaxError>(empty_position(), "Expected compound list after 'elif'"_string);
|
||||
|
||||
if (peek().type != Token::Type::Then) {
|
||||
if (!syntax_error)
|
||||
|
@ -1249,7 +1249,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_if_clause()
|
|||
|
||||
auto consequence = TRY(parse_compound_list());
|
||||
if (!consequence)
|
||||
consequence = make_ref_counted<AST::SyntaxError>(empty_position(), TRY("Expected compound list after 'then'"_string));
|
||||
consequence = make_ref_counted<AST::SyntaxError>(empty_position(), "Expected compound list after 'then'"_string);
|
||||
|
||||
auto new_node = make_ref_counted<AST::IfCond>(start_position, Optional<AST::Position>(), condition.release_nonnull(), consequence.release_nonnull(), nullptr);
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_if_clause()
|
|||
skip();
|
||||
active_node->false_branch() = TRY(parse_compound_list());
|
||||
if (!active_node->false_branch())
|
||||
active_node->false_branch() = make_ref_counted<AST::SyntaxError>(empty_position(), TRY("Expected compound list after 'else'"_string));
|
||||
active_node->false_branch() = make_ref_counted<AST::SyntaxError>(empty_position(), "Expected compound list after 'else'"_string);
|
||||
break;
|
||||
case Token::Type::Fi:
|
||||
skip();
|
||||
|
@ -1305,10 +1305,10 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_subshell()
|
|||
|
||||
auto list = TRY(parse_compound_list());
|
||||
if (!list)
|
||||
error = make_ref_counted<AST::SyntaxError>(peek().position.value_or(empty_position()), TRY("Expected compound list after ("_string));
|
||||
error = make_ref_counted<AST::SyntaxError>(peek().position.value_or(empty_position()), "Expected compound list after ("_string);
|
||||
|
||||
if (peek().type != Token::Type::CloseParen)
|
||||
error = make_ref_counted<AST::SyntaxError>(peek().position.value_or(empty_position()), TRY("Expected ) after compound list"_string));
|
||||
error = make_ref_counted<AST::SyntaxError>(peek().position.value_or(empty_position()), "Expected ) after compound list"_string);
|
||||
else
|
||||
skip();
|
||||
|
||||
|
@ -1535,14 +1535,14 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
|
|||
auto node = make_ref_counted<AST::ImmediateExpression>(
|
||||
token.position.value_or(empty_position()),
|
||||
AST::NameWithPosition {
|
||||
TRY("math"_string),
|
||||
"math"_string,
|
||||
token.position.value_or(empty_position()),
|
||||
},
|
||||
Vector<NonnullRefPtr<AST::Node>> {
|
||||
make_ref_counted<AST::ImmediateExpression>(
|
||||
token.position.value_or(empty_position()),
|
||||
AST::NameWithPosition {
|
||||
TRY("reexpand"_string),
|
||||
"reexpand"_string,
|
||||
token.position.value_or(empty_position()),
|
||||
},
|
||||
Vector<NonnullRefPtr<AST::Node>> {
|
||||
|
@ -1617,7 +1617,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
|
|||
case ResolvedParameterExpansion::Op::GetLastBackgroundPid:
|
||||
node = make_ref_counted<AST::SyntaxError>(
|
||||
token.position.value_or(empty_position()),
|
||||
TRY("$! not implemented"_string));
|
||||
"$! not implemented"_string);
|
||||
break;
|
||||
case ResolvedParameterExpansion::Op::GetPositionalParameterList:
|
||||
node = make_ref_counted<AST::SpecialVariable>(
|
||||
|
@ -1627,7 +1627,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
|
|||
case ResolvedParameterExpansion::Op::GetCurrentOptionFlags:
|
||||
node = make_ref_counted<AST::SyntaxError>(
|
||||
token.position.value_or(empty_position()),
|
||||
TRY("The current option flags are not available in parameter expansions"_string));
|
||||
"The current option flags are not available in parameter expansions"_string);
|
||||
break;
|
||||
case ResolvedParameterExpansion::Op::GetPositionalParameterCount:
|
||||
node = make_ref_counted<AST::SpecialVariable>(
|
||||
|
@ -1642,7 +1642,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
|
|||
case ResolvedParameterExpansion::Op::GetPositionalParameterListAsString:
|
||||
node = make_ref_counted<AST::SyntaxError>(
|
||||
token.position.value_or(empty_position()),
|
||||
TRY("$* not implemented"_string));
|
||||
"$* not implemented"_string);
|
||||
break;
|
||||
case ResolvedParameterExpansion::Op::GetShellProcessId:
|
||||
node = make_ref_counted<AST::SpecialVariable>(
|
||||
|
@ -1676,7 +1676,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
|
|||
node = make_ref_counted<AST::ImmediateExpression>(
|
||||
token.position.value_or(empty_position()),
|
||||
AST::NameWithPosition {
|
||||
TRY("reexpand"_string),
|
||||
"reexpand"_string,
|
||||
token.position.value_or(empty_position()),
|
||||
},
|
||||
Vector { node.release_nonnull() },
|
||||
|
@ -1904,14 +1904,14 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_simple_command()
|
|||
// run_with_env -e*(assignments) -- (command)
|
||||
nodes.append(make_ref_counted<AST::BarewordLiteral>(
|
||||
empty_position(),
|
||||
TRY("run_with_env"_string)));
|
||||
"run_with_env"_string));
|
||||
}
|
||||
|
||||
auto position = peek().position.value_or(empty_position());
|
||||
nodes.append(make_ref_counted<AST::ImmediateExpression>(
|
||||
position,
|
||||
AST::NameWithPosition {
|
||||
TRY("reexpand"_string),
|
||||
"reexpand"_string,
|
||||
position,
|
||||
},
|
||||
Vector<NonnullRefPtr<AST::Node>> {
|
||||
|
@ -1947,7 +1947,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_simple_command()
|
|||
auto expanded_value = make_ref_counted<AST::ImmediateExpression>(
|
||||
position,
|
||||
AST::NameWithPosition {
|
||||
TRY("reexpand"_string),
|
||||
"reexpand"_string,
|
||||
position,
|
||||
},
|
||||
Vector<NonnullRefPtr<AST::Node>> {
|
||||
|
@ -2034,7 +2034,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_io_here(AST::Position start_position, O
|
|||
|
||||
auto end_keyword = consume();
|
||||
if (!is_one_of(end_keyword.type, Token::Type::Word, Token::Type::Token))
|
||||
return make_ref_counted<AST::SyntaxError>(io_operator_token.position.value_or(start_position), TRY("Expected a heredoc keyword"_string), true);
|
||||
return make_ref_counted<AST::SyntaxError>(io_operator_token.position.value_or(start_position), "Expected a heredoc keyword"_string, true);
|
||||
|
||||
auto [end_keyword_text, allow_interpolation] = Lexer::process_heredoc_key(end_keyword);
|
||||
RefPtr<AST::SyntaxError> error;
|
||||
|
|
|
@ -1743,7 +1743,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
|
|||
else if (!options.invoke_program_for_autocomplete)
|
||||
return Error::from_string_literal("Refusing to use the program itself as completion source");
|
||||
|
||||
completion_command.argv.extend({ TRY("--complete"_string), "--"_short_string });
|
||||
completion_command.argv.extend({ "--complete"_string, "--"_short_string });
|
||||
|
||||
struct Visitor : public AST::NodeVisitor {
|
||||
Visitor(Shell& shell, AST::Position position)
|
||||
|
@ -1912,7 +1912,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
|
|||
|
||||
completion_command.argv.extend(visitor.list());
|
||||
|
||||
auto devnull = TRY("/dev/null"_string);
|
||||
auto devnull = "/dev/null"_string;
|
||||
completion_command.should_wait = true;
|
||||
completion_command.redirections.append(AST::PathRedirection::create(devnull, STDERR_FILENO, AST::PathRedirection::Write));
|
||||
completion_command.redirections.append(AST::PathRedirection::create(devnull, STDIN_FILENO, AST::PathRedirection::Read));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue