authorgravatar for matthew.mcallister.0@gmail.comMatthew McAllister <matthew.mcallister.0@gmail.com> 2019-01-29 16:20:38-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-30 14:02:01-05:00
logad8381e0d2936ffecaa0b54e51e26d6bdb98682e
treeb7a51c0044311876c296f30a2e46762f6a80e0ad
parentecb0cb661a75a130cf6978fa42d464e2d654d8df

Move tokenizer error location to offending char

Previously, it pointed to the start of the current token, but this made it difficult to tell where the error occurred when it was, say, in the middle of a string.

2 files changed, 3 insertions(+), 8 deletions(-)

src/tokenizer.cpp+2-7
...@@ -248,13 +248,8 @@ ATTRIBUTE_PRINTF(2, 3)...@@ -248,13 +248,8 @@ ATTRIBUTE_PRINTF(2, 3)
248static void tokenize_error(Tokenize *t, const char *format, ...) {248static void tokenize_error(Tokenize *t, const char *format, ...) {
249 t->state = TokenizeStateError;249 t->state = TokenizeStateError;
250250
251 if (t->cur_tok) {251 t->out->err_line = t->line;
252 t->out->err_line = t->cur_tok->start_line;252 t->out->err_column = t->column;
253 t->out->err_column = t->cur_tok->start_column;
254 } else {
255 t->out->err_line = t->line;
256 t->out->err_column = t->column;
257 }
258253
259 va_list ap;254 va_list ap;
260 va_start(ap, format);255 va_start(ap, format);
test/compile_errors.zig+1-1
...@@ -2645,7 +2645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2645,7 +2645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2645 \\2645 \\
2646 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }2646 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2647 ,2647 ,
2648 ".tmp_source.zig:1:13: error: newline not allowed in string literal",2648 ".tmp_source.zig:1:15: error: newline not allowed in string literal",
2649 );2649 );
26502650
2651 cases.add(2651 cases.add(