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:
parent
df10215e4e
commit
6955c5cb4d
@ -13,7 +13,7 @@ vector<tok> lex(const string& in)
|
|||||||
{
|
{
|
||||||
vector<tok> resVal;
|
vector<tok> resVal;
|
||||||
unsigned long lineNumber = 1;
|
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];
|
const char& current = in[i];
|
||||||
|
|
||||||
switch (current) {
|
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
|
if (current == TAG && in[i + 1] == DEFINE) { // See the IDENTIFIER case in Parser.hpp
|
||||||
goto insertToken;
|
goto insertToken;
|
||||||
} else {
|
} else {
|
||||||
while (not (in[i + 1] == EOF_ || in[i + 1] == '\n')) {
|
while (not (i == in.size() || in[i + 1] == '\n')) {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -42,7 +42,6 @@ vector<tok> lex(const string& in)
|
|||||||
break;
|
break;
|
||||||
} else goto insertToken;
|
} else goto insertToken;
|
||||||
}
|
}
|
||||||
[[unlikely]] case EOF_: --lineNumber;
|
|
||||||
case DEFINE: case LPAR: case RPAR: case COMMA:
|
case DEFINE: case LPAR: case RPAR: case COMMA:
|
||||||
case LBRACE: case RBRACE: case LBRACKET: case RBRACKET:
|
case LBRACE: case RBRACE: case LBRACKET: case RBRACKET:
|
||||||
case PLUS: case HYPHEN: case LCOMP: case RCOMP:
|
case PLUS: case HYPHEN: case LCOMP: case RCOMP:
|
||||||
|
@ -10,7 +10,7 @@ struct tok {
|
|||||||
typedef Yerbacon::Exception LexerException;
|
typedef Yerbacon::Exception LexerException;
|
||||||
enum type: const unsigned short {
|
enum type: const unsigned short {
|
||||||
UNEXPECTED = std::numeric_limits<unsigned char>::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR,
|
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 = ')',
|
LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')',
|
||||||
RBRACE = '}', RBRACKET = ']',
|
RBRACE = '}', RBRACKET = ']',
|
||||||
PLUS = '+', HYPHEN = '-', DIVIDE = '/',
|
PLUS = '+', HYPHEN = '-', DIVIDE = '/',
|
||||||
|
@ -32,7 +32,8 @@ namespace Parser {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
for (;i < lexed.size(); ++i) {
|
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) {
|
switch (current.toktype) {
|
||||||
case STRING: parseTree << types::String(current.toktext.data()); break;
|
case STRING: parseTree << types::String(current.toktext.data()); break;
|
||||||
@ -41,7 +42,7 @@ namespace Parser {
|
|||||||
if (next.toktype == IDENTIFIER) {
|
if (next.toktype == IDENTIFIER) {
|
||||||
parseTree << Class(next.toktext); ++i;
|
parseTree << Class(next.toktext); ++i;
|
||||||
} else {
|
} 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);
|
parsingError(next, isNotBlank ? " is not a valid class identifier" : "A class identifier is required", isNotBlank);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -67,9 +68,7 @@ namespace Parser {
|
|||||||
return it.toktype == inverseCharacter;
|
return it.toktype == inverseCharacter;
|
||||||
});
|
});
|
||||||
if (closingCharacter != lexed.cend()) {
|
if (closingCharacter != lexed.cend()) {
|
||||||
vector<tok> subTokens;
|
vector<tok> subTokens(lexed.cbegin() + i + 1, closingCharacter);
|
||||||
subTokens.reserve(distance(lexed.cbegin() + i, closingCharacter));
|
|
||||||
subTokens.assign(lexed.cbegin() + 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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user