mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Add c preprocessor proxies to command file parser to support defines and include
This commit is contained in:
parent
1822979a8b
commit
751cb2cd6e
@ -2,6 +2,12 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
#include "Parsing/Impl/DefinesStreamProxy.h"
|
||||
#include "Parsing/Impl/IncludingStreamProxy.h"
|
||||
#include "Parsing/Impl/ParserFilesystemStream.h"
|
||||
|
||||
CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||
: m_args(args),
|
||||
m_filename(std::move(filename))
|
||||
@ -11,5 +17,42 @@ CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, s
|
||||
bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||
{
|
||||
std::cout << "Reading commands file: " << m_filename << std::endl;
|
||||
|
||||
ParserFilesystemStream stream(m_filename);
|
||||
if (!stream.IsOpen())
|
||||
{
|
||||
std::cout << "Could not open commands file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
IParserLineStream* lineStream = &stream;
|
||||
|
||||
CommentRemovingStreamProxy commentProxy(lineStream);
|
||||
lineStream = &commentProxy;
|
||||
|
||||
IncludingStreamProxy includeProxy(lineStream);
|
||||
lineStream = &includeProxy;
|
||||
|
||||
DefinesStreamProxy definesProxy(lineStream);
|
||||
definesProxy.AddDefine(ZONE_CODE_GENERATOR_DEFINE_NAME, ZONE_CODE_GENERATOR_DEFINE_VALUE);
|
||||
lineStream = &definesProxy;
|
||||
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
auto line = lineStream->NextLine();
|
||||
|
||||
if (line.IsEof())
|
||||
break;
|
||||
|
||||
std::cout << "Line " << line.m_filename << ":" << line.m_line_number << ": " << line.m_line << "\n";
|
||||
}
|
||||
}
|
||||
catch (const ParsingException& e)
|
||||
{
|
||||
std::cout << "Error: " << e.FullMessage() << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
class CommandsFileReader
|
||||
{
|
||||
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_NAME = "__zonecodegenerator";
|
||||
static constexpr const char* ZONE_CODE_GENERATOR_DEFINE_VALUE = "1";
|
||||
|
||||
const ZoneCodeGeneratorArguments* m_args;
|
||||
std::string m_filename;
|
||||
|
||||
|
@ -47,7 +47,7 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository) const
|
||||
if (line.IsEof())
|
||||
break;
|
||||
|
||||
std::cout << "Line " << line.m_filename << ":" << line.m_line_number << ": " << line.m_line << std::endl;
|
||||
std::cout << "Line " << line.m_filename << ":" << line.m_line_number << ": " << line.m_line << "\n";
|
||||
}
|
||||
}
|
||||
catch (const ParsingException& e)
|
||||
|
Loading…
x
Reference in New Issue
Block a user