Add c preprocessor proxies to command file parser to support defines and include

This commit is contained in:
Jan 2021-02-11 11:51:06 +01:00
parent 1822979a8b
commit 751cb2cd6e
3 changed files with 47 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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)