From 248fbef9b4ea6f1a41cd8bd920f8983d98510d99 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 16 Jun 2015 04:27:37 +0200 Subject: [PATCH] WIP: draft a DSL for simplified definition of literal records This is just a draft for now -- kindof a by-catch, since it is chep to build that DSL on top of the Rec::Mutator. This DSL could be of value later, when it comes to define some configuration data inline, in a copact and clear fashion, without the need to use a bridge to/from JSON --- tests/library/diff/gen-node-basic-test.cpp | 84 +++++++++++++++++++++- wiki/thinkPad.ichthyo.mm | 21 +++++- 2 files changed, 101 insertions(+), 4 deletions(-) diff --git a/tests/library/diff/gen-node-basic-test.cpp b/tests/library/diff/gen-node-basic-test.cpp index 81d00dbd1..18b511802 100644 --- a/tests/library/diff/gen-node-basic-test.cpp +++ b/tests/library/diff/gen-node-basic-test.cpp @@ -63,6 +63,18 @@ namespace test{ /*****************************************************************************//** * @test Verify properties of a special collection type shaped for * external representation of object-like data. + * - GenNode elements can be created "right away", picking up + * the given type, assumed that the payload is one of the + * supported basic types. + * - optionally, GenNode elements can be named + * - unnamed elements get a marker ID plus unique number extension + * - object-like elements can be represented by using a diff:Record + * as payload. Obviously, the resulting data structure type is recursive. + * - a shortcut is provided to simplify defining empty baseline objects + * - there is a special notation to create "id references", which can + * can be used to stand-in for an "object" (Record). This shortcut + * notation is relevant for the tree diff language -- used within + * Lumiera as "External Tree Description" of object networks. * * @see IndexTable * @see DiffListApplication_test @@ -74,7 +86,8 @@ namespace test{ run (Arg) { simpleUsage(); - verifySnapshot(); + objectShortcut(); + symbolReference(); sequenceIteration(); duplicateDetection(); copy_and_move(); @@ -115,7 +128,7 @@ namespace test{ VERIFY_ERROR (WRONG_TYPE, n1 = n2 ); // can build recursive data structures - GenNode n3(Rec({"spam", GenNode("ham", "eggs")})); + GenNode n3(Rec({GenNode("type", "spam"), GenNode("ham", "eggs")})); CHECK ("spam" == n3.data.get().getType()); CHECK ("eggs" == n3.data.get().get("ham").data.get()); CHECK ("ham" == n3.data.get().get("ham").idi.getSym()); @@ -125,7 +138,72 @@ namespace test{ void - verifySnapshot() + objectShortcut() + { + auto o0 = Rec().genNode(); + auto o1 = Rec().genNode("νόμος"); + auto o2 = Rec().type("spam").genNode(); + auto o3 = Rec().attrib("Ψ", int64_t(42), "π", 3.14159265358979323846264338328).genNode("νόμος"); + + CHECK (!o0.isNamed()); + CHECK (isnil(o0.data.get())); + CHECK ("NIL" == o0.data.get().getType()); + + CHECK (o1.isNamed()); + CHECK ("νόμος" == o1.idi.getSym()); + CHECK (isnil(o1.data.get())); + + CHECK (!o2.isNamed()); + CHECK ("spam" == o0.data.get().getType()); + CHECK (isnil(o2.data.get())); + + CHECK (o3.isNamed()); + CHECK ("νόμος" == o3.idi.getSym()); + CHECK ("NIL" == o3.data.get().getType()); + CHECK (GenNode("Ψ", int64_t(42)) == o3.data.get().get("Ψ")); + CHECK (42L == o3.data.get().get("Ψ").data.get); + CHECK (1e-7 > fabs (3.14159265 - o3.data.get().get("π").data.get)); + + LuidH luid; + auto o4 = Rec::Mutator(o2) // ...use GenNode o2 as starting point + .appendChild(GenNode("τ", Time(1,2,3,4))) // a named node with Time value + .scope('*' // a char node + ,"★" // a string node + ,luid // a hash value (LUID) + ,TimeSpan(Time::ZERO, FSecs(23,25)) // a time span + ,Rec().type("ham").scope("eggs").genNode()) // a spam object + .genNode("baked beans"); // ---> finish into named node + + CHECK (o4.isNamed()); + CHECK ("baked beans" == o4.idi.getSym()); + CHECK ("spam" == o4.data.get().getType()); // this was "inherited" from o2 + + auto scope = o4.data.get().scope(); + CHECK (!isnil(scope)); + CHECK (GenNode("τ", Time(1,2,3,4)) == *scope); + ++scope; + CHECK (GenNode(char('*')) == *scope); + ++scope; + CHECK ("★" == scope->data.get()); + ++scope; + CHECK (luid == scope->data.get()); + ++scope; + CHECK (Time(0.92,0) == scope->data.get().end()); + ++scope; + auto spam = *scope; + CHECK (!++scope); + CHECK ("ham" == spam.getType()); + CHECK (spam.contains (GenNode("eggs"))); + + // but while o4 was based on o2, + // adding all the additional contents didn't mutate o2 + CHECK (isnil(o2.data.get())); + } + + + + void + symbolReference() { } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 671867b0f..c31af429b 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -34,7 +34,26 @@ - + + + + + + + + + +

+ Zweck: kompaktes Anschreiben +

+

+ von literalen Daten +

+ + +
+
+