From 835c43027d620c6d64d124fc56495eb0432a8f4b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 18 Apr 2016 01:21:38 +0200 Subject: [PATCH] add support for Ref::THIS (questionable, #996) while simple to add into the implementation, this whole feature seems rather qestionable to me now, thus I've added a Ticket to be revisited later. In a nutshell, right here, when implementing the binding layer for STL collections, it is easy to enable the framework to treat Ref::THIS properly, but the *actual implementation* will necessarily be offloaded onto each and every concrete binding implementation. Thus client code would have to add support for an rather obscure shortcut within the Diff language. The only way to avoid this would be to change the semantics of the "match"-lambda: if this binding would rather be a back-translation of implementation data into GenNode::ID values, then we'd be able to implement Ref::THIS natively. But such an approach looks like a way inferiour deisgn to me; having delegated the meaning of a "match" to the client seems like an asset, since it is both natural and opens a lot of flexibility, without adding complexity. For that reason I tend to avoid that shortcut now, in the hope to be able to drop it entirely from the language --- src/lib/diff/gen-node.cpp | 2 +- src/lib/diff/tree-diff.hpp | 2 +- .../diff/tree-mutator-collection-binding.hpp | 4 ++- wiki/thinkPad.ichthyo.mm | 33 ++++++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/lib/diff/gen-node.cpp b/src/lib/diff/gen-node.cpp index ba930a329..f20985686 100644 --- a/src/lib/diff/gen-node.cpp +++ b/src/lib/diff/gen-node.cpp @@ -66,7 +66,7 @@ namespace diff{ const Ref Ref::I ("_I_"); const Ref Ref::NO ("_NO_"); const Ref Ref::END ("_END_"); - const Ref Ref::THIS ("_THIS_"); + const Ref Ref::THIS ("_THIS_"); ////////TICKET #996 : Feature of questionable usefulness. Maybe dispensable? const Ref Ref::CHILD ("_CHILD_"); const Ref Ref::ATTRIBS("_ATTRIBS_"); diff --git a/src/lib/diff/tree-diff.hpp b/src/lib/diff/tree-diff.hpp index 329001661..4c7e8259a 100644 --- a/src/lib/diff/tree-diff.hpp +++ b/src/lib/diff/tree-diff.hpp @@ -121,7 +121,7 @@ namespace diff{ * or \c pick or \c find), it is allowed immediately to open the * nested scope with \c mut(Ref::THIS) -- which circumvents the * problem that it is sometimes difficult to know the precise ID, - * especially when hand-writing a diff to populate a data structure. + * especially when hand-writing a diff to populate a data structure. ////////TICKET #996 : `Ref::THIS` is a questionable feature * - \c emu bracketing construct and counterpart to \c mut(ID). This verb * must be given precisely at the end of the nested scope (it is * not allowed to "return" from the middle of a scope, for sake diff --git a/src/lib/diff/tree-mutator-collection-binding.hpp b/src/lib/diff/tree-mutator-collection-binding.hpp index b7c4f5120..5fd7eaab3 100644 --- a/src/lib/diff/tree-mutator-collection-binding.hpp +++ b/src/lib/diff/tree-mutator-collection-binding.hpp @@ -149,7 +149,9 @@ iterator locate (GenNode const& targetSpec) { - if (not collection.empty() and matches (targetSpec, collection.back())) + if (not collection.empty() + and (Ref::THIS.matches(targetSpec.idi) + or matches (targetSpec, collection.back()))) return lastElm(); else return search (targetSpec, eachElm(collection)); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index cb2a8ed8d..a000357c7 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -2732,8 +2732,7 @@ daß der Client hier eigentlich ein Protokoll implementieren muß.

- - + @@ -3390,7 +3389,7 @@ - + @@ -4612,6 +4611,10 @@ + + + + @@ -5419,7 +5422,29 @@ - + + + + + + + + + + + + + + + + + + + + + + +