From dc645a36aaade7087ade574cefe69ce7bb29753e Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 09:09:03 +0000 Subject: refactor(diag): file-qualified diagnostic locations Co-Authored-By: Claude Opus 5.5 --- lib/Parser/Parser.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/Parser/Parser.cc') diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc index a7e7edf..826bc89 100644 --- a/lib/Parser/Parser.cc +++ b/lib/Parser/Parser.cc @@ -1,3 +1,4 @@ +#include "cps/Diagnostics.h" #include "cps/Parser.h" #include "cps/FunctionAST.h" #include @@ -98,7 +99,7 @@ std::unique_ptr Parser::ParseStatementImpl() { int Line = Lex.getLine(); getNextToken(); if (CurTok != tok_identifier) { - fprintf(stderr, "error: DELETE requires an object designator at line %d\n", Line); + cps::sourceDiagnostic(Lex.getLine(), "error: DELETE requires an object designator at line %d\n", Line); return nullptr; } std::string Name = Lex.IdentifierStr; @@ -110,7 +111,7 @@ std::unique_ptr Parser::ParseStatementImpl() { } if (CurTok == tok_case) return ParseCaseStmt(); if (CurTok == tok_endcase || CurTok == tok_otherwise) { - fprintf(stderr, "error: Unexpected CASE terminator at line %d\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: Unexpected CASE terminator at line %d\n", Lex.getLine()); getNextToken(); return nullptr; } @@ -124,7 +125,7 @@ std::unique_ptr Parser::ParseStatementImpl() { else if (CurTok == tok_input) { getNextToken(); if (CurTok != tok_identifier) { - fprintf(stderr, "error: Expected variable name after INPUT at line %d\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: Expected variable name after INPUT at line %d\n", Lex.getLine()); return nullptr; } std::string Name = Lex.IdentifierStr; @@ -165,7 +166,7 @@ std::unique_ptr Parser::ParseStatementImpl() { return std::make_unique(); } else if (CurTok == tok_catch || CurTok == tok_endtry) { - fprintf(stderr, "error: Unexpected %s without matching TRY at line %d\n", + cps::sourceDiagnostic(Lex.getLine(), "error: Unexpected %s without matching TRY at line %d\n", CurTok == tok_catch ? "CATCH" : "ENDTRY", Lex.getLine()); getNextToken(); return nullptr; @@ -207,22 +208,22 @@ std::unique_ptr Parser::ParseStatementImpl() { return ParseTypeDecl(); } else if (CurTok == tok_define) { - fprintf(stderr, "error: DEFINE (SET literals) is not implemented at line %d\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: DEFINE (SET literals) is not implemented at line %d\n", Lex.getLine()); getNextToken(); return nullptr; } else if (CurTok == tok_endtype) { - fprintf(stderr, "error: ENDTYPE without matching TYPE at line %d\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: ENDTYPE without matching TYPE at line %d\n", Lex.getLine()); getNextToken(); return nullptr; } else if (CurTok == tok_endclass) { - fprintf(stderr, "error: ENDCLASS without matching CLASS at line %d\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: ENDCLASS without matching CLASS at line %d\n", Lex.getLine()); getNextToken(); return nullptr; } - fprintf(stderr, "error: Unexpected token at line %d when expecting a statement\n", Lex.getLine()); + cps::sourceDiagnostic(Lex.getLine(), "error: Unexpected token at line %d when expecting a statement\n", Lex.getLine()); getNextToken(); // guarantee progress so error recovery cannot loop forever return nullptr; } @@ -252,7 +253,7 @@ std::unique_ptr Parser::ParseAssignStmt() { } if (CurTok != tok_assign) { - fprintf(stderr, "error: Expected '<-' after identifier '%s' at line %d\n", Name.c_str(), Line); + cps::sourceDiagnostic(Lex.getLine(), "error: Expected '<-' after identifier '%s' at line %d\n", Name.c_str(), Line); return nullptr; } getNextToken(); -- cgit v1.3.1-4-g156e