Add a new variadic lambda in Parser.hpp to check the types of tokens
This commit is contained in:
parent
079d99e08a
commit
5d4be1039d
|
@ -4,6 +4,8 @@
|
|||
#include <string>
|
||||
#include "ParseComponents.hpp"
|
||||
#include "../Yerbacon.hpp"
|
||||
#include <cstdarg>
|
||||
#include <concepts>
|
||||
|
||||
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<unsigned int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ParseComponent>& component: tree) {
|
||||
const type_info& id = (*component).getId();
|
||||
with(StandardComponents::Define);
|
||||
with(StandardComponents::types::String);
|
||||
with(StandardComponents::Reference);
|
||||
with(StandardComponents::Class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue