From 4b84a6e2f62e8430106f75bf2bc5d8ee0061a662 Mon Sep 17 00:00:00 2001 From: liviubobocu Date: Mon, 10 Mar 2025 15:17:49 +0200 Subject: [PATCH] Include column number in parser and compiler error messages (#3257) Resolves #1027, resolves #2334, and resolves #3256. --- src/locfile.c | 5 +++-- tests/jq.test | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/locfile.c b/src/locfile.c index 2a4f18e3..a1189e14 100644 --- a/src/locfile.c +++ b/src/locfile.c @@ -82,8 +82,9 @@ void locfile_locate(struct locfile* l, location loc, const char* fmt, ...) { jv_free(m1); return; } - jv m2 = jv_string_fmt("%s at %s, line %d:\n%.*s%*s", jv_string_value(m1), - jv_string_value(l->fname), startline + 1, + jv m2 = jv_string_fmt("%s at %s, line %d, column %d:\n%.*s%*s", + jv_string_value(m1), jv_string_value(l->fname), + startline + 1, loc.start - offset + 1, locfile_line_length(l, startline), l->data + offset, loc.start - offset, ""); jv_free(m1); diff --git a/tests/jq.test b/tests/jq.test index 245652bb..e25558d2 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -117,11 +117,11 @@ null %%FAIL {(0):1} -jq: error: Cannot use number (0) as object key at , line 1: +jq: error: Cannot use number (0) as object key at , line 1, column 2: %%FAIL {non_const:., (0):1} -jq: error: Cannot use number (0) as object key at , line 1: +jq: error: Cannot use number (0) as object key at , line 1, column 15: # # Field access, piping @@ -300,7 +300,7 @@ null %%FAIL . as $foo | break $foo -jq: error: $*label-foo is not defined at , line 1: +jq: error: $*label-foo is not defined at , line 1, column 13: [.[]|[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]] [1,2,3,4,5] @@ -506,11 +506,11 @@ null %%FAIL IGNORE MSG . as [] | null -jq: error: syntax error, unexpected ']', expecting '$' or '[' or '{' (Unix shell quoting issues?) at , line 1: +jq: error: syntax error, unexpected ']', expecting '$' or '[' or '{' (Unix shell quoting issues?) at , line 1, column 7: %%FAIL IGNORE MSG . as {} | null -jq: error: syntax error, unexpected '}' (Unix shell quoting issues?) at , line 1: +jq: error: syntax error, unexpected '}' (Unix shell quoting issues?) at , line 1, column 7: # [.,(.[] | {x:.},.),.,.[]] @@ -1750,27 +1750,27 @@ null %%FAIL module (.+1); 0 -jq: error: Module metadata must be constant at , line 1: +jq: error: Module metadata must be constant at , line 1, column 1: %%FAIL module []; 0 -jq: error: Module metadata must be an object at , line 1: +jq: error: Module metadata must be an object at , line 1, column 1: %%FAIL include "a" (.+1); 0 -jq: error: Module metadata must be constant at , line 1: +jq: error: Module metadata must be constant at , line 1, column 1: %%FAIL include "a" []; 0 -jq: error: Module metadata must be an object at , line 1: +jq: error: Module metadata must be an object at , line 1, column 1: %%FAIL include "\ "; 0 -jq: error: Invalid escape at line 1, column 4 (while parsing '"\ "') at , line 1: +jq: error: Invalid escape at line 1, column 4 (while parsing '"\ "') at , line 1, column 10: %%FAIL include "\(a)"; 0 -jq: error: Import path must be constant at , line 1: +jq: error: Import path must be constant at , line 1, column 9: modulemeta "c" @@ -1786,11 +1786,11 @@ modulemeta | .defs | length %%FAIL IGNORE MSG import "syntaxerror" as e; . -jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?) at /home/nico/ws/jq/tests/modules/syntaxerror/syntaxerror.jq, line 1: +jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?) at /home/nico/ws/jq/tests/modules/syntaxerror/syntaxerror.jq, line 1, column 8: %%FAIL IGNORE MSG %::wat -jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?) at , line 1: +jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?) at , line 1, column 1: import "test_bind_order" as check; check::check null @@ -1871,7 +1871,7 @@ null %%FAIL IGNORE MSG } -jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at , line 1: +jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at , line 1, column 1: (.[{}] = 0)? null