From 927e3fc0384c941f9ad313a28768660c3cdb1777 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:04:15 +0000 Subject: feat(driver): add #LIB directive hiding library lines in runtime errors Co-Authored-By: Claude Opus 5.5 --- lib/Lexer/Lexer.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/Lexer') 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(LastChar); + LastChar = Input.get(); + } while (LastChar != EOF && LastChar != '\n' && LastChar != '\r'); + while (!Directive.empty() && isspace(static_cast(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; -- cgit v1.3.1-4-g156e