1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
// This file is meant to be specific to the framework in which the parser
// operates, and is likely to be adapted for different environments.
// Specifically, the error output might not always go to std::cerr,
// but will rather be placed as items inside some listbox.
#include "coolparser.h"
#include "cool_lexer.h"
#include <iostream>
void print_token_environment(cool::Parser* parser);
namespace cool
{
void Parser::report_problem( Parser::problem_type type, const QString & message )
{
if (type == error)
std::cerr << "** ERROR: " << qPrintable(message) << std::endl;
else if (type == warning)
std::cerr << "** WARNING: " << qPrintable(message) << std::endl;
else if (type == info)
std::cerr << "** Info: " << qPrintable(message) << std::endl;
}
// custom error recovery
void Parser::expectedToken(int /*expected*/, qint64 /*where*/, const QString & name)
{
print_token_environment(this);
report_problem(
Parser::error,
QLatin1String("Expected token ``") + name
//+ "'' instead of ``" + current_token_text
+ QLatin1String("''")
);
}
void Parser::expectedSymbol(int /*expected_symbol*/, const QString & name)
{
print_token_environment(this);
report_problem(
Parser::error,
QLatin1String("Expected symbol ``") + name
//+ "'' instead of ``" + current_token_text
+ QLatin1String("''")
);
}
} // end of namespace cool
|