From 0524d105904be5dc48c4bfdeda4eddaa9c7b5dff Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 26 Jul 2016 14:20:11 -0400 Subject: [PATCH] parse | pipe lines. --- command.cpp | 11 +++++++++-- command.h | 6 ++---- phase2-parser.lemon | 7 ++++--- phase2.rl | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/command.cpp b/command.cpp index a500eb5..95db807 100644 --- a/command.cpp +++ b/command.cpp @@ -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; diff --git a/command.h b/command.h index f554574..68b07b2 100644 --- a/command.h +++ b/command.h @@ -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 { diff --git a/phase2-parser.lemon b/phase2-parser.lemon index 2f00c1b..5ecc2d6 100644 --- a/phase2-parser.lemon +++ b/phase2-parser.lemon @@ -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(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(std::move(L), std::move(R)); } -*/ command(RV) ::= term(T). { RV = std::move(T); } diff --git a/phase2.rl b/phase2.rl index 779cc83..b5ab4ca 100644 --- a/phase2.rl +++ b/phase2.rl @@ -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 + | '|'