ERROR terminal for parser.

This commit is contained in:
Kelvin Sherlock 2016-07-23 11:40:40 -04:00
parent 6d929aa87f
commit 31f33096cb
3 changed files with 14 additions and 4 deletions

View File

@ -446,6 +446,11 @@ int error_command::execute(Environment &e, const fdmask &fds, bool throwup) {
if (control_c) throw execution_of_input_terminated(); 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); std::string s = expand_vars(text, e);
e.echo("%s", s.c_str()); e.echo("%s", s.c_str());

View File

@ -22,7 +22,7 @@ struct command {
{} {}
virtual bool terminal() const noexcept { 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; int type = 0;

View File

@ -110,15 +110,20 @@ term(RV) ::= paren_command(C). { RV = std::move(C); }
term(RV) ::= loop_command(C). { RV = std::move(C); } term(RV) ::= loop_command(C). { RV = std::move(C); }
term(RV) ::= for_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<error_command>(@C, std::move(C));
}
/* /*
* fall back to an end error. w/o fallback, it will cause a parse conflict. * fall back to an end error. w/o fallback, it will cause a parse conflict.
*/ */
/* /*
%fallback ERROR END RPAREN ELSE ELSE_IF. %fallback ERROR END RPAREN ELSE ELSE_IF.
term(RV) ::= ERROR(C). {
RV = std::make_unique<error_command>(@C, std::move(C));
}
*/ */
/* /*