Skip to content

Commit

Permalink
Shell: Mark And and Or nodes as execute nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard authored and awesomekling committed Jul 5, 2020
1 parent 3a37e8c commit d2bdbc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Shell/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ RefPtr<Value> Execute::run(RefPtr<Shell> shell)
{
RefPtr<Job> 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;

Expand Down
5 changes: 4 additions & 1 deletion Shell/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class Node : public RefCounted<Node> {
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; }
Expand Down Expand Up @@ -365,6 +366,7 @@ class And final : public Node {
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<Node> m_left;
RefPtr<Node> m_right;
Expand Down Expand Up @@ -585,6 +587,7 @@ class Execute final : public Node {
virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, RefPtr<Node> 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<Node> m_command;
bool m_capture_stdout { false };
Expand Down Expand Up @@ -619,7 +622,7 @@ class Or final : public Node {
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<Node> m_left;
RefPtr<Node> m_right;
Expand Down
4 changes: 2 additions & 2 deletions Shell/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ RefPtr<AST::Node> Parser::parse_sequence()
if (peek() == '&') {
consume();
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;
}
Expand All @@ -181,7 +181,7 @@ RefPtr<AST::Node> Parser::parse_sequence()
}
consume();
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();
return execute_pipe_seq;
Expand Down

0 comments on commit d2bdbc3

Please sign in to comment.