aboutsummaryrefslogtreecommitdiff
path: root/lib/Lexer
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 08:04:15 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 08:04:15 +0000
commit927e3fc0384c941f9ad313a28768660c3cdb1777 (patch)
treeee82bef8d8332dad79d05db87f33979f0e7eb423 /lib/Lexer
parent34a4998658674411ef3b5a392483990467a5d6e2 (diff)
feat(driver): add #LIB directive hiding library lines in runtime errors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Lexer')
-rw-r--r--lib/Lexer/Lexer.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc
index 9435d04..577a741 100644
--- a/lib/Lexer/Lexer.cc
+++ b/lib/Lexer/Lexer.cc
@@ -91,11 +91,27 @@ std::string Lexer::readEscape(bool IsChar) {
int Lexer::readToken() {
while (isspace(LastChar)) {
- if (LastChar == '\n') CurrentLine++;
+ if (LastChar == '\n') { CurrentLine++; LineStart = true; }
LastChar = Input.get();
}
TokenLine = CurrentLine;
+ if (LastChar == '#' && LineStart) {
+ std::string Directive;
+ do {
+ Directive += static_cast<char>(LastChar);
+ LastChar = Input.get();
+ } while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');
+ while (!Directive.empty() && isspace(static_cast<unsigned char>(Directive.back())))
+ Directive.pop_back();
+ if (Directive == "#LIB") Library = true;
+ else {
+ cps::sourceDiagnostic(TokenLine, "error: Unknown compiler directive at line %d\n", TokenLine);
+ HadError = true;
+ }
+ return readToken();
+ }
+ LineStart = false;
if (LastChar == '"' || LastChar == '\'') {
const int Quote = LastChar;