diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | parse.cxx | 40 | ||||
-rw-r--r-- | parse.h | 10 |
3 files changed, 36 insertions, 22 deletions
@@ -1,3 +1,11 @@ +2007-04-03 Frank Ch. Eigler <fche@elastic.org> + + Improve error messages for underprivileged scripts. + * parse.h (parse_error): Add skip_some member, true default. + * parse.cxx (parse_embedded_code): Send false on missing -g. + * parse.cxx (parser::parse): Respect flag during parse error + recovery. + 2007-04-02 Frank Ch. Eigler <fche@redhat.com> PR 3261. @@ -803,24 +803,25 @@ parser::parse () catch (parse_error& pe) { print_error (pe); - try - { - // Quietly swallow all tokens until the next '}'. - while (1) - { - const token* t = peek (); - if (! t) - break; - next (); - if (t->type == tok_operator && t->content == "}") - break; - } - } - catch (parse_error& pe2) - { - // parse error during recovery ... ugh - print_error (pe2); - } + if (pe.skip_some) // for recovery + try + { + // Quietly swallow all tokens until the next '}'. + while (1) + { + const token* t = peek (); + if (! t) + break; + next (); + if (t->type == tok_operator && t->content == "}") + break; + } + } + catch (parse_error& pe2) + { + // parse error during recovery ... ugh + print_error (pe2); + } } } @@ -927,7 +928,8 @@ parser::parse_embeddedcode () throw parse_error ("expected '%{'"); if (! privileged) - throw parse_error ("embedded code in unprivileged script"); + throw parse_error ("embedded code in unprivileged script", + false /* don't skip tokens for parse resumption */); e->tok = t; e->code = t->content; @@ -53,9 +53,13 @@ std::ostream& operator << (std::ostream& o, const token& t); struct parse_error: public std::runtime_error { const token* tok; - parse_error (const std::string& msg): runtime_error (msg), tok (0) {} - parse_error (const std::string& msg, const token* t): runtime_error (msg), - tok (t) {} + bool skip_some; + parse_error (const std::string& msg): + runtime_error (msg), tok (0), skip_some (true) {} + parse_error (const std::string& msg, const token* t): + runtime_error (msg), tok (t), skip_some (true) {} + parse_error (const std::string& msg, bool skip): + runtime_error (msg), tok (0), skip_some (skip) {} }; |