mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-06-09 17:29:33 +00:00
simplify grammar a little bit.
This commit is contained in:
parent
09ed3428bc
commit
449595c56b
|
@ -196,7 +196,7 @@ int and_command::execute(Environment &e, const fdmask &fds, bool throwup) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
for (auto &c : children) {
|
for (auto &c : children) {
|
||||||
if (!c) continue;
|
if (!c) continue;
|
||||||
c->execute(e, fds, false);
|
rv = c->execute(e, fds, false);
|
||||||
if (rv != 0) return rv;
|
if (rv != 0) return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +208,8 @@ int vector_command::execute(Environment &e, const fdmask &fds, bool throwup) {
|
||||||
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
for (auto &c : children) {
|
for (auto &c : children) {
|
||||||
|
if (!c) continue;
|
||||||
rv = c->execute(e, fds);
|
rv = c->execute(e, fds);
|
||||||
if (e.exit()) break;
|
|
||||||
}
|
}
|
||||||
return e.status(rv);
|
return e.status(rv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,79 +26,43 @@ std::unique_ptr<phase2_parser> phase2_parser::make() {
|
||||||
%default_type {command_ptr}
|
%default_type {command_ptr}
|
||||||
|
|
||||||
%type start {void}
|
%type start {void}
|
||||||
%type opt_command_list {void}
|
|
||||||
%type command_list {void}
|
%type command_list {void}
|
||||||
%type opt_command_sep {void}
|
|
||||||
|
|
||||||
/* these are put into a queue for immmediate execution */
|
/* 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));
|
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.
|
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 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 ::= .
|
compound_list(RV) ::= compound_list(L) command(C) sep . {
|
||||||
opt_compound_list(RV) ::= compound_list(L). { RV = std::move(L); }
|
|
||||||
|
|
||||||
compound_list(RV) ::= compound_list(L) opt_command(C) sep . {
|
|
||||||
RV = std::move(L);
|
RV = std::move(L);
|
||||||
if (C) RV.emplace_back(std::move(C));
|
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 ::= SEMI.
|
||||||
sep ::= NL.
|
sep ::= NL.
|
||||||
|
|
||||||
%type opt_command { command_ptr }
|
|
||||||
opt_command(RV) ::= command(C). { RV = std::move(C); }
|
|
||||||
opt_command ::= .
|
|
||||||
|
|
||||||
%type command { command_ptr }
|
%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<begin_command>(@T, std::move(L), std::move(T), std::move(E));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* compound list ends with a separator. paren command does not need the final separator */
|
/* compound list ends with a separator. paren command does not need the final separator */
|
||||||
paren_command(RV) ::= LPAREN(T) opt_command(C) RPAREN(E). {
|
%type paren_list { command_ptr_vector }
|
||||||
command_ptr_vector L;
|
|
||||||
if (C) L.emplace_back(std::move(C));
|
paren_list(RV) ::= compound_list(L) . {
|
||||||
RV = std::make_unique<begin_command>(@T, std::move(L), std::move(T), std::move(E));
|
RV = std::move(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
paren_command(RV) ::= LPAREN(T) compound_list(L) RPAREN(E). {
|
paren_list(RV) ::= compound_list(L) command(C) . {
|
||||||
RV = std::make_unique<begin_command>(@T, std::move(L), std::move(T), std::move(E));
|
RV = std::move(L);
|
||||||
|
RV.emplace_back(std::move(C));
|
||||||
}
|
}
|
||||||
|
|
||||||
paren_command(RV) ::= LPAREN(T) compound_list(L) command(C) RPAREN(E). {
|
paren_command(RV) ::= LPAREN(T) paren_list(L) RPAREN(E). {
|
||||||
if (C) L.emplace_back(std::move(C));
|
|
||||||
RV = std::make_unique<begin_command>(@T, std::move(L), std::move(T), std::move(E));
|
RV = std::make_unique<begin_command>(@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<begin_command>(@T, std::move(L), std::move(T), std::move(E));
|
RV = std::make_unique<begin_command>(@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;
|
if_command::clause_vector_type v;
|
||||||
v.emplace_back(std::make_unique<if_else_clause>(IF, std::move(L), std::move(I)));
|
v.emplace_back(std::make_unique<if_else_clause>(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;
|
if_command::clause_vector_type v;
|
||||||
v.emplace_back(std::make_unique<if_else_clause>(IF, std::move(L), std::move(I)));
|
v.emplace_back(std::make_unique<if_else_clause>(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.
|
%token_class else ELSE_IF ELSE.
|
||||||
|
|
||||||
%type else_command { if_command::clause_vector_type }
|
%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<if_else_clause>(@E, std::move(L), std::move(E)));
|
RV.emplace_back(std::make_unique<if_else_clause>(@E, std::move(L), std::move(E)));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
else_command(RV) ::= ELSE_IF(E) sep opt_compound_list(L). {
|
|
||||||
RV.emplace_back(std::make_unique<if_else_clause>(@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 = std::move(EC);
|
||||||
RV.emplace_back(std::make_unique<if_else_clause>(@E, std::move(L), std::move(E)));
|
RV.emplace_back(std::make_unique<if_else_clause>(@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<else_command>(std::move(E), std::move(L)));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
opt_nl ::= .
|
opt_nl ::= .
|
||||||
opt_nl ::= nl.
|
opt_nl ::= opt_nl NL .
|
||||||
nl ::= NL.
|
|
||||||
nl ::= nl NL.
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user