From e28741f97d98ea84347a28100964c777830e5f74 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 29 Jan 2016 22:21:51 -0500 Subject: [PATCH] fix command.h --- command.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/command.h b/command.h index 5876b7b..95e9171 100644 --- a/command.h +++ b/command.h @@ -1,44 +1,96 @@ +#ifndef __command_h__ +#define __command_h__ + #include #include #include +#include "mpw-shell-grammar.h" typedef std::unique_ptr command_ptr; typedef std::vector command_ptr_vector; typedef std::array command_ptr_pair; -struct command { - enum { - }; - int type; +struct command { + + command(int t = 0) : type(t) + {} + + int type = 0; virtual ~command(); - virtual int run(); + virtual int execute(); }; struct simple_command : public command { + template + simple_command(S &&s) : command(COMMAND), text(std::forward(s)) + {} + std::string text; }; struct binary_command : public command { + + binary_command(int t, command_ptr &&a, command_ptr &&b) : + command(t), children({{std::move(a), std::move(b)}}) + {} + command_ptr_pair children; }; struct or_command : public binary_command { + or_command(command_ptr &&a, command_ptr &&b) : + binary_command(PIPE_PIPE, std::move(a), std::move(b)) + {} }; struct and_command : public binary_command { - + and_command(command_ptr &&a, command_ptr &&b) : + binary_command(AMP_AMP, std::move(a), std::move(b)) + {} }; -struct begin_command : public command { +struct vector_command : public command { + vector_command(int t, command_ptr_vector &&v) : command(t), children(std::move(v)) + {} + command_ptr_vector children; +}; + +struct begin_command : public vector_command { + template + begin_command(int t, command_ptr_vector &&v, S &&s) : + vector_command(t, std::move(v)), end(std::forward(s)) + {} + std::string end; }; struct if_command : public command { - std::string begin; - command_ptr_vector children; - command_ptr_vector else_clause; + + typedef std::vector clause_vector_type; + + template + if_command(clause_vector_type &&v, S &&s) : + command(IF), clauses(std::move(v)), end(std::forward(s)) + {} + + + clause_vector_type clauses; std::string end; }; + +struct if_else_clause : public vector_command { + + template + if_else_clause(int t, command_ptr_vector &&v, S &&s) : + vector_command(t, std::move(v)), clause(std::forward(s)) + {} + + std::string clause; + + bool evaluate(); +}; + +#endif \ No newline at end of file