Rename parseVector to parse in Parser.hpp, and make the parameter a span instead of a vector

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-03-09 19:28:59 +01:00
parent cca696b27a
commit 8e7aaadbd0
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 9 additions and 8 deletions

View File

@ -6,6 +6,6 @@ void outputFileContent(const string& file, string_view content);
#include "lex.hpp"
#include "parsing/Parser.hpp"
inline auto parseString(const string& toParse) { return Parser::parseVector(lex(toParse)); }
inline auto parseString(const string& toParse) { return Parser::parse(lex(toParse)); }
#endif //YERBACON_MISC_HPP

View File

@ -5,6 +5,7 @@
#include "ParseComponents.hpp"
#include "../Yerbacon.hpp"
#include <concepts>
#include <span>
namespace Parser {
typedef Yerbacon::Exception ParsingException;
@ -16,7 +17,7 @@ namespace Parser {
const bool& quoteTokenText = false
) { error(token, text, token.line, quoteTokenText); }
IS(ParseTree)
T parseVector(const vector<tok>& lexed) {
T parse(const span<const tok>&& lexed) {
T parseTree;
using namespace StandardComponents;
using enum tok::type;
@ -63,11 +64,11 @@ namespace Parser {
}
case LPAR: case LBRACE: case LBRACKET: {
const auto inverseCharacter = tok::inverseLCharacter(current.toktype);
const auto closingCharacter = find_if(lexed.cbegin() + i, lexed.cend(), [&inverseCharacter](const tok& it){
const auto closingCharacter = find_if(lexed.begin() + i, lexed.end(), [&inverseCharacter](const tok& it){
return it.toktype == inverseCharacter;
});
if (closingCharacter != lexed.cend()) {
vector<tok> subTokens(lexed.cbegin() + i + 1, closingCharacter);
if (closingCharacter != lexed.end()) {
vector<tok> subTokens(lexed.begin() + i + 1, closingCharacter);
if (current.toktype == LPAR || current.toktype == LBRACKET) {
if (subTokens.size() >= 2 && subTokens[1].toktype != RPAR) {
for (auto iterator = subTokens.cbegin(); iterator < (subTokens.cend() - 1); ++iterator) {
@ -79,12 +80,12 @@ namespace Parser {
}
}
switch (current.toktype) {
case LPAR: parseTree << parseVector<Call>(subTokens); break;
case LPAR: parseTree << parse<Call>(subTokens); break;
case LBRACE: // TODO Add structures for class/function bodies
case LBRACKET:
default: parseTree << parseVector(subTokens); break;
default: parseTree << parse(subTokens); break;
}
i = distance(lexed.cbegin(), closingCharacter);
i = distance(lexed.begin(), closingCharacter);
} else parsingError(current, string(" is missing a closing \"").append(1, inverseCharacter) + '"', true);
break;
}