1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

66 lines
1.7 KiB
C++
Raw Normal View History

// Stand-alone MW-script compiler
2010-06-27 19:20:21 +02:00
#include <exception>
#include <iostream>
#include <fstream>
2010-06-27 19:20:21 +02:00
#include <components/compiler/streamerrorhandler.hpp>
#include <components/compiler/scanner.hpp>
#include <components/compiler/fileparser.hpp>
2010-06-28 01:01:48 +02:00
#include <components/compiler/exception.hpp>
#include "context.hpp"
2010-06-27 19:20:21 +02:00
int main (int argc, char **argv)
{
try
{
SACompiler::Context context;
2010-06-27 19:20:21 +02:00
Compiler::StreamErrorHandler errorHandler (std::cout);
Compiler::FileParser parser (errorHandler, context);
2010-06-28 01:01:48 +02:00
try
{
std::string filename = argc>1 ? argv[1] : "test.mwscript";
2010-06-27 19:20:21 +02:00
2010-06-28 01:01:48 +02:00
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);
2010-06-28 01:01:48 +02:00
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;
2010-06-27 19:20:21 +02:00
}
catch (const std::exception &e)
{
std::cout << "\nERROR: " << e.what() << std::endl;
return 1;
}
}