Parsing 95% complete, only missing string parsing

Ruben Dahl 2023-01-26 20:52:43 +01:00
parent 88bd82b762
commit c4b515491a
No known key found for this signature in database
GPG Key ID: C7838D0300EDEF1B
1 changed files with 4 additions and 6 deletions

View File

@ -40,8 +40,6 @@ int parse_line(std::string line, int row) {
struct parsed_token parsed { struct parsed_token parsed {
empty_token, empty_token empty_token, empty_token
}; };
if (line.length() == 0)
return 0;
std::deque<std::string> tokens; std::deque<std::string> tokens;
int start = 0; int start = 0;
size_t end = line.find(" "); size_t end = line.find(" ");
@ -50,6 +48,7 @@ int parse_line(std::string line, int row) {
start = end + 1; start = end + 1;
end = line.find(" ", start); end = line.find(" ", start);
} }
tokens.push_back(line.substr(start));
for (std::string &token : tokens) { for (std::string &token : tokens) {
if (token == "//") if (token == "//")
return 0; return 0;
@ -57,9 +56,6 @@ int parse_line(std::string line, int row) {
try { try {
Token curr_token = CV_Tokens.at(token); Token curr_token = CV_Tokens.at(token);
parsed.last_token = parsed.current_token; parsed.last_token = parsed.current_token;
if (curr_token == parsed.last_token &&
curr_token.type == TokenType::SPACE)
continue;
parsed.current_token = curr_token; parsed.current_token = curr_token;
switch (parsed.current_token.type) { switch (parsed.current_token.type) {
case TokenType::COLONCOLON: { case TokenType::COLONCOLON: {
@ -87,6 +83,8 @@ int parse_line(std::string line, int row) {
ctoken); ctoken);
break; break;
} }
default:
break;
} }
switch (parsed.current_token.intrinsic) { switch (parsed.current_token.intrinsic) {
case Intrinsic::INCLUDE: { case Intrinsic::INCLUDE: {
@ -146,7 +144,7 @@ int parse_line(std::string line, int row) {
default: default:
break; break;
} }
} catch (std::out_of_range &oor) { } catch (std::out_of_range) {
// this is most likely a variable or a string // this is most likely a variable or a string
ferr("%s: Invalid token `%s'.\n", here(row, col), ctoken); ferr("%s: Invalid token `%s'.\n", here(row, col), ctoken);
} }