From d2bdbc3e775e08b16d38033d978417955e7c2bfa Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 24 Jun 2020 07:45:24 +0430 Subject: [PATCH] Shell: Mark And and Or nodes as execute nodes --- Shell/AST.cpp | 3 +++ Shell/AST.h | 5 ++++- Shell/Parser.cpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 9fd98a74fd..1f64d81c13 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -688,6 +688,9 @@ RefPtr Execute::run(RefPtr shell) { RefPtr job; + if (m_command->would_execute()) + return m_command->run(shell); + auto initial_commands = m_command->run(shell)->resolve_as_commands(shell); decltype(initial_commands) commands; diff --git a/Shell/AST.h b/Shell/AST.h index 581a85ed89..6484ed49cb 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -330,6 +330,7 @@ public: virtual bool is_syntax_error() const { return m_is_syntax_error; } virtual bool is_list() const { return false; } + virtual bool would_execute() const { return false; } const Position& position() const { return m_position; } 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 HitTestResult hit_test_position(size_t) override; virtual String class_name() const override { return "And"; } + virtual bool would_execute() const override { return true; } RefPtr m_left; RefPtr m_right; @@ -585,6 +587,7 @@ private: virtual Vector complete_for_editor(Shell&, size_t, RefPtr matching_node) override; virtual String class_name() const override { return "Execute"; } virtual bool is_execute() const override { return true; } + virtual bool would_execute() const override { return true; } RefPtr m_command; bool m_capture_stdout { false }; @@ -619,7 +622,7 @@ private: virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) override; 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 m_left; RefPtr m_right; diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index ef7d23c79b..ebb81bf79e 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -161,7 +161,7 @@ RefPtr Parser::parse_sequence() if (peek() == '&') { consume(); if (auto expr = parse_sequence()) { - return create(move(execute_pipe_seq), move(expr)); // And + return create(move(execute_pipe_seq), create(move(expr))); // And } return execute_pipe_seq; } @@ -181,7 +181,7 @@ RefPtr Parser::parse_sequence() } consume(); if (auto expr = parse_sequence()) { - return create(move(execute_pipe_seq), move(expr)); // Or + return create(move(execute_pipe_seq), create(move(expr))); // Or } putback(); return execute_pipe_seq;