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 <string>
|
||||||
#include "ParseComponents.hpp"
|
#include "ParseComponents.hpp"
|
||||||
#include "../Yerbacon.hpp"
|
#include "../Yerbacon.hpp"
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <concepts>
|
||||||
|
|
||||||
namespace Parser {
|
namespace Parser {
|
||||||
class ParsingException: public Yerbacon::Exception {
|
class ParsingException: public Yerbacon::Exception {
|
||||||
|
@ -14,7 +16,20 @@ namespace Parser {
|
||||||
using namespace StandardComponents;
|
using namespace StandardComponents;
|
||||||
using enum tok::type;
|
using enum tok::type;
|
||||||
if (lexed.size() > 1) {
|
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];
|
const auto& current = lexed[i], next = lexed[i + 1];
|
||||||
|
|
||||||
switch (current.toktype) {
|
switch (current.toktype) {
|
||||||
|
@ -25,7 +40,8 @@ namespace Parser {
|
||||||
parseTree << Class(next.toktext); ++i;
|
parseTree << Class(next.toktext); ++i;
|
||||||
} else throw ParsingException('"' + next.toktext + "\" is not a valid class identifier");
|
} else throw ParsingException('"' + next.toktext + "\" is not a valid class identifier");
|
||||||
} else {
|
} else {
|
||||||
const bool isFinalDefine = next.toktype == TAG && (lexed.size() - i) > 2 && lexed[i + 2].toktype == DEFINE;
|
if ((lexed.size() - i) > 2) {
|
||||||
|
bool isFinalDefine = nextAre(2, TAG, DEFINE);
|
||||||
if (isFinalDefine || next.toktype == DEFINE) {
|
if (isFinalDefine || next.toktype == DEFINE) {
|
||||||
parseTree << Define(isFinalDefine, current.toktext);
|
parseTree << Define(isFinalDefine, current.toktext);
|
||||||
i += isFinalDefine ? 2 : 1;
|
i += isFinalDefine ? 2 : 1;
|
||||||
|
@ -34,6 +50,7 @@ namespace Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Target {
|
||||||
protected:
|
protected:
|
||||||
std::stringstream output;
|
std::stringstream output;
|
||||||
INCLUDECOMPONENT(StandardComponents::Define);
|
INCLUDECOMPONENT(StandardComponents::Define);
|
||||||
|
INCLUDECOMPONENT(StandardComponents::types::String)
|
||||||
INCLUDECOMPONENT(StandardComponents::Reference);
|
INCLUDECOMPONENT(StandardComponents::Reference);
|
||||||
INCLUDECOMPONENT(StandardComponents::Class);
|
INCLUDECOMPONENT(StandardComponents::Class);
|
||||||
public:
|
public:
|
||||||
|
@ -25,6 +26,7 @@ public:
|
||||||
for (const unique_ptr<ParseComponent>& component: tree) {
|
for (const unique_ptr<ParseComponent>& component: tree) {
|
||||||
const type_info& id = (*component).getId();
|
const type_info& id = (*component).getId();
|
||||||
with(StandardComponents::Define);
|
with(StandardComponents::Define);
|
||||||
|
with(StandardComponents::types::String);
|
||||||
with(StandardComponents::Reference);
|
with(StandardComponents::Reference);
|
||||||
with(StandardComponents::Class);
|
with(StandardComponents::Class);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue