aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-13 21:35:18 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-13 21:35:21 +0100
commit2fdbbc75ac46920e075570cea3cb77608aacba4b (patch)
treeeada80c40412ca806df5074295a165aaa2365c07 /src/mds-kbdc
parentparse let statement, however not arrays yet (diff)
downloadmds-2fdbbc75ac46920e075570cea3cb77608aacba4b.tar.gz
mds-2fdbbc75ac46920e075570cea3cb77608aacba4b.tar.bz2
mds-2fdbbc75ac46920e075570cea3cb77608aacba4b.tar.xz
check that the parsing stack is empty when the end of a file has been reached
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r--src/mds-kbdc/make-tree.c16
-rw-r--r--src/mds-kbdc/parse-error.c13
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");
}