From 34a4998658674411ef3b5a392483990467a5d6e2 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:02:20 +0000 Subject: feat(lexer): accept identifiers starting with an underscore Co-Authored-By: Claude Opus 5.5 --- lib/Lexer/Lexer.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/Lexer') 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(LastChar); while (isalnum((LastChar = Input.get())) || LastChar == '_') IdentifierStr += static_cast(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; -- cgit v1.3.1-4-g156e