From b6360b2e9ca6432e02bed0d7590a3559a12b93c0 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 17 Feb 2018 05:11:34 +0100 Subject: [PATCH] LocationSolver: automatically inject persp(UIC_ELIDED) (closes #1128) decided to add a very specific preprocessing here, to make the DSL notation more natural. My guess is that most people won't spot the presence of this tiny bit of magic, and it would be way more surprising to have rules like UICoord::currentWindow().panel("viewer").create() fail in most cases, simply because there is a wildcard on the perspective and the panel viewer does not (yet) exist. In such a case, we now turn the perspective into a "existential quantified" wildcard, which is treated as if the actually existing element was written explicitly into the pattern. --- src/gui/interact/ui-coord-resolver.hpp | 18 +++ src/gui/interact/ui-location-solver.hpp | 17 ++- tests/12metaprogramming.tests | 2 +- tests/52-gui-control.tests | 2 +- .../gui/interact/ui-location-solver-test.cpp | 2 +- wiki/thinkPad.ichthyo.mm | 116 ++++++++++++++---- 6 files changed, 128 insertions(+), 29 deletions(-) diff --git a/src/gui/interact/ui-coord-resolver.hpp b/src/gui/interact/ui-coord-resolver.hpp index ab32baac1..687f0c180 100644 --- a/src/gui/interact/ui-coord-resolver.hpp +++ b/src/gui/interact/ui-coord-resolver.hpp @@ -539,6 +539,24 @@ namespace interact { } + /** mutate to turn a wildcard into _existentially quantified._ + * This means to assume (or require) that an element actually exists at the given position, + * without knowing or caring about its actual name. This becomes relevant when matching for + * _partially covered_ path; normal wildcards are only accepted to build a solution, when + * the matching can be confirmed by an explicit element after (below) the wildcard part. + * While this restriction serves to prevent ambiguous and surprising arbitrary matches, + * it can sometimes defeat any solution, e.g. when creating a new panel on top of an + * existing but irrelevant perspective. + */ + UICoordResolver&& + existentiallyQuantify (size_t pos) + { + if (pos < uic_.size() and not uic_.isPresent(pos)) + overwrite (pos, UIC_ELIDED); + return std::move (*this); + } + + /** diagnostics */ operator string() const { return string(this->uic_); } diff --git a/src/gui/interact/ui-location-solver.hpp b/src/gui/interact/ui-location-solver.hpp index 09fc09a31..b8e356d96 100644 --- a/src/gui/interact/ui-location-solver.hpp +++ b/src/gui/interact/ui-location-solver.hpp @@ -275,6 +275,7 @@ namespace interact { // try to solve the current Clause by matching against real UI topology UICoordResolver resolver{clause.pattern, getLocationQuery()}; + preprocess (resolver, clause); resolver.coverPartially(); // now either holds a solution or is empty if (not isnil(resolver) // Solution found! @@ -304,7 +305,21 @@ namespace interact { } private: - + /** perform adjustments on the current pattern to support some very specific situations + * - when we want to create a new panel (or re-use an existing of the same name), on top + * of an existing (but irrelevant) perspective, we mark this perspective as "just there". + * This allows to get a new path as solution, which is just covered up to and including + * that perspective; without special treatment, such a match would otherwise be rejected. + */ + void + preprocess (UICoordResolver& builder, LocationClause const& clause) + { + if (clause.createParents + and clause.pattern.isComplete()) + { + builder.existentiallyQuantify (UIC_PERSP); + } + } }; diff --git a/tests/12metaprogramming.tests b/tests/12metaprogramming.tests index b559425aa..36ee4d7ac 100644 --- a/tests/12metaprogramming.tests +++ b/tests/12metaprogramming.tests @@ -252,7 +252,7 @@ return: 0 END -TEST: "Iterator monad variations (2nd draft)" IterTreeExplorer_test < - + @@ -3542,7 +3542,7 @@ - + @@ -3853,8 +3853,31 @@ - - + + + + + + +

+ habe diese Analyse 2017/2018 ein Stück weit vorangetrieben. +

+

+ Ergebnis war die Schaffung von UI-Koordinaten und die ViewSpec-DSL +

+

+ +

+

+ Damit ist das Thema aber bei Weitem noch nicht ausgeschöpft, +

+

+ jedoch genügend aufgeschlossen, um die konkrete Implementierung fortzusetzen +

+ + +
+ @@ -9246,8 +9269,8 @@ - - + + @@ -9910,7 +9933,12 @@ - + + + + + + @@ -9944,7 +9972,7 @@ - + @@ -9968,12 +9996,11 @@ - - - + + + - @@ -10171,9 +10198,9 @@ - + - + @@ -10247,7 +10274,7 @@ - + @@ -10260,15 +10287,54 @@ - - + + - + + + + + + + + + + + + + + + + + +

+ ...denn durch overwrite kann man denormalisierte Pattern erzeugen. +

+

+ Also muß jeder Anwender dieser Funktion sicherstellen, daß dies +

+

+ entweder nicht passieren kann, oder explizit normalise() aufrufen. +

+ + +
+ +
+ + + +
+ + + +
+
@@ -10368,7 +10434,7 @@
- + @@ -10422,7 +10488,7 @@ - + @@ -11106,9 +11172,9 @@ - + - + @@ -11305,9 +11371,9 @@ - + - + @@ -21067,7 +21133,7 @@ - +