diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 87439b7..9278f26 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -4,6 +4,8 @@ #include #include "ParseComponents.hpp" #include "../Yerbacon.hpp" +#include +#include namespace Parser { class ParsingException: public Yerbacon::Exception { @@ -14,7 +16,20 @@ namespace Parser { using namespace StandardComponents; using enum tok::type; if (lexed.size() > 1) { - for (unsigned int i = 0; i < lexed.size() - 1; ++i) { + unsigned int i = 0; + const auto nextAre = [&i, &lexed](convertible_to auto nextValues,...) { + va_list argumentsList; + va_start(argumentsList, nextValues); + for (decltype(nextValues) j = 1; j <= nextValues; ++j) { + if (!cmp_greater(lexed.size() - i, nextValues) || lexed[i + j].toktype != va_arg(argumentsList, decltype(nextValues))) { + va_end(argumentsList); + return false; + } + } + va_end(argumentsList); + return true; + }; + for (;i < lexed.size() - 1; ++i) { const auto& current = lexed[i], next = lexed[i + 1]; switch (current.toktype) { @@ -25,12 +40,14 @@ namespace Parser { parseTree << Class(next.toktext); ++i; } else throw ParsingException('"' + next.toktext + "\" is not a valid class identifier"); } else { - const bool isFinalDefine = next.toktype == TAG && (lexed.size() - i) > 2 && lexed[i + 2].toktype == DEFINE; - if (isFinalDefine || next.toktype == DEFINE) { - parseTree << Define(isFinalDefine, current.toktext); - i += isFinalDefine ? 2 : 1; - } else { - parseTree << Reference(current.toktext); + if ((lexed.size() - i) > 2) { + bool isFinalDefine = nextAre(2, TAG, DEFINE); + if (isFinalDefine || next.toktype == DEFINE) { + parseTree << Define(isFinalDefine, current.toktext); + i += isFinalDefine ? 2 : 1; + } else { + parseTree << Reference(current.toktext); + } } } } diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index bd65a5f..39a753a 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -14,6 +14,7 @@ class Target { protected: std::stringstream output; INCLUDECOMPONENT(StandardComponents::Define); + INCLUDECOMPONENT(StandardComponents::types::String) INCLUDECOMPONENT(StandardComponents::Reference); INCLUDECOMPONENT(StandardComponents::Class); public: @@ -25,6 +26,7 @@ public: for (const unique_ptr& component: tree) { const type_info& id = (*component).getId(); with(StandardComponents::Define); + with(StandardComponents::types::String); with(StandardComponents::Reference); with(StandardComponents::Class); }