diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-29 21:18:09 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-29 21:18:14 +0100 |
commit | e912254516bedb2d45fff6aa70432146a45d8381 (patch) | |
tree | b3c7b81a7bdbe6807b59a458a81d6de6aea51aae | |
parent | mds-kbdc: check that there is something after the : (diff) | |
download | mds-e912254516bedb2d45fff6aa70432146a45d8381.tar.gz mds-e912254516bedb2d45fff6aa70432146a45d8381.tar.bz2 mds-e912254516bedb2d45fff6aa70432146a45d8381.tar.xz |
mds-kbdc: only five test cases to go before it's time for the next step
Signed-off-by: Mattias Andrée <maandree@operamail.com>
21 files changed, 425 insertions, 14 deletions
diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c index 52b3151..938795b 100644 --- a/src/mds-kbdc/simplify-tree.c +++ b/src/mds-kbdc/simplify-tree.c @@ -171,7 +171,7 @@ static int eliminate_alternation(mds_kbdc_tree_t* tree, mds_kbdc_tree_t* argumen for (first = last = NULL; alternative; alternative = next_alternative) { /* Duplicate statement. */ - if (new_tree = mds_kbdc_tree_dup((mds_kbdc_tree_t*)tree), new_tree == NULL) + if (new_tree = mds_kbdc_tree_dup(tree), new_tree == NULL) { int saved_errno = errno; argument->alternation.inner = alternative; @@ -184,7 +184,8 @@ static int eliminate_alternation(mds_kbdc_tree_t* tree, mds_kbdc_tree_t* argumen last = new_tree; first = first ? first : new_tree; /* Jump to the alternation. */ - here = &(new_tree->macro_call.arguments); + here = &(new_tree->macro_call.arguments); /* `new_tree->macro_call.arguments` and + * `new_tree->map.sequence` as the same address. */ for (new_argument = *here, i = 0; i < argument_index; i++, here = &((*here)->next)) new_argument = new_argument->next; /* Detach alternative. */ @@ -318,6 +319,40 @@ static int simplify_macro_call(mds_kbdc_tree_macro_call_t* restrict tree) /** + * Check for bad things in a value statement + * + * @param tree The value statement-tree + * @return Zero on success, -1 on error + */ +static int check_value_statement(mds_kbdc_tree_map_t* restrict tree) +{ + again: + /* Check that there is only one value. */ + if (tree->sequence->next) + NEW_ERROR(tree->sequence->next, ERROR, "more the one value in value statement"); + + /* Check for alternation. */ + if ((tree->sequence->type == C(ALTERNATION)) && (tree->processed != PROCESS_LEVEL)) + NEW_ERROR(tree->sequence, WARNING, + "alternated value statement is undefined unless the alternatives are identical"); + + /* Check for unordered. */ + if (tree->sequence->type != C(UNORDERED)) + return 0; + if (tree->processed != PROCESS_LEVEL) + NEW_ERROR(tree->sequence, WARNING, "use of sequence in value statement is discouraged"); + + /* Simplify argument and start over. */ + //fail_if(simplify(tree->sequence)); + //goto again; + return 0; /* TODO */ + + pfail: + return -1; +} + + +/** * Simplify a mapping-subtree * * @param tree The mapping-subtree @@ -337,16 +372,38 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree) if ((argument->type != C(KEYS)) && (argument->type != C(STRING))) NEW_ERROR(argument, ERROR, "not allowed in mapping output"); + /* Valid value properties. */ + if (tree->result == NULL) + fail_if(check_value_statement(tree)); + /* Simplify sequence. */ for (argument = tree->sequence; argument; argument = argument->next) fail_if (simplify(argument)); + /* Test predicted emptyness. */ + for (argument = tree->sequence; argument; argument = argument->next) + if (argument->type != C(NOTHING)) + goto will_not_be_empty; + if (tree->sequence->processed != PROCESS_LEVEL) + NEW_ERROR(tree->sequence, ERROR, "mapping of null sequence"); + /* The tree parsing process will not allow a mapping statement + * to start with a ‘.’. Thus if we select to highlight it we + * know that it is either an empty alternation, an empty + * unordered subsequence or a nothing inside an alternation. + * If it is already been processed by the simplifier, it is an + * error because it is an empty alternation or empty unordered + * subsequence, and there is not reason to print an additional + * error. If however it is a nothing inside an alternation we + * know that it is the cause of the error, however possibily + * in conjunction with additional such constructs, but those + * are harder to locate. */ + return 0; + will_not_be_empty: + /* Remove ‘.’:s. */ REMOVE_NOTHING(sequence); /* Copy sequence. */ - if (tree->sequence == NULL) - return 0; fail_if ((dup_sequence = mds_kbdc_tree_dup(tree->sequence), dup_sequence == NULL)); /* Eliminate alterations, remember, unordered subsequences have @@ -588,11 +645,12 @@ static int simplify_unordered(mds_kbdc_tree_unordered_t* restrict tree) mds_kbdc_tree_t** here; int allow_long = 0; size_t argument_count; - int argv_force = 1; /* TODO globals.h */ + int argv_force = 0; /* TODO globals.h */ /* Test for ‘(( ))’. */ if (tree->inner && (tree->inner->next == NULL) && (tree->inner->type == C(UNORDERED))) { + tree->loc_end = tree->inner->loc_end; temp = tree->inner; tree->inner = tree->inner->unordered.inner; temp->unordered.inner = NULL; @@ -622,7 +680,16 @@ static int simplify_unordered(mds_kbdc_tree_unordered_t* restrict tree) /* Remove ‘.’:s. */ REMOVE_NOTHING(inner); - /* Simplify. */ + /* Check that the sequnced contained anything else. */ + if (tree->inner == NULL) + { + NEW_ERROR(tree, ERROR, "unordered subsequence contained nothing else than ‘.’"); + tree->type = C(NOTHING); + tree->processed = PROCESS_LEVEL; + return 0; + } + + /* Simplify. */ /* TODO test */ for (argument = tree->inner, argument_count = 0; argument; argument = argument->next, argument_count++) if (argument->type == C(ALTERNATION)) { @@ -640,10 +707,11 @@ static int simplify_unordered(mds_kbdc_tree_unordered_t* restrict tree) if ((argument_count > 5) && (allow_long * argv_force == 0)) { if (allow_long == 0) - NEW_ERROR(argument, ERROR, "unordered subsequence longer than 5 elements need double brackets"); + NEW_ERROR(tree->inner, ERROR, + "unordered subsequence longer than 5 elements need double brackets"); else if (argv_force == 0) - NEW_ERROR(argument, ERROR, "unordered subsequence of size %zu found, requires ‘--force’ to compile", - argument_count); + NEW_ERROR(tree->inner, ERROR, + "unordered subsequence of size %zu found, requires ‘--force’ to compile", argument_count); return 0; } diff --git a/src/mds-kbdc/tree.h b/src/mds-kbdc/tree.h index 8354744..6fd5bca 100644 --- a/src/mds-kbdc/tree.h +++ b/src/mds-kbdc/tree.h @@ -500,6 +500,11 @@ typedef struct mds_kbdc_tree_map */ mds_kbdc_tree_t* result; + /* + * These are ordered so that `mds_kbdc_tree_t.macro_call.arguments` + * and `mds_kbdc_tree_t.map.sequence` have the same address. + */ + MDS_KBDC_TREE_PADDING(2); } mds_kbdc_tree_map_t; @@ -598,17 +603,22 @@ typedef struct mds_kbdc_tree_macro_call MDS_KBDC_TREE_COMMON; /** - * The name of the macro - */ - char* name; - - /** * The first input argument for the * macro call, the second is accessed * using `.arguments.next` */ mds_kbdc_tree_t* arguments; + /** + * The name of the macro + */ + char* name; + + /* + * These are ordered so that `mds_kbdc_tree_t.macro_call.arguments` + * and `mds_kbdc_tree_t.map.sequence` have the same address. + */ + MDS_KBDC_TREE_PADDING(2); } mds_kbdc_tree_macro_call_t; diff --git a/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement b/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement new file mode 100644 index 0000000..fae3bc1 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/alternated_value_statement @@ -0,0 +1,18 @@ +[1 2] + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result nil) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 3-4) ‘2’) +# ) +# (.result nil) +# ) +# :1:0–1: warning: alternated value statement is undefined unless the alternatives are identical +# [1 2] +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/double_value b/test-files/mds-kbdc/simplify-tree/invalid/double_value new file mode 100644 index 0000000..d9d4969 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/double_value @@ -0,0 +1,13 @@ +"a" "b" + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 0-3) ‘"a"’) +# (string (@ 1 4-7) ‘"b"’) +# ) +# (.result nil) +# ) +# :1:4–7: error: more the one value in value statement +# "a" "b" +# ^^^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/empty_unordered b/test-files/mds-kbdc/simplify-tree/invalid/empty_unordered new file mode 100644 index 0000000..c81b1d1 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/empty_unordered @@ -0,0 +1,12 @@ +() : "a" + +# (map (@ 1 0-0) +# (.sequence nil) +# (.result +# (string (@ 1 5-8) ‘"a"’) +# ) +# ) +# :1:0–1: error: empty unordered subsequence +# () : "a" +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/long_double_unordered b/test-files/mds-kbdc/simplify-tree/invalid/long_double_unordered new file mode 100644 index 0000000..2a2e673 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/long_double_unordered @@ -0,0 +1,25 @@ +# Note this should pass if complied with --force + +( ( 1 2 3 4 5 6 ) ) : 0 + +# (map (@ 3 0-0) +# (.sequence +# (unordered (@ 3 0-3) +# (.inner +# (string (@ 3 4-5) ‘1’) +# (string (@ 3 6-7) ‘2’) +# (string (@ 3 8-9) ‘3’) +# (string (@ 3 10-11) ‘4’) +# (string (@ 3 12-13) ‘5’) +# (string (@ 3 14-15) ‘6’) +# ) +# ) +# ) +# (.result +# (string (@ 3 22-23) ‘0’) +# ) +# ) +# :3:4–5: error: unordered subsequence of size 6 found, requires ‘--force’ to compile +# ( ( 1 2 3 4 5 6 ) ) : 0 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/long_single_unordered b/test-files/mds-kbdc/simplify-tree/invalid/long_single_unordered new file mode 100644 index 0000000..38751e5 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/long_single_unordered @@ -0,0 +1,23 @@ +(1 2 3 4 5 6) : 0 + +# (map (@ 1 0-0) +# (.sequence +# (unordered (@ 1 0-1) +# (.inner +# (string (@ 1 1-2) ‘1’) +# (string (@ 1 3-4) ‘2’) +# (string (@ 1 5-6) ‘3’) +# (string (@ 1 7-8) ‘4’) +# (string (@ 1 9-10) ‘5’) +# (string (@ 1 11-12) ‘6’) +# ) +# ) +# ) +# (.result +# (string (@ 1 16-17) ‘0’) +# ) +# ) +# :1:1–2: error: unordered subsequence longer than 5 elements need double brackets +# (1 2 3 4 5 6) : 0 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_alternation b/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_alternation new file mode 100644 index 0000000..6838035 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_alternation @@ -0,0 +1,28 @@ +[1 .] . . : 2 + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result +# (string (@ 1 12-13) ‘2’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (nothing (@ 1 3-4)) +# ) +# (.result +# (string (@ 1 12-13) ‘2’) +# ) +# ) +# :1:6–7: warning: ‘.’ outside alternation has no effect +# [1 .] . . : 2 +# ^ +# :1:8–9: warning: ‘.’ outside alternation has no effect +# [1 .] . . : 2 +# ^ +# :1:3–4: error: mapping of null sequence +# [1 .] . . : 2 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_emptyness b/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_emptyness new file mode 100644 index 0000000..22f6824 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/map_from_nothingness_by_emptyness @@ -0,0 +1,26 @@ +() : 1 +[] : 2 + +# (map (@ 1 0-0) +# (.sequence +# (nothing (@ 1 0-1)) +# ) +# (.result +# (string (@ 1 5-6) ‘1’) +# ) +# ) +# (map (@ 2 0-0) +# (.sequence +# (nothing (@ 2 0-1)) +# ) +# (.result +# (string (@ 2 5-6) ‘2’) +# ) +# ) +# :1:0–1: error: empty unordered subsequence +# () : 1 +# ^ +# :2:0–1: error: empty alternation +# [] : 2 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/nothing_but_nothing_in_unordered b/test-files/mds-kbdc/simplify-tree/invalid/nothing_but_nothing_in_unordered new file mode 100644 index 0000000..d7bfbf3 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/nothing_but_nothing_in_unordered @@ -0,0 +1,18 @@ +(. .) : 1 + +# (map (@ 1 0-0) +# (.sequence nil) +# (.result +# (string (@ 1 8-9) ‘1’) +# ) +# ) +# :1:1–2: warning: ‘.’ outside alternation has no effect +# (. .) : 1 +# ^ +# :1:3–4: warning: ‘.’ outside alternation has no effect +# (. .) : 1 +# ^ +# :1:0–1: error: unordered subsequence contained nothing else than ‘.’ +# (. .) : 1 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value b/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value new file mode 100644 index 0000000..3a253d7 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value @@ -0,0 +1,4 @@ +(1 2) + +# TODO + diff --git a/test-files/mds-kbdc/simplify-tree/valid/alternated_map b/test-files/mds-kbdc/simplify-tree/valid/alternated_map new file mode 100644 index 0000000..2668805 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/alternated_map @@ -0,0 +1,35 @@ +[1 2 3 <key>] : "result" + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result +# (string (@ 1 16-24) ‘"result"’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 3-4) ‘2’) +# ) +# (.result +# (string (@ 1 16-24) ‘"result"’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 5-6) ‘3’) +# ) +# (.result +# (string (@ 1 16-24) ‘"result"’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (keys (@ 1 7-12) ‘<key>’) +# ) +# (.result +# (string (@ 1 16-24) ‘"result"’) +# ) +# ) + diff --git a/test-files/mds-kbdc/simplify-tree/valid/alternation_inside_unordered b/test-files/mds-kbdc/simplify-tree/valid/alternation_inside_unordered new file mode 100644 index 0000000..da3d3d2 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/alternation_inside_unordered @@ -0,0 +1,4 @@ +(1 [2 3]) : 0 + +# TODO + diff --git a/test-files/mds-kbdc/simplify-tree/valid/map_with_nested_alternation b/test-files/mds-kbdc/simplify-tree/valid/map_with_nested_alternation new file mode 100644 index 0000000..434c068 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/map_with_nested_alternation @@ -0,0 +1,30 @@ +[1 [2 3]] : 4 + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 4-5) ‘2’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 6-7) ‘3’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) +# :1:3–4: warning: alternation inside alternation is unnessary +# [1 [2 3]] : 4 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/valid/map_with_nothing_in_alternation b/test-files/mds-kbdc/simplify-tree/valid/map_with_nothing_in_alternation new file mode 100644 index 0000000..498de9e --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/map_with_nothing_in_alternation @@ -0,0 +1,29 @@ +[1 2 .] 3 : 4 + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# (string (@ 1 8-9) ‘3’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 3-4) ‘2’) +# (string (@ 1 8-9) ‘3’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 8-9) ‘3’) +# ) +# (.result +# (string (@ 1 12-13) ‘4’) +# ) +# ) + diff --git a/test-files/mds-kbdc/simplify-tree/valid/mapping_with_unordered_singleton b/test-files/mds-kbdc/simplify-tree/valid/mapping_with_unordered_singleton new file mode 100644 index 0000000..cfe630d --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/mapping_with_unordered_singleton @@ -0,0 +1,14 @@ +(1) : 2 + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 1-2) ‘1’) +# ) +# (.result +# (string (@ 1 6-7) ‘2’) +# ) +# ) +# :1:0–1: warning: singleton unordered subsequence +# (1) : 2 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/valid/nothing_in_map b/test-files/mds-kbdc/simplify-tree/valid/nothing_in_map new file mode 100644 index 0000000..25d433d --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/nothing_in_map @@ -0,0 +1,18 @@ +1 . . 2 : 3 + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 0-1) ‘1’) +# (string (@ 1 6-7) ‘2’) +# ) +# (.result +# (string (@ 1 10-11) ‘3’) +# ) +# ) +# nothing_in_map:1:2–3: warning: ‘.’ outside alternation has no effect +# 1 . . 2 : 3 +# ^ +# nothing_in_map:1:4–5: warning: ‘.’ outside alternation has no effect +# 1 . . 2 : 3 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/valid/nothing_in_unordered b/test-files/mds-kbdc/simplify-tree/valid/nothing_in_unordered new file mode 100644 index 0000000..b75c71a --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/nothing_in_unordered @@ -0,0 +1,24 @@ +(. . . 1) : 2 + +# (map (@ 1 0-0) +# (.sequence +# (unordered (@ 1 0-1) +# (.inner +# (string (@ 1 7-8) ‘1’) +# ) +# ) +# ) +# (.result +# (string (@ 1 12-13) ‘2’) +# ) +# ) +# :1:1–2: warning: ‘.’ outside alternation has no effect +# (. . . 1) : 2 +# ^ +# :1:3–4: warning: ‘.’ outside alternation has no effect +# (. . . 1) : 2 +# ^ +# :1:5–6: warning: ‘.’ outside alternation has no effect +# (. . . 1) : 2 +# ^ + diff --git a/test-files/mds-kbdc/simplify-tree/valid/unorderd_inside_alternation b/test-files/mds-kbdc/simplify-tree/valid/unorderd_inside_alternation new file mode 100644 index 0000000..ac52b62 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/unorderd_inside_alternation @@ -0,0 +1,4 @@ +[1 (2 3)] : 0 + +# TODO + diff --git a/test-files/mds-kbdc/simplify-tree/valid/unordered_inside_unordered b/test-files/mds-kbdc/simplify-tree/valid/unordered_inside_unordered new file mode 100644 index 0000000..ce999a2 --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/unordered_inside_unordered @@ -0,0 +1,4 @@ +(1 2 (3 4)) : 0 + +# TODO + diff --git a/test-files/mds-kbdc/simplify-tree/valid/unordered_sequence b/test-files/mds-kbdc/simplify-tree/valid/unordered_sequence new file mode 100644 index 0000000..a7cb1bf --- /dev/null +++ b/test-files/mds-kbdc/simplify-tree/valid/unordered_sequence @@ -0,0 +1,4 @@ +(1 2 3) : 0 + +# TODO + |