Remove tok::type::EOF_ because it is useless, and fix the next local constant reference in Parser.hpp

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-03-01 19:40:30 +01:00
parent df10215e4e
commit 6955c5cb4d
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 7 additions and 9 deletions

View File

@ -13,7 +13,7 @@ vector<tok> lex(const string& in)
{
vector<tok> resVal;
unsigned long lineNumber = 1;
for (unsigned int i = 0; i <= in.size(); ++i) {
for (unsigned int i = 0; i < in.size(); ++i) {
const char& current = in[i];
switch (current) {
@ -22,7 +22,7 @@ vector<tok> lex(const string& in)
if (current == TAG && in[i + 1] == DEFINE) { // See the IDENTIFIER case in Parser.hpp
goto insertToken;
} else {
while (not (in[i + 1] == EOF_ || in[i + 1] == '\n')) {
while (not (i == in.size() || in[i + 1] == '\n')) {
++i;
}
break;
@ -42,7 +42,6 @@ vector<tok> lex(const string& in)
break;
} else goto insertToken;
}
[[unlikely]] case EOF_: --lineNumber;
case DEFINE: case LPAR: case RPAR: case COMMA:
case LBRACE: case RBRACE: case LBRACKET: case RBRACKET:
case PLUS: case HYPHEN: case LCOMP: case RCOMP:

View File

@ -10,7 +10,7 @@ struct tok {
typedef Yerbacon::Exception LexerException;
enum type: const unsigned short {
UNEXPECTED = std::numeric_limits<unsigned char>::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR,
EOF_ = '\0', DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$', DOT = '.', COMMA = ',',
DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$', DOT = '.', COMMA = ',',
LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')',
RBRACE = '}', RBRACKET = ']',
PLUS = '+', HYPHEN = '-', DIVIDE = '/',

View File

@ -32,7 +32,8 @@ namespace Parser {
return true;
};
for (;i < lexed.size(); ++i) {
const tok& current = lexed[i], next = (current.toktype != EOF_) ? lexed[i + 1] : current;
const bool hasNext = (i + 1) < lexed.size();
const tok& current = lexed[i], next = hasNext ? lexed[i + 1] : tok(UNEXPECTED);
switch (current.toktype) {
case STRING: parseTree << types::String(current.toktext.data()); break;
@ -41,7 +42,7 @@ namespace Parser {
if (next.toktype == IDENTIFIER) {
parseTree << Class(next.toktext); ++i;
} else {
const bool isNotBlank = (not (next.toktext.empty() or next.toktype == tok::EOF_));
const bool isNotBlank = not next.toktext.empty();
parsingError(next, isNotBlank ? " is not a valid class identifier" : "A class identifier is required", isNotBlank);
}
} else {
@ -67,9 +68,7 @@ namespace Parser {
return it.toktype == inverseCharacter;
});
if (closingCharacter != lexed.cend()) {
vector<tok> subTokens;
subTokens.reserve(distance(lexed.cbegin() + i, closingCharacter));
subTokens.assign(lexed.cbegin() + i + 1, closingCharacter);
vector<tok> subTokens(lexed.cbegin() + 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) {