From 99ec00b0eb3d7a1250398821680709c4f44fa530 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 9 Dec 2014 14:38:18 +0100 Subject: mds-kbdc: bug fixes and test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/compile-layout.c | 26 +++++++-------- src/mds-kbdc/make-tree.c | 18 ++++++++--- src/mds-kbdc/raw-data.c | 2 +- .../compile-layout/invalid/invalid_strings | 2 -- .../compile-layout/invalid/invalid_use_of_array | 3 ++ .../compile-layout/invalid/nonsingleton_bounds | 6 ++++ .../compile-layout/invalid/undefined_variable | 2 ++ .../mds-kbdc/make-tree/invalid/invalid_arrays | 37 ++++++++++++++++++++++ 8 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 test-files/mds-kbdc/compile-layout/invalid/invalid_use_of_array create mode 100644 test-files/mds-kbdc/compile-layout/invalid/nonsingleton_bounds create mode 100644 test-files/mds-kbdc/compile-layout/invalid/undefined_variable create mode 100644 test-files/mds-kbdc/make-tree/invalid/invalid_arrays diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c index 1d05d83..fbf7119 100644 --- a/src/mds-kbdc/compile-layout.c +++ b/src/mds-kbdc/compile-layout.c @@ -700,11 +700,11 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri { /* Variable dereference. */ if (value = variables_get((size_t)numbuf), value == NULL) - RETURN_ERROR(tree, ERROR, "variable ‘%.*s’ is not defined", VARIABLE);/* TODO test */ + RETURN_ERROR(tree, ERROR, "variable ‘%.*s’ is not defined", VARIABLE); if (value->type == C(ARRAY)) - RETURN_ERROR(tree, ERROR, "variable ‘%.*s’ is an array", VARIABLE);/* TODO test */ + RETURN_ERROR(tree, ERROR, "variable ‘%.*s’ is an array", VARIABLE); if (value->type != C(COMPILED_STRING)) - NEW_ERROR(tree, INTERNAL_ERROR, "variable ‘%.*s’ is of impossible type", VARIABLE);/* TODO test */ + NEW_ERROR(tree, INTERNAL_ERROR, "variable ‘%.*s’ is of impossible type", VARIABLE); fail_if (rc = string_dup(value->compiled_string.string), rc == NULL); } else @@ -1621,14 +1621,14 @@ static int compile_have_range(mds_kbdc_tree_assumption_have_range_t* restrict tr /* Check that the primary bound is single-character. */ if ((first[0] == -1) || (first[1] != -1)) { - NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");/* TODO test */ + NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string"); error->start = lineoff_first, lineoff_first = 0; error->end = error->start + strlen(tree->first); } /* Check that the secondary bound is single-character. */ if ((last[0] == -1) || (last[1] != -1)) { - NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");/* TODO test */ + NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string"); error->start = lineoff_last, lineoff_last = 0; error->end = error->start + strlen(tree->last); } @@ -2080,14 +2080,14 @@ static int compile_for(mds_kbdc_tree_for_t* restrict tree) /* Check that the primary bound is single-character. */ if ((first[0] == -1) || (first[1] != -1)) { - NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");/* TODO test */ + NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string"); error->start = lineoff_first, lineoff_first = 0; error->end = error->start + strlen(tree->first); } /* Check that the secondary bound is single-character. */ if ((last[0] == -1) || (last[1] != -1)) { - NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string");/* TODO test */ + NEW_ERROR(tree, ERROR, "iteration boundary must be a single character string"); error->start = lineoff_last, lineoff_last = 0; error->end = error->start + strlen(tree->last); } @@ -2253,7 +2253,7 @@ static int evaluate_element(mds_kbdc_tree_t* restrict node) */ static int compile_keys(mds_kbdc_tree_keys_t* restrict tree) { - fail_if (evaluate_element((mds_kbdc_tree_t*)tree)); + fail_if (evaluate_element((mds_kbdc_tree_t*)tree) < 0); return 0; fail: return -1; @@ -2268,7 +2268,7 @@ static int compile_keys(mds_kbdc_tree_keys_t* restrict tree) */ static int compile_string(mds_kbdc_tree_string_t* restrict tree) { - fail_if (evaluate_element((mds_kbdc_tree_t*)tree)); + fail_if (evaluate_element((mds_kbdc_tree_t*)tree) < 0); return 0; fail: return -1; @@ -2549,10 +2549,10 @@ static int compile_subtree(mds_kbdc_tree_t* restrict tree) case C(ASSUMPTION_HAVE_RANGE): c (have_range); break; case C(FOR): c_ (for); break; case C(IF): c_ (if); break; - case C(LET): c (let); break;/* TODO test */ - case C(KEYS): c (keys); break;/* TODO test */ - case C(STRING): c (string); break;/* TODO test */ - case C(ARRAY): c (array); break;/* TODO test */ + case C(LET): c (let); break; + case C(KEYS): c (keys); break; + case C(STRING): c (string); break; + case C(ARRAY): c (array); break; case C(MAP): c (map); break; case C(MACRO_CALL): c (macro_call); break;/* TODO test */ case C(RETURN): break_level = 3; break;/* TODO test */ diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index 77155b2..7534a40 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -1311,14 +1311,18 @@ static int parse_array_elements(void) end = line + strlen(line); END; line = end, prev_end_char = '\0'; - in_array = 0; - stack_ptr -= 2; - NEXT; - return 0; + goto done; } else { NEW_NODE(string, STRING); + if (strchr("[]()<>{}", *line)) + { + mds_kbdc_tree_free((mds_kbdc_tree_t*)node); + NEW_ERROR(1, ERROR, "x-stray ‘%c’", *line); + error->end = error->start + 1; + goto done; + } NO_JUMP; CHARS(string); LEAF; @@ -1330,6 +1334,12 @@ static int parse_array_elements(void) fail: return -1; + + done: + in_array = 0; + stack_ptr -= 2; + NEXT; + return 0; } diff --git a/src/mds-kbdc/raw-data.c b/src/mds-kbdc/raw-data.c index 83e8b48..52bec82 100644 --- a/src/mds-kbdc/raw-data.c +++ b/src/mds-kbdc/raw-data.c @@ -264,7 +264,7 @@ static size_t remove_comments(char* restrict content, size_t size) else if (quote) { t; - if (c == '"') quote = 0; + if (strchr("\"\n", c)) quote = 0; } /* # is the comment symbol. */ else if (c == '#') comment = 1; diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_strings b/test-files/mds-kbdc/compile-layout/invalid/invalid_strings index 93b58e1..676d86e 100644 --- a/test-files/mds-kbdc/compile-layout/invalid/invalid_strings +++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_strings @@ -4,8 +4,6 @@ "hello"_ \0.0 " -" -\ \ \\ diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_use_of_array b/test-files/mds-kbdc/compile-layout/invalid/invalid_use_of_array new file mode 100644 index 0000000..b5f8e32 --- /dev/null +++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_use_of_array @@ -0,0 +1,3 @@ +let \1 : {} + : "\1" + diff --git a/test-files/mds-kbdc/compile-layout/invalid/nonsingleton_bounds b/test-files/mds-kbdc/compile-layout/invalid/nonsingleton_bounds new file mode 100644 index 0000000..541c5d0 --- /dev/null +++ b/test-files/mds-kbdc/compile-layout/invalid/nonsingleton_bounds @@ -0,0 +1,6 @@ +for "" to "hello" as \1 +end for +assumption + have_range "" "hello" +end assumption + diff --git a/test-files/mds-kbdc/compile-layout/invalid/undefined_variable b/test-files/mds-kbdc/compile-layout/invalid/undefined_variable new file mode 100644 index 0000000..65f3457 --- /dev/null +++ b/test-files/mds-kbdc/compile-layout/invalid/undefined_variable @@ -0,0 +1,2 @@ +"\1" : "" + diff --git a/test-files/mds-kbdc/make-tree/invalid/invalid_arrays b/test-files/mds-kbdc/make-tree/invalid/invalid_arrays new file mode 100644 index 0000000..2ae4cdf --- /dev/null +++ b/test-files/mds-kbdc/make-tree/invalid/invalid_arrays @@ -0,0 +1,37 @@ +let \1 : {{}}} +let \1 : {)} +let \1 : {>} + +# (let (@ 1 0-3) ‘\1’ +# (.value +# (array (@ 1 9-10) +# (.elements +# (string (@ 1 10-11) ‘{’) +# ) +# ) +# ) +# ) +# (let (@ 2 0-3) ‘\1’ +# (.value +# (array (@ 2 9-10) +# (.elements nil) +# ) +# ) +# ) +# (let (@ 3 0-3) ‘\1’ +# (.value +# (array (@ 3 9-10) +# (.elements nil) +# ) +# ) +# ) +# :1:12–14: error: too many parameters +# let \1 : {{}}} +# ^^ +# :2:10–11: error: x-stray ‘)’ +# let \1 : {)} +# ^ +# :3:10–11: error: x-stray ‘>’ +# let \1 : {>} +# ^ + -- cgit v1.2.3-70-g09d2