From 3968529cad2baec099acff5fee47b5fe24624b03 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 3 Jul 2016 04:49:09 +0200 Subject: error: improved parser error reporting now it shows a visual indicator '^' pointing to the position of the error, in the line after the error message. should be helpful for users writing templates, if any. --- src/error.c | 4 ++-- src/template-parser.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/error.c b/src/error.c index 586386a..acce506 100644 --- a/src/error.c +++ b/src/error.c @@ -96,8 +96,8 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, rv = blogc_error_new(type, msg); else rv = blogc_error_new_printf(type, - "%s\nError occurred near line %d, position %d: %s", msg, lineno, - pos, line); + "%s\nError occurred near line %d, position %d:\n%s\n%*s", msg, + lineno, pos, line, pos, "^"); free(msg); free(line); diff --git a/src/template-parser.c b/src/template-parser.c index de6eb52..751fd9e 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -622,7 +622,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) if (*err == NULL) { if (state == TEMPLATE_BLOCK_IF_STRING_OPERAND) *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, - start2 - 1, "Found an open double-quoted string."); + start2, "Found an open double-quoted string."); else if (if_count != 0) *err = blogc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER, "%d open 'ifdef' and/or 'ifndef' statements were not closed!", -- cgit v1.2.3-18-g5258