From 2dec96663fccc93da803c0b0bc8287f468144efc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 31 Oct 2015 04:25:43 +0100 Subject: [PATCH] implement the last missing verb 'after' --- src/lib/diff/tree-diff-application.hpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index 564b4419e..6bb1f1808 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -151,6 +151,16 @@ namespace diff{ , LUMIERA_ERROR_DIFF_CONFLICT); } + void + __expect_successful_location (GenNode const& elm) + { + if (endOfData() + and not ( elm.matches(Ref::END) // after(_END_) -> its OK we hit the end + or (elm.matches(Ref::ATTRIBS) and src().children.empty()))) // after(_ATTRIBS_) -> if there are no children, it's OK to hit the end + throw error::State(_Fmt("Unable locate position 'after(%s)'") % elm.idi + , LUMIERA_ERROR_DIFF_CONFLICT); + } + void __expect_valid_parent_scope (GenNode::ID const& idi) { @@ -260,10 +270,23 @@ namespace diff{ /* == Implementation of the tree diff application primitives == */ + /** cue to a position behind the named node, + * thereby picking (accepting) all traversed elements + * into the reshaped new data structure as-is */ void after (GenNode const& n) override { - UNIMPLEMENTED("cue to a position behind the named node"); + // use an appropriate predicate to know when to stop. Default is to stop on ID match + function found = [&](GenNode const& elm) { return elm.matches(n); }; + if (n.matches(Ref::ATTRIBS)) found = [](GenNode const& elm) { return not elm.isNamed();}; + else if (n.matches(Ref::END)) found = [](GenNode const& ) { return false; }; + + while (not endOfData() and not found(*srcPos())) + { + move_into_new_sequence (srcPos()); + ++src(); + } + __expect_successful_location(n); } /** open nested scope to apply diff to child object */