From 31f33096cb0c22726780434cb4fc9269d4f086df Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 23 Jul 2016 11:40:40 -0400 Subject: [PATCH] ERROR terminal for parser. --- command.cpp | 5 +++++ command.h | 2 +- phase2-parser.lemon | 11 ++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/command.cpp b/command.cpp index fc12a9b..ca16790 100644 --- a/command.cpp +++ b/command.cpp @@ -446,6 +446,11 @@ int error_command::execute(Environment &e, const fdmask &fds, bool throwup) { if (control_c) throw execution_of_input_terminated(); + if (type == ERROR) { + fprintf(stderr, "%s\n", text.c_str()); + return e.status(-3); + } + std::string s = expand_vars(text, e); e.echo("%s", s.c_str()); diff --git a/command.h b/command.h index 743c25d..f554574 100644 --- a/command.h +++ b/command.h @@ -22,7 +22,7 @@ struct command { {} virtual bool terminal() const noexcept { - return type == EVALUATE || type == COMMAND || type == BREAK || type == CONTINUE; + return type == EVALUATE || type == COMMAND || type == BREAK || type == CONTINUE || type == ERROR; } int type = 0; diff --git a/phase2-parser.lemon b/phase2-parser.lemon index 5d59c93..2f00c1b 100644 --- a/phase2-parser.lemon +++ b/phase2-parser.lemon @@ -110,15 +110,20 @@ term(RV) ::= paren_command(C). { RV = std::move(C); } term(RV) ::= loop_command(C). { RV = std::move(C); } term(RV) ::= for_command(C). { RV = std::move(C); } + +/* lexer error (mismatched quotes, etc) */ +term(RV) ::= ERROR(C). { + RV = std::make_unique(@C, std::move(C)); +} + + /* * fall back to an end error. w/o fallback, it will cause a parse conflict. */ /* %fallback ERROR END RPAREN ELSE ELSE_IF. -term(RV) ::= ERROR(C). { - RV = std::make_unique(@C, std::move(C)); -} + */ /*