mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 13:15:32 +00:00
improved error handling
This commit is contained in:
parent
a068ca78d7
commit
de8a651df4
2 changed files with 38 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <components/compiler/scanner.hpp>
|
||||
#include <components/compiler/fileparser.hpp>
|
||||
#include <components/compiler/context.hpp>
|
||||
#include <components/compiler/exception.hpp>
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
|
@ -17,12 +18,42 @@ int main (int argc, char **argv)
|
|||
Compiler::StreamErrorHandler errorHandler (std::cout);
|
||||
Compiler::FileParser parser (errorHandler, context);
|
||||
|
||||
std::ifstream file (argc>1 ? argv[1] : "test.mwscript");
|
||||
Compiler::Scanner scanner (errorHandler, file);
|
||||
try
|
||||
{
|
||||
std::string filename = argc>1 ? argv[1] : "test.mwscript";
|
||||
|
||||
scanner.scan (parser);
|
||||
std::ifstream file (filename.c_str());
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cout << "can't open script file: " << filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Compiler::Scanner scanner (errorHandler, file);
|
||||
|
||||
std::cout << "parsed script: " << parser.getName() << std::endl;
|
||||
scanner.scan (parser);
|
||||
}
|
||||
catch (const Compiler::SourceException&)
|
||||
{
|
||||
// ignore exception (problem has already been reported to the user)
|
||||
}
|
||||
|
||||
if (errorHandler.countErrors() || errorHandler.countWarnings())
|
||||
{
|
||||
std::cout
|
||||
<< errorHandler.countErrors() << " error(s), "
|
||||
<< errorHandler.countWarnings() << " warning(s)" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if (errorHandler.isGood())
|
||||
{
|
||||
std::cout << "parsed script: " << parser.getName() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
|
|
@ -386,6 +386,9 @@ namespace Compiler
|
|||
else
|
||||
return false;
|
||||
|
||||
if (special==S_newline)
|
||||
mLoc.mLiteral = "<newline>";
|
||||
|
||||
TokenLoc loc (mLoc);
|
||||
mLoc.mLiteral.clear();
|
||||
|
||||
|
|
Loading…
Reference in a new issue