Intern identifier strings only after checking for keywords

This commit is contained in:
Rangi
2026-05-25 23:55:57 -04:00
parent 7eaca1577d
commit 007672f080
+8 -8
View File
@@ -1203,8 +1203,6 @@ static Token readIdentifier(char firstChar, bool raw) {
builder += c; builder += c;
} }
InternedStr identifier = intern(builder);
// Check for a keyword if the identifier is not raw and not a local label // Check for a keyword if the identifier is not raw and not a local label
if (!raw && tokenType != T_(LOCAL)) { if (!raw && tokenType != T_(LOCAL)) {
if (auto search = keywords.find(builder); search != keywords.end()) { if (auto search = keywords.find(builder); search != keywords.end()) {
@@ -1212,6 +1210,8 @@ static Token readIdentifier(char firstChar, bool raw) {
} }
} }
InternedStr identifier = intern(builder);
// Label scopes `.` and `..` are the only nonlocal identifiers that start with a dot // Label scopes `.` and `..` are the only nonlocal identifiers that start with a dot
if (sym_IsDotScope(identifier)) { if (sym_IsDotScope(identifier)) {
tokenType = T_(SYMBOL); tokenType = T_(SYMBOL);
@@ -1285,13 +1285,13 @@ static std::pair<Symbol const *, std::shared_ptr<std::string>> readInterpolation
return {nullptr, nullptr}; return {nullptr, nullptr};
} }
InternedStr identifier = intern(builder); InternedStr symName = intern(builder);
if (Symbol const *sym = sym_FindScopedValidSymbol(identifier); !sym || !sym->isDefined()) { if (Symbol const *sym = sym_FindScopedValidSymbol(symName); !sym || !sym->isDefined()) {
if (sym_IsPurgedScoped(identifier)) { if (sym_IsPurgedScoped(symName)) {
error("Interpolated symbol `%s` does not exist; it was purged", identifier.c_str()); error("Interpolated symbol `%s` does not exist; it was purged", symName.c_str());
} else { } else {
error("Interpolated symbol `%s` does not exist", identifier.c_str()); error("Interpolated symbol `%s` does not exist", symName.c_str());
} }
return {sym, nullptr}; return {sym, nullptr};
} else if (sym->type == SYM_EQUS) { } else if (sym->type == SYM_EQUS) {
@@ -1303,7 +1303,7 @@ static std::pair<Symbol const *, std::shared_ptr<std::string>> readInterpolation
fmt.appendNumber(*buf, sym->getConstantValue()); fmt.appendNumber(*buf, sym->getConstantValue());
return {sym, buf}; return {sym, buf};
} else { } else {
error("Interpolated symbol `%s` is not a numeric or string symbol", identifier.c_str()); error("Interpolated symbol `%s` is not a numeric or string symbol", symName.c_str());
return {sym, nullptr}; return {sym, nullptr};
} }
} }