void
parser::print_error (const parse_error &pe)
{
- string align_parse_error (" ");
-
const token *tok = pe.tok ? pe.tok : last_t;
-
- // print either pe.what() or a deferred error from the lexer
- bool found_junk = false;
- if (tok && tok->type == tok_junk && tok->msg != "")
- {
- found_junk = true;
- cerr << _("parse error: ") << tok->msg << endl;
- }
- else
- {
- cerr << _("parse error: ") << pe.what() << endl;
- }
-
- // NB: It makes sense for lexer errors to always override parser
- // errors, since the original obvious scheme was for the lexer to
- // throw an exception before the token reached the parser.
-
- if (pe.tok || found_junk)
- {
- cerr << _("\tat: ") << *tok << endl;
- session.print_error_source (cerr, align_parse_error, tok);
- }
- else if (tok) // "expected" type error
- {
- cerr << _("\tsaw: ") << *tok << endl;
- session.print_error_source (cerr, align_parse_error, tok);
- }
- else
- {
- cerr << _("\tsaw: ") << input_name << " EOF" << endl;
- }
-
- // print chained macro invocations
- while (tok && tok->chain) {
- tok = tok->chain;
- cerr << _("\tin expansion of macro: ") << *tok << endl;
- session.print_error_source (cerr, align_parse_error, tok);
- }
-
+ session.print_error(pe, tok, input_name);
num_errors ++;
}
std::ostream& operator << (std::ostream& o, const token& t);
-struct parse_error: public std::runtime_error
-{
- const token* tok;
- 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) {}
-};
-
-
typedef enum { ctx_library, ctx_local } macro_ctx;
/* structs from session.h: */
}
}
+void
+systemtap_session::print_error (const parse_error &pe,
+ const token* tok,
+ const std::string &input_name)
+{
+ string align_parse_error (" ");
+
+ // print either pe.what() or a deferred error from the lexer
+ bool found_junk = false;
+ if (tok && tok->type == tok_junk && tok->msg != "")
+ {
+ found_junk = true;
+ cerr << _("parse error: ") << tok->msg << endl;
+ }
+ else
+ {
+ cerr << _("parse error: ") << pe.what() << endl;
+ }
+
+ // NB: It makes sense for lexer errors to always override parser
+ // errors, since the original obvious scheme was for the lexer to
+ // throw an exception before the token reached the parser.
+
+ if (pe.tok || found_junk)
+ {
+ cerr << _("\tat: ") << *tok << endl;
+ print_error_source (cerr, align_parse_error, tok);
+ }
+ else if (tok) // "expected" type error
+ {
+ cerr << _("\tsaw: ") << *tok << endl;
+ print_error_source (cerr, align_parse_error, tok);
+ }
+ else
+ {
+ cerr << _("\tsaw: ") << input_name << " EOF" << endl;
+ }
+
+ // print chained macro invocations
+ while (tok && tok->chain) {
+ tok = tok->chain;
+ cerr << _("\tin expansion of macro: ") << *tok << endl;
+ print_error_source (cerr, align_parse_error, tok);
+ }
+}
+
void
systemtap_session::create_tmp_dir()
{
struct macrodecl; // defined in parse.h
+struct parse_error: public std::runtime_error
+{
+ const token* tok;
+ 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) {}
+};
+
+
struct systemtap_session
{
private:
translator_output* op_create_auxiliary();
- // void print_error (const parse_error& e);
const token* last_token;
void print_token (std::ostream& o, const token* tok);
void print_error (const semantic_error& e);
void print_error_source (std::ostream&, std::string&, const token* tok);
+ void print_error (const parse_error &pe,
+ const token* tok,
+ const std::string &input_name);
void print_warning (const std::string& w, const token* tok = 0);
void printscript(std::ostream& o);