diff options
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/make-tree.c | 16 | ||||
-rw-r--r-- | src/mds-kbdc/parse-error.c | 13 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index b34b358..2169342 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -90,7 +90,8 @@ error->start = (size_t)(line - source_code.lines[line_i]); \ error->end = (size_t)(end - source_code.lines[line_i]); \ fail_if ((error->pathname = strdup(pathname)) == NULL); \ - fail_if ((error->code = strdup(source_code.real_lines[line_i])) == NULL); \ + if (ERROR_IS_IN_FILE) \ + fail_if ((error->code = strdup(source_code.real_lines[line_i])) == NULL); \ fail_if (xasprintf(error->description, __VA_ARGS__)) @@ -706,7 +707,18 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu *end = prev_end_char; } - /* TODO check that the stack is empty */ + /* Check that all scopes have been popped. */ + if (stack_ptr) + { + char* line = NULL; + char* end = NULL; + NEW_ERROR(0, ERROR, "premature end of file"); + while (stack_ptr--) + { + NEW_ERROR(0, NOTE, "missing ‘end %s’", keyword_stack[stack_ptr]); + /* TODO from where? */ + } + } free(pathname); free(keyword_stack); diff --git a/src/mds-kbdc/parse-error.c b/src/mds-kbdc/parse-error.c index c16b9f4..1ad5ae1 100644 --- a/src/mds-kbdc/parse-error.c +++ b/src/mds-kbdc/parse-error.c @@ -93,10 +93,15 @@ void mds_kbdc_parse_error_print(const mds_kbdc_parse_error_t* restrict this, FIL abort(); break; } - fprintf(output, "%s\n %s\n \033[01;32m", desc, code); - i = 0; - for (n = start; i < n; i++) fputc(' ', output); - for (n = end; i < n; i++) fputc('^', output); + if (this->error_is_in_file) + { + fprintf(output, "%s\n %s\n \033[01;32m", desc, code); + i = 0; + for (n = start; i < n; i++) fputc(' ', output); + for (n = end; i < n; i++) fputc('^', output); + } + else + fprintf(output, "%s\n", desc); fprintf(output, "\033[00m\n"); } |