Fix tokenization of long words

This commit is contained in:
Sofia 2026-04-11 22:06:15 +03:00
parent bd76e8676f
commit 96e4d6232f

View File

@ -128,7 +128,9 @@ namespace token {
uint32_t line = 0;
uint32_t line_start = 0;
for (int i = 0; i < static_cast<int>(text.length());) {
int text_length = static_cast<int>(text.length());
for (int i = 0; i < text_length;) {
Position position{ line, i - line_start };
Metadata meta{ position, position, filename };
@ -138,6 +140,7 @@ namespace token {
std::string content{};
do {
content += c;
if ((i + 1) >= text_length) break;
c = text[++i];
} while (std::isdigit(c));
tokens.push_back(token::Token{ token::Type::LiteralInt, content, meta + content.size() });
@ -147,6 +150,7 @@ namespace token {
c = text[++i]; // Skip initial "
do {
content += c;
if ((i + 1) >= text_length) break;
c = text[++i];
} while (c != '\"');
i++; // Skip second "
@ -156,6 +160,7 @@ namespace token {
std::string content{};
do {
content += c;
if ((i + 1) >= text_length) break;
c = text[++i];
} while (std::isalnum(c));
@ -179,6 +184,7 @@ namespace token {
line_start = i + 1;
}
content += c;
if ((i + 1) >= text_length) break;
c = text[++i];
} while (iswhitespace(c));
// tokens.push_back(token::Token{ token::Type::Whitespace, content });