mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +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 <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)
|
CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||||
: m_args(args),
|
: m_args(args),
|
||||||
m_filename(std::move(filename))
|
m_filename(std::move(filename))
|
||||||
@ -11,5 +17,42 @@ CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, s
|
|||||||
bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||||
{
|
{
|
||||||
std::cout << "Reading commands file: " << m_filename << std::endl;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
class CommandsFileReader
|
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;
|
const ZoneCodeGeneratorArguments* m_args;
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository) const
|
|||||||
if (line.IsEof())
|
if (line.IsEof())
|
||||||
break;
|
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)
|
catch (const ParsingException& e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user