aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-29 23:36:36 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-29 23:36:36 +0100
commit40443932e23874cbd929ce50188d50fa1041a5e8 (patch)
tree3e39bdf606ca10946c0a6dd39d5c87d2cc1bb2a8
parentmds-kbdc: fix permutation generation (diff)
downloadmds-40443932e23874cbd929ce50188d50fa1041a5e8.tar.gz
mds-40443932e23874cbd929ce50188d50fa1041a5e8.tar.bz2
mds-40443932e23874cbd929ce50188d50fa1041a5e8.tar.xz
mds-kbdc: value statement stuff
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/mds-kbdc/simplify-tree.c43
-rw-r--r--test-files/mds-kbdc/simplify-tree/invalid/bad_value12
-rw-r--r--test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value28
3 files changed, 73 insertions, 10 deletions
diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c
index 67c2b03..a6b4247 100644
--- a/src/mds-kbdc/simplify-tree.c
+++ b/src/mds-kbdc/simplify-tree.c
@@ -319,18 +319,14 @@ static int simplify_macro_call(mds_kbdc_tree_macro_call_t* restrict tree)
/**
- * Check for bad things in a value statement
+ * Check for bad things in a value statement for before the simplification process
*
* @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)
+static int check_value_statement_before_simplification(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,
@@ -352,6 +348,28 @@ static int check_value_statement(mds_kbdc_tree_map_t* restrict tree)
/**
+ * Check for bad things in a value statement for after the simplification process
+ *
+ * @param tree The value statement-tree
+ * @return Zero on success, -1 on error
+ */
+static int check_value_statement_after_simplification(mds_kbdc_tree_map_t* restrict tree)
+{
+ /* 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 the type of the value */
+ if (tree->sequence->type != C(STRING))
+ NEW_ERROR(tree->sequence, ERROR, "bad value type");
+
+ return 0;
+ pfail:
+ return -1;
+}
+
+
+/**
* Simplify a mapping-subtree
*
* @param tree The mapping-subtree
@@ -373,7 +391,7 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree)
/* Valid value properties. */
if (tree->result == NULL)
- fail_if(check_value_statement(tree));
+ fail_if(check_value_statement_before_simplification(tree));
/* Simplify sequence. */
for (argument = tree->sequence; argument; argument = argument->next)
@@ -384,7 +402,12 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree)
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");
+ {
+ if (tree->result)
+ NEW_ERROR(tree->sequence, ERROR, "mapping of null sequence");
+ else
+ NEW_ERROR(tree->sequence, ERROR, "nothing in value statement");
+ }
/* 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
@@ -421,6 +444,10 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree)
redo = 1;
}
+ /* Valid value properties. */
+ if (tree->result == NULL)
+ fail_if(check_value_statement_after_simplification(tree));
+
/* Mapping statements are simplified in a manner similar
* to how macro calls are simplified. However mapping
* statements can also contain unordered subsequences,
diff --git a/test-files/mds-kbdc/simplify-tree/invalid/bad_value b/test-files/mds-kbdc/simplify-tree/invalid/bad_value
new file mode 100644
index 0000000..cdd8b54
--- /dev/null
+++ b/test-files/mds-kbdc/simplify-tree/invalid/bad_value
@@ -0,0 +1,12 @@
+<key>
+
+# (map (@ 1 0-0)
+# (.sequence
+# (keys (@ 1 0-5) ‘<key>’)
+# )
+# (.result nil)
+# )
+# :1:0–5: error: bad value type
+# <key>
+# ^^^^^
+
diff --git a/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value b/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value
index 3a253d7..b26b2ef 100644
--- a/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value
+++ b/test-files/mds-kbdc/simplify-tree/invalid/unordered_double_value
@@ -1,4 +1,28 @@
(1 2)
-# TODO
-
+# (map (@ 1 0-0)
+# (.sequence
+# (string (@ 1 1-2) ‘1’)
+# (string (@ 1 3-4) ‘2’)
+# )
+# (.result nil)
+# )
+# (map (@ 1 0-0)
+# (.sequence
+# (string (@ 1 3-4) ‘2’)
+# (string (@ 1 1-2) ‘1’)
+# )
+# (.result nil)
+# )
+# :1:0–1: warning: use of sequence in value statement is discouraged
+# (1 2)
+# ^
+# :1:0–1: warning: alternated value statement is undefined unless the alternatives are identical
+# (1 2)
+# ^
+# :1:3–4: error: more the one value in value statement
+# (1 2)
+# ^
+# :1:1–2: error: more the one value in value statement
+# (1 2)
+# ^