Library: lay out foundation for recursive clauses
In accordance to the plan drafted yesterday, I will try to integrate this essential capability into the framework established thus far by a trick, requiring only minimal adjustment, but some work by the user. Since the parse function is defined as a (unqualified) template argument, it is possible to emplace either a `std::function`, or a reference thereto. For this to work, the user is required to pre-define the expected result type, and, furthermore, must later on assign a fully specified clause, which also has a model transformation binding attached to yield this predeclared result type
This commit is contained in:
parent
70a5a7a06c
commit
5e86aa3880
3 changed files with 119 additions and 2 deletions
|
|
@ -90,14 +90,13 @@ namespace util {
|
|||
*/
|
||||
template<class FUN>
|
||||
struct Connex
|
||||
: util::NonAssign
|
||||
{
|
||||
using PFun = FUN;
|
||||
PFun parse;
|
||||
|
||||
using Result = typename _Fun<PFun>::Ret::Result;
|
||||
|
||||
Connex (FUN&& pFun)
|
||||
Connex (FUN pFun)
|
||||
: parse{move(pFun)}
|
||||
{ }
|
||||
};
|
||||
|
|
@ -879,6 +878,15 @@ namespace util {
|
|||
}
|
||||
|
||||
|
||||
/** Setup an assignable, recursive Syntax clause, initially empty */
|
||||
template<typename RES>
|
||||
auto
|
||||
expectResult()
|
||||
{
|
||||
return accept (Connex{std::function<Eval<RES>(StrView)>{}});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Combinator: extend this Syntax clause by expecting a further sub-clause
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ namespace test {
|
|||
acceptBracketed();
|
||||
|
||||
verify_modelBinding();
|
||||
verify_recursiveSyntax();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -616,6 +617,17 @@ namespace test {
|
|||
CHECK (syntax1e.parse("ham actor").getResult() == 8);
|
||||
CHECK (syntax1e.parse("con artist").getResult() == 9);
|
||||
}
|
||||
|
||||
|
||||
/** @test definition of recursive Syntax clauses
|
||||
*/
|
||||
void
|
||||
verify_recursiveSyntax()
|
||||
{
|
||||
auto recursive = expectResult<int>();
|
||||
|
||||
string s1{"great ! great ! great"};
|
||||
}
|
||||
};
|
||||
|
||||
LAUNCHER (Parse_test, "unit common");
|
||||
|
|
|
|||
|
|
@ -57643,6 +57643,103 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737900281772" ID="ID_1448096788" MODIFIED="1737900299647" TEXT="Funktionalität ergänzen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737900357508" ID="ID_1812575904" MODIFIED="1737902053232" TEXT="opaqueConnex">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1737900423425" ID="ID_1797162357" MODIFIED="1737900451668" TEXT="parse function is type-erased"/>
|
||||
<node CREATED="1737900453103" ID="ID_1367568195" MODIFIED="1737900551119" TEXT="FUN ≡ std::function"/>
|
||||
<node CREATED="1737900557468" ID="ID_311377436" MODIFIED="1737901871328" TEXT="Unterschied">
|
||||
<node CREATED="1737900569320" ID="ID_1096113156" MODIFIED="1737900574986" TEXT="ist zuweisbar"/>
|
||||
<node CREATED="1737900578558" ID="ID_344632892" MODIFIED="1737900631289" TEXT="(Zuweisbarkeit) dient auch als type-Tag"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737900639590" ID="ID_1759226520" MODIFIED="1737902126147" TEXT="ansonsten: nichts zu tun">
|
||||
<arrowlink COLOR="#f6fec6" DESTINATION="ID_677433286" ENDARROW="Default" ENDINCLINATION="-25;-71;" ID="Arrow_ID_47317323" STARTARROW="None" STARTINCLINATION="-19;2;"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1737900687256" ID="ID_1682593770" MODIFIED="1737900709225" TEXT="Steuerung über das Konstruktor-Argument"/>
|
||||
<node CREATED="1737900726635" ID="ID_844484749" MODIFIED="1737900746868" TEXT="anlegen durch eine leere std::function"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737900361556" ID="ID_1323300092" MODIFIED="1737902053232" TEXT="forwardConnex">
|
||||
<icon BUILTIN="info"/>
|
||||
<node CREATED="1737901815146" ID="ID_248887267" MODIFIED="1737901826492" TEXT="Referenz auf einen anderen Connex"/>
|
||||
<node CREATED="1737900453103" ID="ID_432272475" MODIFIED="1737901850195">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
FUN ≡ std::function <font color="#9b0202">&</font>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737901890719" ID="ID_677433286" MODIFIED="1737902114644">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Connex-Definition
|
||||
</p>
|
||||
<p>
|
||||
erfüllt das bereits
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<linktarget COLOR="#f6fec6" DESTINATION="ID_677433286" ENDARROW="Default" ENDINCLINATION="-25;-71;" ID="Arrow_ID_47317323" SOURCE="ID_1759226520" STARTARROW="None" STARTINCLINATION="-19;2;"/>
|
||||
<icon BUILTIN="idea"/>
|
||||
<node BACKGROUND_COLOR="#ccb59b" COLOR="#6e2a38" CREATED="1737901921332" ID="ID_969187731" MODIFIED="1737901935953" TEXT="Connex ist ein low-level-Konstrukt">
|
||||
<font ITALIC="true" NAME="SansSerif" SIZE="14"/>
|
||||
<icon BUILTIN="yes"/>
|
||||
<node CREATED="1737901937041" ID="ID_25503755" MODIFIED="1737901942778" TEXT="deshalb haben wir den Parser">
|
||||
<icon BUILTIN="ksmiletris"/>
|
||||
</node>
|
||||
<node CREATED="1737901944289" ID="ID_1298401085" MODIFIED="1737901960594" TEXT="der darüber liegende Code sorgt für den richtigen Zugang"/>
|
||||
</node>
|
||||
<node CREATED="1737902212717" ID="ID_1611321813" MODIFIED="1737902236666" TEXT="umstellen...">
|
||||
<node CREATED="1737902237690" ID="ID_1997654816" MODIFIED="1737903301670" TEXT="NonAssign ⟶ beliebig kopierbar und zuweisbar">
|
||||
<node CREATED="1737903172029" ID="ID_1448785140" MODIFIED="1737903181056" TEXT="die ganze Unterscheidung war künstlich"/>
|
||||
<node CREATED="1737903181956" ID="ID_395623810" MODIFIED="1737903192030" TEXT="die Weichen werden auf DSL-Ebene gestellt"/>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1737903192730" ID="ID_1283071351" MODIFIED="1737903229001" TEXT="und dort oft auf gefährliche Weise">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
da viele Builder-Funktionen in ein neues Syntax-Objekt schieben
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1737902239393" ID="ID_1905199568" MODIFIED="1737902257475" TEXT="Konstruktor per Value ⟶ move into place"/>
|
||||
</node>
|
||||
<node CREATED="1737901961822" ID="ID_40485946" MODIFIED="1737901986910" TEXT="maximal ist eine Spezialisierung der Konstruktoren notwendig">
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1737901988013" ID="ID_317683367" MODIFIED="1737901996197" TEXT="könnte relevant werden zur Fehler-Behandlung"/>
|
||||
<node CREATED="1737901996833" ID="ID_1612965331" MODIFIED="1737902030982" TEXT="denn das Fehler-Schema muß in den Connex abgelegt werden"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1737928226021" ID="ID_1934790072" MODIFIED="1737928238887" TEXT="Zuweisung an die Funktion explizit in Syntax realisieren"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1737900294630" ID="ID_770847444" MODIFIED="1737900299648" TEXT="in DSL einbinden">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1737903350357" ID="ID_870130978" MODIFIED="1737903359576" TEXT="expectResult<RES>()">
|
||||
<node CREATED="1737903366802" ID="ID_806063281" MODIFIED="1737903376846" TEXT="bewußt ein sehr expliziter Name!">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node CREATED="1737903380886" ID="ID_1444141146" MODIFIED="1737903395440" TEXT="legt ein leeres Platzhalter-Syntax-Objekt an"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1737048820482" ID="ID_235554745" MODIFIED="1737048832524" TEXT="generisches Model-Binding"/>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue