From 5e86aa38804f64e189b5e95363ab5491360d52ac Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 26 Jan 2025 15:55:01 +0100 Subject: [PATCH] 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 --- src/lib/parse.hpp | 12 ++++- tests/library/parse-test.cpp | 12 +++++ wiki/thinkPad.ichthyo.mm | 97 ++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/src/lib/parse.hpp b/src/lib/parse.hpp index 7eb8aa796..e8f75d310 100644 --- a/src/lib/parse.hpp +++ b/src/lib/parse.hpp @@ -90,14 +90,13 @@ namespace util { */ template struct Connex - : util::NonAssign { using PFun = FUN; PFun parse; using Result = typename _Fun::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 + auto + expectResult() + { + return accept (Connex{std::function(StrView)>{}}); + } + + /** * Combinator: extend this Syntax clause by expecting a further sub-clause diff --git a/tests/library/parse-test.cpp b/tests/library/parse-test.cpp index 2073490f4..4738fe732 100644 --- a/tests/library/parse-test.cpp +++ b/tests/library/parse-test.cpp @@ -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(); + + string s1{"great ! great ! great"}; + } }; LAUNCHER (Parse_test, "unit common"); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index abd468065..6d32f1223 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -57643,6 +57643,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ FUN ≡ std::function & +

+ + +
+
+
+ + + + + + +

+ Connex-Definition +

+

+ erfüllt das bereits +

+ + +
+ + + + + + + + + + + + + + + + + + + + +

+ da viele Builder-Funktionen in ein neues Syntax-Objekt schieben +

+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + +