parse | pipe lines.

This commit is contained in:
Kelvin Sherlock 2016-07-26 14:20:11 -04:00
parent 2fdca6ea9d
commit 0524d10590
4 changed files with 36 additions and 9 deletions

View File

@ -372,7 +372,7 @@ int break_command::execute(Environment &env, const fdmask &fds, bool throwup) {
env.echo("%s", s.c_str());
if (!env.loop()) {
fputs("MPW Shell - Break must be within for or loop.\n", stderr);
fputs("### MPW Shell - Break must be within for or loop.\n", stderr);
return env.status(-3, throwup);
}
@ -394,7 +394,7 @@ int continue_command::execute(Environment &env, const fdmask &fds, bool throwup)
env.echo("%s", s.c_str());
if (!env.loop()) {
fputs("MPW Shell - Continue must be within for or loop.\n", stderr);
fputs("### MPW Shell - Continue must be within for or loop.\n", stderr);
return env.status(-3, throwup);
}
@ -433,6 +433,13 @@ int and_command::execute(Environment &e, const fdmask &fds, bool throwup) {
}
int pipe_command::execute(Environment &e, const fdmask &fds, bool throwup) {
// not yet supported!
fputs( "### MPW Shell - Pipes are not yet supported.\n", stderr);
return e.status(1, throwup);
}
int vector_command::execute(Environment &e, const fdmask &fds, bool throwup) {
int rv = 0;

View File

@ -114,15 +114,13 @@ struct and_command : public binary_command {
};
#if 0
struct pipe_command : public binary_command {
and_command(command_ptr &&a, command_ptr &&b) :
pipe_command(command_ptr &&a, command_ptr &&b) :
binary_command(PIPE, std::move(a), std::move(b))
{}
virtual int execute(Environment &e) final override;
virtual int execute(Environment &e, const fdmask &fds, bool throwup) final override;
};
#endif
struct vector_command : public command {

View File

@ -29,6 +29,9 @@ bool phase2_parser::continuation() const {
if (e.major == PIPE_PIPE) return true;
if (e.major == LOOP) return true;
if (e.major == FOR) return true;
if (e.major == PIPE) return true;
if (e.major == PIPE_PIPE) return true;
if (e.major == AMP_AMP) return true;
}
return false;
}
@ -92,11 +95,9 @@ command(RV) ::= command(L) AMP_AMP opt_nl command(R). {
RV = std::make_unique<and_command>(std::move(L), std::move(R));
}
/*
command(RV) ::= command PIPE opt_nl command. {
command(RV) ::= command(L) PIPE opt_nl command(R). {
RV = std::make_unique<pipe_command>(std::move(L), std::move(R));
}
*/
command(RV) ::= term(T). { RV = std::move(T); }

View File

@ -42,6 +42,25 @@
}
}
action parse_pipe_any {
if (!special()) {
scratch.pop_back();
flush();
parse(PIPE, "|");
}
fhold;
fgoto main;
}
action parse_pipe_eof {
if (!special()) {
scratch.pop_back();
flush();
parse(PIPE, "|");
}
}
action parse_lparen {
if (scratch.empty()) {
parse(LPAREN, "(");
@ -88,6 +107,8 @@
| ';' $parse_semi
| '(' $parse_lparen
| ')' $parse_rparen
| '|' <eof(parse_pipe_eof)
| '|' [^|] $parse_pipe_any
| '|' '|' $parse_pipe_pipe
| '&' '&' $parse_amp_amp
| escape_seq