diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-12-09 14:38:18 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-12-09 14:38:18 +0100 |
commit | 99ec00b0eb3d7a1250398821680709c4f44fa530 (patch) | |
tree | 1deeb83975a17bcb59bd2090db0e75caa9ee8965 /src | |
parent | mds-kbdc: compile-layout: watch out for incomplete function calls (diff) | |
download | mds-99ec00b0eb3d7a1250398821680709c4f44fa530.tar.gz mds-99ec00b0eb3d7a1250398821680709c4f44fa530.tar.bz2 mds-99ec00b0eb3d7a1250398821680709c4f44fa530.tar.xz |
mds-kbdc: bug fixes and test cases
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mds-kbdc/compile-layout.c | 26 | ||||
-rw-r--r-- | src/mds-kbdc/make-tree.c | 18 | ||||
-rw-r--r-- | src/mds-kbdc/raw-data.c | 2 |
3 files changed, 28 insertions, 18 deletions
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; |