From 2704b38da69d79256702fc8d221dad364ece5a80 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 9 Oct 2015 03:03:27 +0200 Subject: [PATCH] WIP rework demonstration diff to be valid type-wise so basically it's time to explicate the way our diff language will actually be written. Similar to the list diff case, it's a linear sequence of verb tokens, but in this case, the payload value in each token is a GenNode. This is the very reason why GenNode was conceived as value object with an opaque DataCap payload --- src/lib/diff/gen-node.cpp | 8 +- src/lib/diff/gen-node.hpp | 8 +- src/lib/diff/tree-diff-application.hpp | 2 +- src/lib/diff/tree-diff.hpp | 1 + .../diff/diff-tree-application-test.cpp | 92 +++++++++++-------- wiki/thinkPad.ichthyo.mm | 91 ++++++++++-------- 6 files changed, 117 insertions(+), 85 deletions(-) diff --git a/src/lib/diff/gen-node.cpp b/src/lib/diff/gen-node.cpp index 53baef1b3..876703f37 100644 --- a/src/lib/diff/gen-node.cpp +++ b/src/lib/diff/gen-node.cpp @@ -64,10 +64,10 @@ namespace diff{ * used within the tree diff language * to mark specific scopes */ - Ref Ref::END ("_END_"); - Ref Ref::THIS ("_THIS_"); - Ref Ref::CHILD ("_CHILD_"); - Ref Ref::ATTRIBS("_ATTRIBS_"); + const Ref Ref::END ("_END_"); + const Ref Ref::THIS ("_THIS_"); + const Ref Ref::CHILD ("_CHILD_"); + const Ref Ref::ATTRIBS("_ATTRIBS_"); diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index 8208356e7..35de92db4 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -586,10 +586,10 @@ namespace diff{ , DataCap(RecRef(oNode.data.get()))) { } - static Ref END; ///< symbolic ID ref "_END_" - static Ref THIS; ///< symbolic ID ref "_THIS_" - static Ref CHILD; ///< symbolic ID ref "_CHILD_" - static Ref ATTRIBS; ///< symbolic ID ref "_ATTRIBS_" + static const Ref END; ///< symbolic ID ref "_END_" + static const Ref THIS; ///< symbolic ID ref "_THIS_" + static const Ref CHILD; ///< symbolic ID ref "_CHILD_" + static const Ref ATTRIBS; ///< symbolic ID ref "_ATTRIBS_" }; diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index 578df677e..0ab0ac5eb 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -52,7 +52,7 @@ namespace diff{ */ template<> class DiffApplicationStrategy - : public TreeDiffInterpreter + : public TreeDiffInterpreter { }; diff --git a/src/lib/diff/tree-diff.hpp b/src/lib/diff/tree-diff.hpp index 48c14e5fd..a3c8f1dd0 100644 --- a/src/lib/diff/tree-diff.hpp +++ b/src/lib/diff/tree-diff.hpp @@ -42,6 +42,7 @@ #include "lib/diff/diff-language.hpp" +#include "lib/diff/gen-node.hpp" namespace lib { diff --git a/tests/library/diff/diff-tree-application-test.cpp b/tests/library/diff/diff-tree-application-test.cpp index 5c4f0a0b3..68e95255a 100644 --- a/tests/library/diff/diff-tree-application-test.cpp +++ b/tests/library/diff/diff-tree-application-test.cpp @@ -24,15 +24,17 @@ #include "lib/test/run.hpp" #include "lib/diff/tree-diff-application.hpp" #include "lib/iter-adapter-stl.hpp" +#include "lib/time/timevalue.hpp" #include "lib/util.hpp" #include #include using lib::iter_stl::snapshot; -using util::isnil; +// using util::isnil; using std::string; using std::vector; +using lib::time::Time; namespace lib { @@ -41,6 +43,20 @@ namespace test{ namespace {//Test fixture.... + // define some GenNode elements + // to act as templates within the concrete diff + // NOTE: everything in this diff language is by-value + const GenNode ATTRIB1("α", 1), // attribute α = 1 + ATTRIB2("β", 2L), // attribute α = 2L (int64_t) + ATTRIB3("γ", 3.45), // attribute γ = 3.45 (double) + TYPE_X("type", "X"), // a "magic" type attribute "X" + TYPE_Y("type", "Y"), // + CHILD_A("a"), // unnamed string child node + CHILD_B('b'), // unnamed char child node + CHILD_T(Time(12,34,56,78)), // unnamed time value child + SUB_NODE = MakeRec().genNode(), // empty anonymous node used to open a sub scope + ATTRIB_NODE = MakeRec().genNode("δ"), // empty named node to be attached as attribute δ + CHILD_NODE = Ref(SUB_NODE); // use a Node-Reference as child node (!) using Interpreter = TreeDiffInterpreter; @@ -52,23 +68,25 @@ namespace test{ DiffStep_CTOR(pick); DiffStep_CTOR(find); DiffStep_CTOR(skip); + DiffStep_CTOR(mut); + DiffStep_CTOR(emu); inline DiffSeq populationDiff() { - return snapshot({ins(typeX) - , ins(attrib1) - , ins(attrib2) - , ins(attrib3) - , ins(childA) - , ins(childT) - , ins(childT) - , ins(node) - , mut(THIS) - , ins(childB) - , ins(childA) - , emu(THIS) + return snapshot({ins(TYPE_X) + , ins(ATTRIB1) + , ins(ATTRIB2) + , ins(ATTRIB3) + , ins(CHILD_A) + , ins(CHILD_T) + , ins(CHILD_T) + , ins(SUB_NODE) + , mut(SUB_NODE) + , ins(CHILD_B) + , ins(CHILD_A) + , emu(SUB_NODE) }); } @@ -76,30 +94,30 @@ namespace test{ inline DiffSeq mutationDiff() { - return snapshot({after(ATTRIBS) - , find(childT) - , pick(childA) - , skip(childT) - , del(childT) - , pick(CHILD) - , mut(THIS) - , ins(attrib3) - , ins(node(ID("δ"))) - , find(childA) - , del(childB) - , ins(node(CHILD("ω"))) - , ins(childT) - , skip(childA) - , mut(CHILD("ω")) - , ins(typeY) - , ins(attrib2) - , emu(CHILD("ω")) - , mut(ID("δ")) - , ins(childA) - , ins(childA) - , ins(childA) - , emu(ID("δ")) - , emu(THIS) + return snapshot({after(Ref::ATTRIBS) + , find(CHILD_T) + , pick(CHILD_A) + , skip(CHILD_T) + , del(CHILD_T) + , pick(Ref::CHILD) + , mut(Ref::THIS) + , ins(ATTRIB3) + , ins(ATTRIB_NODE) + , find(CHILD_A) + , del(CHILD_B) + , ins(CHILD_NODE) + , ins(CHILD_T) + , skip(CHILD_A) + , mut(CHILD_NODE) + , ins(TYPE_Y) + , ins(ATTRIB2) + , emu(CHILD_NODE) + , mut(ATTRIB_NODE) + , ins(CHILD_A) + , ins(CHILD_A) + , ins(CHILD_A) + , emu(ATTRIB_NODE) + , emu(Ref::THIS) }); } }//(End)Test fixture diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 3be8af357..958addd9f 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -1090,8 +1090,7 @@ Interpreter definiert Sprache

- - + @@ -1107,8 +1106,7 @@ ROOT

- - + @@ -1124,8 +1122,7 @@ INIT

- - + @@ -1140,8 +1137,7 @@ Objekt

- -
+ @@ -1154,9 +1150,40 @@ + + + + + + + +

+ pick(Ref::CHILD) +

+ + +
+
- + + + + + + +

+ würde sagen: ja, aber auch nur für das after-Verb! +

+

+ allgemein halte ich einen wrap-around für keine gute Idee, +

+

+ weil er zu Zweideutigekeigen führt und daher Struktur oder Konsistenzfehler überspielt +

+ + +
@@ -1191,8 +1218,7 @@ läßt sich stets duch eine inverse Folge von find und pick  emulieren

- - +
@@ -1239,8 +1265,7 @@ vorerst verworfen, da zusätzlicher Prüf-Aufwand

- - + @@ -1287,8 +1312,7 @@ - - + @@ -1310,8 +1334,7 @@ Vorteilhaft für Version-Management

- - +
@@ -1323,8 +1346,7 @@ profitiert also von allen Verbesserungen des allgemeinen Algorithmus

- -
+
@@ -1345,8 +1367,7 @@ + NlogN f ür den Index zur Diff-Erzeugung

- -
+
@@ -1379,8 +1400,7 @@ korrekten Listen-Diff zu erzeugen

- - +
@@ -1402,8 +1422,7 @@ dann überträgt sich das auf die Diff-Behandlung

- - +
@@ -1418,8 +1437,7 @@ müssen wir für jede Einfügung eine vollständige Suche machen

- -
+
@@ -1434,8 +1452,7 @@ Auch wenn diese andere Implementierung nur delegiert

- -
+
@@ -1469,8 +1486,7 @@ indem sie an die Attributs-Liste angehängt werden

- - +
@@ -1519,8 +1535,7 @@ wegen Entscheidung für das "Listen"-Modell zur Attribut-Handhabung

- - + @@ -1541,8 +1556,7 @@ ...da das Kind in der Liste der Attribute nämlich garnicht gefunden wird

- - + @@ -1563,8 +1577,7 @@ Aber an allen anderen Stellen in der Attribut-Zone ist ein solcher Fetch ein Fehler!

- -
+
@@ -1581,8 +1594,7 @@ standardmäßig strikt

- - + @@ -1640,6 +1652,7 @@ +