From c6d0e8de631ac4c287f9d98d80ba56e1cdfbdcc0 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 24 Jul 2025 11:19:04 -0400 Subject: [PATCH] Improve some error messages --- src/asm/lexer.cpp | 5 ++++- src/link/script.y | 2 +- test/asm/line-continuation-at-eof.asm | 1 + test/asm/line-continuation-at-eof.err | 3 +++ test/asm/line-continuation.err | 2 +- test/asm/macro-arg-0.err | 2 +- test/asm/macro-arg-recursion.err | 2 +- test/asm/null-outside-string.err | 8 ++++---- 8 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/asm/line-continuation-at-eof.asm create mode 100644 test/asm/line-continuation-at-eof.err diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index b4e4c488..32ccc587 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -982,8 +982,11 @@ static void discardLineContinuation() { break; } else if (c == ';') { discardComment(); + } else if (c == EOF) { + error("Invalid line continuation at end of file"); + break; } else { - error("Begun line continuation, but encountered character %s", printChar(c)); + error("Invalid character after line continuation %s", printChar(c)); break; } } diff --git a/src/link/script.y b/src/link/script.y index 0f769b76..925ab445 100644 --- a/src/link/script.y +++ b/src/link/script.y @@ -459,7 +459,7 @@ yy::parser::symbol_type yylex() { scriptError(context, "Unknown keyword \"%s\"", ident.c_str()); return yylex(); } else { - scriptError(context, "Unexpected character '%s'", printChar(c)); + scriptError(context, "Unexpected character %s", printChar(c)); // Keep reading characters until the EOL, to avoid reporting too many errors. for (c = context.file.sgetc(); !isNewline(c); c = context.file.sgetc()) { if (c == EOF) { diff --git a/test/asm/line-continuation-at-eof.asm b/test/asm/line-continuation-at-eof.asm new file mode 100644 index 00000000..9041133d --- /dev/null +++ b/test/asm/line-continuation-at-eof.asm @@ -0,0 +1 @@ +assert 1 + 1 == 2 \ \ No newline at end of file diff --git a/test/asm/line-continuation-at-eof.err b/test/asm/line-continuation-at-eof.err new file mode 100644 index 00000000..6308d129 --- /dev/null +++ b/test/asm/line-continuation-at-eof.err @@ -0,0 +1,3 @@ +error: line-continuation-at-eof.asm(1): + Invalid line continuation at end of file +Assembly aborted with 1 error! diff --git a/test/asm/line-continuation.err b/test/asm/line-continuation.err index 6eb2b979..08289d37 100644 --- a/test/asm/line-continuation.err +++ b/test/asm/line-continuation.err @@ -1,5 +1,5 @@ error: line-continuation.asm(3): - Begun line continuation, but encountered character 's' + Invalid character after line continuation 's' warning: line-continuation.asm(6) -> line-continuation.asm::spam(4): [-Wuser] spam error: line-continuation.asm(14): diff --git a/test/asm/macro-arg-0.err b/test/asm/macro-arg-0.err index d546dd9b..6357e801 100644 --- a/test/asm/macro-arg-0.err +++ b/test/asm/macro-arg-0.err @@ -1,5 +1,5 @@ error: macro-arg-0.asm(5) -> macro-arg-0.asm::m(2): - Begun line continuation, but encountered character '0' + Invalid character after line continuation '0' error: macro-arg-0.asm(5) -> macro-arg-0.asm::m(3): Invalid bracketed macro argument '\<0>' Assembly aborted with 2 errors! diff --git a/test/asm/macro-arg-recursion.err b/test/asm/macro-arg-recursion.err index ae7efe51..d9e31e07 100644 --- a/test/asm/macro-arg-recursion.err +++ b/test/asm/macro-arg-recursion.err @@ -1,3 +1,3 @@ error: macro-arg-recursion.asm(6) -> macro-arg-recursion.asm::m(2): - Begun line continuation, but encountered character '2' + Invalid character after line continuation '2' Assembly aborted with 1 error! diff --git a/test/asm/null-outside-string.err b/test/asm/null-outside-string.err index 6b170a41..905a4047 100644 --- a/test/asm/null-outside-string.err +++ b/test/asm/null-outside-string.err @@ -1,17 +1,17 @@ error: null-outside-string.asm(3): - Begun line continuation, but encountered character '0' + Invalid character after line continuation '0' error: null-outside-string.asm(3): syntax error, unexpected number error: null-outside-string.asm(4): - Begun line continuation, but encountered character '0' + Invalid character after line continuation '0' error: null-outside-string.asm(4): syntax error, unexpected number error: null-outside-string.asm(6): - Begun line continuation, but encountered character 'X' + Invalid character after line continuation 'X' error: null-outside-string.asm(6): syntax error, unexpected symbol error: null-outside-string.asm(7): - Begun line continuation, but encountered character 'X' + Invalid character after line continuation 'X' error: null-outside-string.asm(7): syntax error, unexpected symbol Assembly aborted with 8 errors!