From daa13ab6dc7f7457e7353902f2b58a7d2bdb6f12 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 1 Nov 2015 02:33:35 +0100 Subject: [PATCH] implement anonymous pick or delete of children ...while I must admit that I'm a bit doubtful about that language feature, but it does come in handy when manually writing diff messages. The reason is the automatic naming of child objects, which makes it often hard to refer to a child after the fact, since the name can not be reconstructed systematically. Obviously the downside of this "anonymous pick / delete" is that we allow to pick (accept) or even delete just any child, which happens to sit there, without being able to detect a synchronisation mismatch between sender and receiver. --- src/lib/diff/tree-diff-application.hpp | 4 ++++ tests/library/diff/diff-tree-application-test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index 836de4aca..5ab996f4b 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -129,6 +129,10 @@ namespace diff{ throw error::State(_Fmt("Unable to %s element %s from target as demanded; " "no (further) elements in target sequence") % oper % elm , LUMIERA_ERROR_DIFF_CONFLICT); + + if (elm.matches(Ref::CHILD) and not srcPos()->isNamed()) + return; // allow for anonymous pick or delete of children + if (not srcPos()->matches(elm)) throw error::State(_Fmt("Unable to %s element %s from target as demanded; " "found element %s on current target position instead") diff --git a/tests/library/diff/diff-tree-application-test.cpp b/tests/library/diff/diff-tree-application-test.cpp index 964a46b72..0c1508d6c 100644 --- a/tests/library/diff/diff-tree-application-test.cpp +++ b/tests/library/diff/diff-tree-application-test.cpp @@ -107,12 +107,12 @@ namespace test{ DiffSeq mutationDiff() { - return snapshot({after(Ref::ATTRIBS) + return snapshot({after(Ref::ATTRIBS) // fast forward to the first child , find(CHILD_T) , pick(CHILD_A) , skip(CHILD_T) , del(CHILD_T) - , pick(Ref::CHILD) + , pick(Ref::CHILD) // pick a child anonymously , mut(Ref::THIS) , ins(ATTRIB3) , ins(ATTRIB_NODE)