Library: establish evaluation and iteration on application

This commit is contained in:
Fischlurch 2024-03-20 21:46:05 +01:00
parent 7893cc99c3
commit 76bd9ba6ce
2 changed files with 81 additions and 17 deletions

View file

@ -49,9 +49,9 @@
** WARNING: critical!
** ${else}(routine report)${end if critical}
**
** Participants
** ${for person}- ${name} ${if role}(${role})${end if role}
** ${else}** no participants **
** **Participants**
** ${for person} - ${name} ${if role}(${role})${end if role}
** ${else} _no participants_
** ${end for person}
** \endcode
** This template spec is parsed and preprocessed into an internal representation,
@ -62,10 +62,10 @@
** can be suitably interpreted as a sequence of sub-scopes, then the »for block«
** is instantiated for each entry, using the values retrieved through the keys
** "name" and "role". Typically these keys are defined for each sub-scope
** - note that the key "role" is enclosed into a conditional section
** - note that `${role}` is enclosed into a conditional section, making it optional
** - note that both for conditional sections, and for iteration, an _else branch_
** can be defined.
** How data is actually accessed, and what constitutes a nested scope is obviously
** can optionally be defined in the template.
** How data is actually accessed and what constitutes a nested scope is obviously
** a matter of the actual data binding, which is picked up through a template
** specialisation for lib::TextTemplate::DataSource
**
@ -101,7 +101,7 @@
#include "lib/nocopy.hpp"
#include "lib/iter-explorer.hpp"
#include "lib/format-util.hpp"
//#include "lib/util.hpp"
#include "lib/util.hpp"
//#include <cmath>
//#include <limits>
@ -116,6 +116,8 @@ namespace lib {
using std::string;
using StrView = std::string_view;
using util::unConst;
namespace {
@ -142,6 +144,9 @@ namespace lib {
/** cross-references by index number */
using Idx = size_t;
template<class SRC>
class InstanceCore;
struct ParseCtx
{
Clause clause;
@ -155,8 +160,8 @@ namespace lib {
string val{""};
Idx refIDX{0};
template<class IT>
StrView instantiate (IT&);
template<class SRC>
StrView instantiate (InstanceCore<SRC>&) const;
};
/** the text template is compiled into a sequence of Actions */
@ -187,6 +192,8 @@ namespace lib {
bool checkPoint() const;
StrView& yield() const;
void iterNext();
void instantiateNext();
};
template<class DAT>
@ -231,28 +238,44 @@ namespace lib {
: dataSrc_{s}
, actionIter_{explore (actions)}
, ctxStack_{}
{ }
, rendered_{}
{
instantiateNext();
}
/**
* TextTemplate instantiation: check point on rendered Action.
* In active operation, there is a further Action, and this action
* can be (or has already been) rendered successfully.
*/
template<class SRC>
inline bool
TextTemplate::InstanceCore<SRC>::checkPoint() const
{
UNIMPLEMENTED ("TextTemplate instantiation: check point on action token");
return bool(actionIter_);
}
template<class SRC>
inline StrView&
TextTemplate::InstanceCore<SRC>::yield() const
{
UNIMPLEMENTED ("TextTemplate instantiation: yield instantiated string element for action token");
return unConst(this)->rendered_;
}
template<class SRC>
inline void
TextTemplate::InstanceCore<SRC>::iterNext()
{
UNIMPLEMENTED ("TextTemplate instantiation: advance to interpretation of next action token");
++actionIter_;
instantiateNext();
}
template<class SRC>
inline void
TextTemplate::InstanceCore<SRC>::instantiateNext()
{
rendered_ = actionIter_? actionIter_->instantiate(*this)
: StrView{};
}
@ -263,11 +286,26 @@ namespace lib {
* @param instanceIter the wrapped InstanceCore with the actual data binding
* @return a string-view pointing to the effective rendered chunk corresponding to this action
*/
template<class IT>
template<class SRC>
inline StrView
TextTemplate::Action::instantiate (IT& instanceIter)
TextTemplate::Action::instantiate (InstanceCore<SRC>&) const
{
UNIMPLEMENTED ("actual implementation of template action interpretation");
switch (code) {
case TEXT:
return val;
case KEY:
return "";
case COND:
return "";
case JUMP:
return "";
case ITER:
return "";
case LOOP:
return "";
default:
NOTREACHED ("uncovered Activity verb in activation function.");
}
}

View file

@ -112915,6 +112915,31 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
<icon BUILTIN="messagebox_warning"/>
</node>
</node>
<node CREATED="1710972830691" ID="ID_895397251" MODIFIED="1710972835926" TEXT="Auswertungs-Muster">
<node CREATED="1710972837963" ID="ID_1932847831" MODIFIED="1710972867251" TEXT="gesteuert wird die Auswertung durch die ActionSeq-Iteration"/>
<node CREATED="1710972870686" ID="ID_522213375" MODIFIED="1710972892484" TEXT="daher bestimmt der ActionIter insgesamt den Zustand"/>
<node COLOR="#5b280f" CREATED="1710972915016" ID="ID_842055820" MODIFIED="1710973898400" TEXT="zudem soll aber auch die eigentliche Instantiierung on-demand geschehen">
<icon BUILTIN="button_cancel"/>
<node CREATED="1710973899798" ID="ID_1993437461" MODIFIED="1710973913433" TEXT="versucht..."/>
<node CREATED="1710973914132" ID="ID_537313276" MODIFIED="1710973928774" TEXT="kollidiert mit der const-correctness"/>
<node CREATED="1710973930125" ID="ID_1761608435" MODIFIED="1710974070025" TEXT="es gibt keinen guten Grund sich dar&#xfc;ber hinwegzusetzen">
<arrowlink COLOR="#51658c" DESTINATION="ID_277250397" ENDARROW="Default" ENDINCLINATION="130;-7;" ID="Arrow_ID_363425606" STARTARROW="None" STARTINCLINATION="-125;6;"/>
<icon BUILTIN="yes"/>
</node>
</node>
<node CREATED="1710972965441" ID="ID_812544425" MODIFIED="1710974073225" TEXT="verwende eine default-konstruierte string-view als Marker f&#xfc;r fehlende Auswertung">
<icon BUILTIN="idea"/>
</node>
<node CREATED="1710973958294" ID="ID_277250397" MODIFIED="1710974070025" TEXT="dann jeweils f&#xfc;r den anstehenden Schritt im Vorraus rendern">
<linktarget COLOR="#51658c" DESTINATION="ID_277250397" ENDARROW="Default" ENDINCLINATION="130;-7;" ID="Arrow_ID_363425606" SOURCE="ID_1761608435" STARTARROW="None" STARTINCLINATION="-125;6;"/>
<node CREATED="1710974084701" ID="ID_1002749282" MODIFIED="1710974099111" TEXT="Hilfsfunktion instantiateNext()"/>
<node CREATED="1710974100979" ID="ID_1061436801" MODIFIED="1710974123068" TEXT="diese kann dann auch den Marker f&#xfc;r Auswertung setzen / pr&#xfc;fen"/>
<node CREATED="1710974178675" ID="ID_493594407" MODIFIED="1710974201222" TEXT="die eigentliche Auswertung wird delegiert durch Action::instantiate()"/>
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1710974202039" ID="ID_1891484853" MODIFIED="1710974280634" TEXT="daf&#xfc;r werden aber die Daten aufgeschlossen &#x27f9; State-&#xc4;nderungen in der Core m&#xf6;glich">
<icon BUILTIN="messagebox_warning"/>
</node>
</node>
</node>
</node>
<node CREATED="1710856784967" ID="ID_201927694" MODIFIED="1710856798759" TEXT="Parsing soll eager sein (wegen Syntax-Fehlern)"/>
</node>
@ -112923,6 +112948,7 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710901502001" ID="ID_1137356719" MODIFIED="1710901531737" TEXT="hier wird der Kern der Template-Interpretation ausformuliert">
<icon BUILTIN="yes"/>
</node>
<node CREATED="1710971037326" ID="ID_775342057" MODIFIED="1710971061408" TEXT="einfachster Fall: ein konstantes Segment (code TEXT)"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710793352301" ID="ID_1691061928" MODIFIED="1710793355254" TEXT="Bindings">