continuation prompt.

This commit is contained in:
Kelvin Sherlock 2016-02-04 21:57:17 -05:00
parent 449595c56b
commit 371ce08ef6
4 changed files with 27 additions and 4 deletions

View File

@ -335,6 +335,8 @@ class yypParser : public LEMON_SUPER {
}
#endif
const yyStackEntry *begin() const { return &yystack[0]; }
const yyStackEntry *end() const { return &yystack[yyidx > 0 ? yyidx + 1: 0]; }
protected:
private:

View File

@ -96,7 +96,7 @@ int read_fd(phase1 &p, int fd) {
return 0;
}
int interactive(phase1 &p) {
int interactive(phase1 &p, phase2& p2) {
std::string history_file = root();
history_file += ".history";
@ -104,7 +104,9 @@ int interactive(phase1 &p) {
for(;;) {
char *cp = readline("# ");
const char *prompt = "# ";
if (p2.continuation()) prompt = "> ";
char *cp = readline(prompt);
if (!cp) break;
std::string s(cp);
@ -233,7 +235,7 @@ int main(int argc, char **argv) {
}
if (isatty(STDIN_FILENO))
interactive(p1);
interactive(p1, p2);
else
read_fd(p1, STDIN_FILENO);
p2.finish();

View File

@ -9,7 +9,7 @@
#include "phase2.h"
#include "command.h"
#define LEMON_SUPER phase2_parser
#include "phase2-parser.h"
}
%code {
@ -17,6 +17,20 @@
std::unique_ptr<phase2_parser> phase2_parser::make() {
return std::make_unique<yypParser>();
}
bool phase2_parser::continuation() const {
yypParser *self = (yypParser *)this;
for (const auto &e : *self) {
if (e.major == BEGIN) return true;
if (e.major == LPAREN) return true;
if (e.major == IF) return true;
if (e.major == AMP_AMP) return true;
if (e.major == PIPE_PIPE) return true;
}
return false;
}
}
%left PIPE_PIPE AMP_AMP.

View File

@ -22,6 +22,7 @@ public:
virtual void parse_accept() override final;
virtual void parse_failure() override final;
bool continuation() const;
private:
friend class phase2;
@ -65,6 +66,10 @@ public:
return *this;
}
bool continuation() const {
return parser ? parser->continuation() : false;
}
private:
void parse(int, std::string &&);