diff --git a/command.cpp b/command.cpp index 1796abc..5773257 100644 --- a/command.cpp +++ b/command.cpp @@ -196,7 +196,7 @@ int and_command::execute(Environment &e, const fdmask &fds, bool throwup) { int rv = 0; for (auto &c : children) { if (!c) continue; - c->execute(e, fds, false); + rv = c->execute(e, fds, false); if (rv != 0) return rv; } @@ -208,9 +208,8 @@ int vector_command::execute(Environment &e, const fdmask &fds, bool throwup) { int rv = 0; for (auto &c : children) { - + if (!c) continue; rv = c->execute(e, fds); - if (e.exit()) break; } return e.status(rv); } diff --git a/phase2-parser.lemon b/phase2-parser.lemon index 85d65dc..1dc1eba 100644 --- a/phase2-parser.lemon +++ b/phase2-parser.lemon @@ -26,79 +26,43 @@ std::unique_ptr phase2_parser::make() { %default_type {command_ptr} %type start {void} -%type opt_command_list {void} %type command_list {void} -%type opt_command_sep {void} /* these are put into a queue for immmediate execution */ +start ::= command_list. -start ::= opt_command_list. -opt_command_list ::= . -opt_command_list ::= command_list. -command_list ::= command_list opt_command(C) sep . { +command_list ::= . +command_list ::= command_list sep . +command_list ::= command_list command(C) sep . { if (C) command_queue.emplace_back(std::move(C)); } -command_list ::= opt_command(C) sep. { - if (C) command_queue.emplace_back(std::move(C)); -} -/* -command_list ::= opt_command_sep. -command_list ::= command_list opt_command_sep. - - -opt_command_sep ::= opt_command(C) sep. { - if (C) command_queue.emplace_back(std::move(C)); -} -*/ /* compound_list is identical to command_list, but it is not executed immediately. */ -%type opt_compound_list { command_ptr_vector } %type compound_list { command_ptr_vector } -//%type opt_paren_list { command_ptr_vector } -//%type paren_list { command_ptr_vector } +compound_list ::= . +compound_list(RV) ::= compound_list(L) sep. { + RV = std::move(L); +} -opt_compound_list ::= . -opt_compound_list(RV) ::= compound_list(L). { RV = std::move(L); } - -compound_list(RV) ::= compound_list(L) opt_command(C) sep . { +compound_list(RV) ::= compound_list(L) command(C) sep . { RV = std::move(L); if (C) RV.emplace_back(std::move(C)); } -compound_list(RV) ::= opt_command(C) sep. { - if (C) RV.emplace_back(std::move(C)); -} - -/* -opt_paren_list ::= . -opt_paren_list(RV) ::= paren_list(L). { RV = std::move(L); } - -paren_list(RV) ::= opt_command(C). { - if (C) RV.emplace_back(std::move(C)); -} - -paren_list(RV) ::= paren_list(L) sep opt_command(C). { - RV = std::move(L); - if (C) RV.emplace_back(std::move(C)); -} -*/ sep ::= SEMI. sep ::= NL. -%type opt_command { command_ptr } -opt_command(RV) ::= command(C). { RV = std::move(C); } -opt_command ::= . %type command { command_ptr } @@ -137,35 +101,29 @@ term(RV) ::= ERROR(C). { } */ -/* opt_compound_list requires a sep after every item -- not ok for paren command! */ -/* -paren_command(RV) ::= LPAREN(T) opt_paren_list(L) RPAREN(E). { - RV = std::make_unique(@T, std::move(L), std::move(T), std::move(E)); -} -*/ /* compound list ends with a separator. paren command does not need the final separator */ -paren_command(RV) ::= LPAREN(T) opt_command(C) RPAREN(E). { - command_ptr_vector L; - if (C) L.emplace_back(std::move(C)); - RV = std::make_unique(@T, std::move(L), std::move(T), std::move(E)); +%type paren_list { command_ptr_vector } + +paren_list(RV) ::= compound_list(L) . { + RV = std::move(L); } -paren_command(RV) ::= LPAREN(T) compound_list(L) RPAREN(E). { - RV = std::make_unique(@T, std::move(L), std::move(T), std::move(E)); +paren_list(RV) ::= compound_list(L) command(C) . { + RV = std::move(L); + RV.emplace_back(std::move(C)); } -paren_command(RV) ::= LPAREN(T) compound_list(L) command(C) RPAREN(E). { - if (C) L.emplace_back(std::move(C)); +paren_command(RV) ::= LPAREN(T) paren_list(L) RPAREN(E). { RV = std::make_unique(@T, std::move(L), std::move(T), std::move(E)); } -begin_command(RV) ::= BEGIN(T) sep opt_compound_list(L) END(E). { +begin_command(RV) ::= BEGIN(T) sep compound_list(L) END(E). { RV = std::make_unique(@T, std::move(L), std::move(T), std::move(E)); } -if_command(RV) ::= IF(I) sep opt_compound_list(L) END(E). { +if_command(RV) ::= IF(I) sep compound_list(L) END(E). { if_command::clause_vector_type v; v.emplace_back(std::make_unique(IF, std::move(L), std::move(I))); @@ -177,7 +135,7 @@ if_command(RV) ::= IF(I) sep opt_compound_list(L) END(E). { } -if_command(RV) ::= IF(I) sep opt_compound_list(L) else_command(EC) END(E). { +if_command(RV) ::= IF(I) sep compound_list(L) else_command(EC) END(E). { if_command::clause_vector_type v; v.emplace_back(std::make_unique(IF, std::move(L), std::move(I))); @@ -190,29 +148,16 @@ if_command(RV) ::= IF(I) sep opt_compound_list(L) else_command(EC) END(E). { %token_class else ELSE_IF ELSE. %type else_command { if_command::clause_vector_type } -else_command(RV) ::= else(E) sep opt_compound_list(L). { +else_command(RV) ::= else(E) sep compound_list(L). { RV.emplace_back(std::make_unique(@E, std::move(L), std::move(E))); } -/* -else_command(RV) ::= ELSE_IF(E) sep opt_compound_list(L). { - RV.emplace_back(std::make_unique(@E, std::move(L), std::move(E))); -} -*/ -else_command(RV) ::= else_command(EC) else(E) sep opt_compound_list(L). { + +else_command(RV) ::= else_command(EC) else(E) sep compound_list(L). { RV = std::move(EC); RV.emplace_back(std::make_unique(@E, std::move(L), std::move(E))); } -/* -else_command(RV) ::= else_command(EC) ELSE_IF(E) sep opt_compound_list(L). { - RV = std::move(EC); - RV.emplace_back(std::make_unique(std::move(E), std::move(L))); -} -*/ opt_nl ::= . -opt_nl ::= nl. -nl ::= NL. -nl ::= nl NL. - +opt_nl ::= opt_nl NL .