1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:47:47 +00:00

Shell: Mark And and Or nodes as execute nodes

This commit is contained in:
AnotherTest 2020-06-24 07:45:24 +04:30 committed by Andreas Kling
parent 3a37e8c56f
commit d2bdbc3e77
3 changed files with 9 additions and 3 deletions

View file

@ -688,6 +688,9 @@ RefPtr<Value> Execute::run(RefPtr<Shell> shell)
{ {
RefPtr<Job> job; RefPtr<Job> job;
if (m_command->would_execute())
return m_command->run(shell);
auto initial_commands = m_command->run(shell)->resolve_as_commands(shell); auto initial_commands = m_command->run(shell)->resolve_as_commands(shell);
decltype(initial_commands) commands; decltype(initial_commands) commands;

View file

@ -330,6 +330,7 @@ public:
virtual bool is_syntax_error() const { return m_is_syntax_error; } virtual bool is_syntax_error() const { return m_is_syntax_error; }
virtual bool is_list() const { return false; } virtual bool is_list() const { return false; }
virtual bool would_execute() const { return false; }
const Position& position() const { return m_position; } const Position& position() const { return m_position; }
void set_is_syntax_error() { m_is_syntax_error = true; } void set_is_syntax_error() { m_is_syntax_error = true; }
@ -365,6 +366,7 @@ private:
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) override; virtual HitTestResult hit_test_position(size_t) override;
virtual String class_name() const override { return "And"; } virtual String class_name() const override { return "And"; }
virtual bool would_execute() const override { return true; }
RefPtr<Node> m_left; RefPtr<Node> m_left;
RefPtr<Node> m_right; RefPtr<Node> m_right;
@ -585,6 +587,7 @@ private:
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, RefPtr<Node> matching_node) override; virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, RefPtr<Node> matching_node) override;
virtual String class_name() const override { return "Execute"; } virtual String class_name() const override { return "Execute"; }
virtual bool is_execute() const override { return true; } virtual bool is_execute() const override { return true; }
virtual bool would_execute() const override { return true; }
RefPtr<Node> m_command; RefPtr<Node> m_command;
bool m_capture_stdout { false }; bool m_capture_stdout { false };
@ -619,7 +622,7 @@ private:
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) override; virtual HitTestResult hit_test_position(size_t) override;
virtual String class_name() const override { return "Or"; } virtual String class_name() const override { return "Or"; }
virtual bool is_list() const override { return true; } virtual bool would_execute() const override { return true; }
RefPtr<Node> m_left; RefPtr<Node> m_left;
RefPtr<Node> m_right; RefPtr<Node> m_right;

View file

@ -161,7 +161,7 @@ RefPtr<AST::Node> Parser::parse_sequence()
if (peek() == '&') { if (peek() == '&') {
consume(); consume();
if (auto expr = parse_sequence()) { if (auto expr = parse_sequence()) {
return create<AST::And>(move(execute_pipe_seq), move(expr)); // And return create<AST::And>(move(execute_pipe_seq), create<AST::Execute>(move(expr))); // And
} }
return execute_pipe_seq; return execute_pipe_seq;
} }
@ -181,7 +181,7 @@ RefPtr<AST::Node> Parser::parse_sequence()
} }
consume(); consume();
if (auto expr = parse_sequence()) { if (auto expr = parse_sequence()) {
return create<AST::Or>(move(execute_pipe_seq), move(expr)); // Or return create<AST::Or>(move(execute_pipe_seq), create<AST::Execute>(move(expr))); // Or
} }
putback(); putback();
return execute_pipe_seq; return execute_pipe_seq;