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