File indexing completed on 2024-05-19 12:20:57
0001 0002 // This file is meant to be specific to the framework in which the parser 0003 // operates, and is likely to be adapted for different environments. 0004 // Specifically, the error output might not always go to std::cerr, 0005 // but will rather be placed as items inside some listbox. 0006 0007 0008 #include "coolparser.h" 0009 #include "cool_lexer.h" 0010 0011 #include <iostream> 0012 0013 void print_token_environment(cool::Parser* parser); 0014 0015 0016 namespace cool 0017 { 0018 0019 void Parser::report_problem( Parser::problem_type type, const QString & message ) 0020 { 0021 if (type == error) 0022 std::cerr << "** ERROR: " << qPrintable(message) << std::endl; 0023 else if (type == warning) 0024 std::cerr << "** WARNING: " << qPrintable(message) << std::endl; 0025 else if (type == info) 0026 std::cerr << "** Info: " << qPrintable(message) << std::endl; 0027 } 0028 0029 0030 // custom error recovery 0031 void Parser::expectedToken(int /*expected*/, qint64 /*where*/, const QString & name) 0032 { 0033 print_token_environment(this); 0034 report_problem( 0035 Parser::error, 0036 "Expected token ``" + name 0037 //+ "'' instead of ``" + current_token_text 0038 + "''" 0039 ); 0040 } 0041 0042 void Parser::expectedSymbol(int /*expected_symbol*/, const QString & name) 0043 { 0044 print_token_environment(this); 0045 report_problem( 0046 Parser::error, 0047 "Expected symbol ``" + name 0048 //+ "'' instead of ``" + current_token_text 0049 + "''" 0050 ); 0051 } 0052 0053 } // end of namespace cool 0054