aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 08:02:20 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 08:02:20 +0000
commit34a4998658674411ef3b5a392483990467a5d6e2 (patch)
treeace5773a4890ffb88d8f3338f9938d4dfa929804 /lib
parente7320359c12b97ccb85ebfb06b2540124630df7b (diff)
feat(lexer): accept identifiers starting with an underscore
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Lexer/Lexer.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc
index edc77de..9435d04 100644
--- a/lib/Lexer/Lexer.cc
+++ b/lib/Lexer/Lexer.cc
@@ -124,11 +124,20 @@ int Lexer::readToken() {
return IsChar ? tok_char_literal : tok_string_literal;
}
- if (isalpha(LastChar)) {
+ if (isalpha(LastChar) || LastChar == '_') {
IdentifierStr = static_cast<char>(LastChar);
while (isalnum((LastChar = Input.get())) || LastChar == '_')
IdentifierStr += static_cast<char>(LastChar);
+ if (IdentifierStr.size() >= 6) {
+ std::string Prefix = IdentifierStr.substr(0, 6);
+ std::transform(Prefix.begin(), Prefix.end(), Prefix.begin(),
+ [](unsigned char C) { return std::tolower(C); });
+ if (Prefix == "__cps_") {
+ cps::sourceDiagnostic(TokenLine, "error: Reserved runtime identifier at line %d\n", TokenLine);
+ HadError = true;
+ }
+ }
if (IdentifierStr == "CONSTANT") return tok_constant;
if (IdentifierStr == "INCLUDE") return tok_include;
if (IdentifierStr == "INCLUDE_OBJ") return tok_include_obj;