aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-30 00:05:33 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-30 00:05:37 +0100
commitcbe63bd8b26177fcd1b25e9f5b92f69608bd29ce (patch)
treeaf43fccdd6c3b365766929353e5259a4c5f2c87c /src/mds-kbdc
parentmds-kbdc: value statement stuff (diff)
downloadmds-cbe63bd8b26177fcd1b25e9f5b92f69608bd29ce.tar.gz
mds-cbe63bd8b26177fcd1b25e9f5b92f69608bd29ce.tar.bz2
mds-cbe63bd8b26177fcd1b25e9f5b92f69608bd29ce.tar.xz
mds-kbdc: fix nesting inside unordered
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r--src/mds-kbdc/simplify-tree.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c
index a6b4247..b9a5d7a 100644
--- a/src/mds-kbdc/simplify-tree.c
+++ b/src/mds-kbdc/simplify-tree.c
@@ -381,8 +381,8 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree)
mds_kbdc_tree_t** here;
mds_kbdc_tree_t* dup_sequence = NULL;
mds_kbdc_tree_t* temp;
- size_t argument_index = 0;
- int redo = 0, saved_errno;
+ size_t argument_index;
+ int redo = 0, need_reelimination, saved_errno;
/* Check for bad things in the result. */
for (argument = tree->result; argument; argument = argument->next)
@@ -425,24 +425,32 @@ static int simplify_map(mds_kbdc_tree_map_t* restrict tree)
/* Remove ‘.’:s. */
REMOVE_NOTHING(sequence);
- /* Copy sequence. */
- fail_if ((dup_sequence = mds_kbdc_tree_dup(tree->sequence), dup_sequence == NULL));
-
- /* Eliminate alterations, remember, unordered subsequences have
- been simplified to alternations of ordered subsequences. */
- for (argument = dup_sequence; argument; argument = argument->next, argument_index++)
- if (argument->type == C(ALTERNATION))
- fail_if (eliminate_alternation((mds_kbdc_tree_t*)tree, argument, argument_index));
-
- mds_kbdc_tree_free(dup_sequence), dup_sequence = NULL;
-
- /* Eliminated ordered subsequences. */
- for (here = &(tree->sequence); (argument = *here); redo ? (redo = 0) : (here = &(argument->next), 0))
- if (argument->type == C(ORDERED))
- {
- FLATTEN(argument);
- redo = 1;
- }
+ /* Because unordered are simplified to alternations of ordered subsequences, which
+ in turn can contain alternations, possibiled from simplification of nested
+ unordered sequenceses, we need to reeliminated until there are not alternations. */
+ for (need_reelimination = 1; need_reelimination ? (need_reelimination = 0, 1) : 0; redo = 0)
+ {
+ /* Copy sequence. */
+ fail_if ((dup_sequence = mds_kbdc_tree_dup(tree->sequence), dup_sequence == NULL));
+
+ /* Eliminate alterations, remember, unordered subsequences have
+ been simplified to alternations of ordered subsequences. */
+ for (argument_index = 0, argument = dup_sequence; argument; argument = argument->next, argument_index++)
+ if (argument->type == C(ALTERNATION))
+ fail_if (eliminate_alternation((mds_kbdc_tree_t*)tree, argument, argument_index));
+
+ mds_kbdc_tree_free(dup_sequence), dup_sequence = NULL;
+
+ /* Eliminated ordered subsequences. */
+ for (here = &(tree->sequence); (argument = *here); redo ? (redo = 0) : (here = &(argument->next), 0))
+ if (argument->type == C(ORDERED))
+ {
+ FLATTEN(argument);
+ redo = 1;
+ }
+ else if (argument->type == C(ALTERNATION))
+ need_reelimination = 1;
+ }
/* Valid value properties. */
if (tree->result == NULL)