Make Parser::parseVector a function template
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
c4f75a3b04
commit
68dc7ea1a1
|
@ -107,7 +107,7 @@ namespace StandardComponents {
|
|||
explicit String(const char* string): content(string) {}
|
||||
};
|
||||
}
|
||||
struct Call: ParseTree { inline explicit Call(ParseTree&& tree) noexcept: ParseTree(move(tree)) {} };
|
||||
struct Call: ParseTree {};
|
||||
|
||||
struct Class: NamedIdentifier {
|
||||
using NamedIdentifier::NamedIdentifier;
|
||||
|
|
|
@ -15,14 +15,15 @@ namespace Parser {
|
|||
const tok& token, const string& text,
|
||||
const bool& quoteTokenText = false
|
||||
) { error(token, text, token.line, quoteTokenText); }
|
||||
ParseTree parseVector(const vector<tok>& lexed) {
|
||||
ParseTree parseTree;
|
||||
IS(ParseTree)
|
||||
T parseVector(const vector<tok>& lexed) {
|
||||
T parseTree;
|
||||
using namespace StandardComponents;
|
||||
using enum tok::type;
|
||||
unsigned int i = 0;
|
||||
const auto nextAre = [&i, &lexed]<convertible_to<tok::type> T>(const initializer_list<T>& nextValues) -> bool {
|
||||
const auto nextAre = [&i, &lexed]<convertible_to<tok::type> Y>(const initializer_list<Y>& nextValues) -> bool {
|
||||
unsigned int j = 1;
|
||||
for (const T& nextValue: nextValues) {
|
||||
for (const Y& nextValue: nextValues) {
|
||||
if (!cmp_greater(lexed.size() - i, nextValues.size()) || lexed[i + j].toktype != nextValue) {
|
||||
return false;
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ namespace Parser {
|
|||
} else {
|
||||
bool isFinalDefine = nextAre({TAG, DEFINE});
|
||||
if (isFinalDefine || next.toktype == DEFINE) {
|
||||
const optional previousDefinition = parseTree.findReferenceByName<Define>(current.toktext);
|
||||
const optional previousDefinition = parseTree.template findReferenceByName<Define>(current.toktext);
|
||||
if (previousDefinition.has_value()) {
|
||||
if (previousDefinition.value().get().final || isFinalDefine) {
|
||||
parsingError(current, previousDefinition->get().final ? " cannot be redefined as it is final" : " cannot be made final after it has been declared", true);
|
||||
|
@ -80,7 +81,7 @@ namespace Parser {
|
|||
}
|
||||
}
|
||||
switch (current.toktype) {
|
||||
case LPAR: parseTree << Call(parseVector(subTokens)); break;
|
||||
case LPAR: parseTree << parseVector<Call>(subTokens); break;
|
||||
case LBRACE: // TODO Add structures for class/function bodies
|
||||
case LBRACKET:
|
||||
default: parseTree << parseVector(subTokens); break;
|
||||
|
|
Loading…
Reference in New Issue