morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
rules.hpp File Reference

x-rules read into RuleExpr trees, translated into the UI document's expression language (expr/1) and evaluated by its one evaluator, three-valued and exactly. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <functional>
#include <limits>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "../../render/locale_format.hpp"
#include "../../ui/expression.hpp"
#include "../../ui/value.hpp"
#include "../../util/rational.hpp"
#include "detail/text.hpp"

Go to the source code of this file.

Classes

struct  morph::forms::SchemaError
 Why a schema does not read as a form: where, and why. More...
struct  morph::forms::RuleOperand
 What a rule reads of one field. More...
class  morph::forms::RuleExpr
 One x-rules entry, or a condition inside one, and its translation into expr/1. More...

Typedefs

using morph::forms::RuleLookup = std::function<RuleOperand(std::string_view field)>
 Reads one field by wire name, for a rule. The session's lookup is tracked, so a verdict computed inside a reactive computation recomputes when a field it read changes.

Enumerations

enum class  morph::forms::Tri : std::uint8_t { False , True , Unknown }
 A three-valued verdict: a half-typed form has fields with no value yet, so a rule can be undecided. More...

Functions

constexpr Tri morph::forms::triNot (Tri value) noexcept
 Kleene negation.
Tri morph::forms::gatingVerdict (std::span< RuleExpr const > rules, RuleLookup const &lookup)
 Whether the gating rules let the form submit.
Tri morph::forms::visibleVerdict (std::span< RuleExpr const > rules, std::string_view field, RuleLookup const &lookup)
 Whether field is shown: hidden as soon as one visibleWhen naming it is false.
Tri morph::forms::readonlyVerdict (std::span< RuleExpr const > rules, std::string_view field, RuleLookup const &lookup)
 Whether field is frozen: as soon as one readonlyWhen naming it is true.
Tri morph::forms::requiredVerdict (std::span< RuleExpr const > rules, std::string_view field, RuleLookup const &lookup)
 Whether field is required by a rule: as soon as one requiredWhen naming it is true.

Detailed Description

x-rules read into RuleExpr trees, translated into the UI document's expression language (expr/1) and evaluated by its one evaluator, three-valued and exactly.

Specified in docs/spec/forms/engine.md, "Rules".

Definition in file rules.hpp.

Typedef Documentation

◆ RuleLookup

using morph::forms::RuleLookup = std::function<RuleOperand(std::string_view field)>

Reads one field by wire name, for a rule. The session's lookup is tracked, so a verdict computed inside a reactive computation recomputes when a field it read changes.

Definition at line 84 of file rules.hpp.

Enumeration Type Documentation

◆ Tri

enum class morph::forms::Tri : std::uint8_t
strong

A three-valued verdict: a half-typed form has fields with no value yet, so a rule can be undecided.

Enumerator
False 

Definitely does not hold.

True 

Definitely holds.

Unknown 

Cannot be decided: an operand does not encode, or the kind is not one this engine knows.

Definition at line 46 of file rules.hpp.

Function Documentation

◆ triNot()

Tri morph::forms::triNot ( Tri value)
nodiscardconstexprnoexcept

Kleene negation.

Parameters
valueThe verdict.
Returns
True for False, False for True, Unknown for Unknown.

Definition at line 55 of file rules.hpp.

◆ gatingVerdict()

Tri morph::forms::gatingVerdict ( std::span< RuleExpr const > rules,
RuleLookup const & lookup )
inlinenodiscard

Whether the gating rules let the form submit.

Only a False rule blocks: an Unknown one is waiting on a field that is required or does not encode, and that field blocks readiness itself; and a rule kind this engine does not know must not lock an older client out of a newer server's forms.

Parameters
rulesThe rules.
lookupReads each operand.
Returns
False when some gating rule is false, Unknown when none is false and some is undecided, else True.

Definition at line 743 of file rules.hpp.

◆ visibleVerdict()

Tri morph::forms::visibleVerdict ( std::span< RuleExpr const > rules,
std::string_view field,
RuleLookup const & lookup )
inlinenodiscard

Whether field is shown: hidden as soon as one visibleWhen naming it is false.

Parameters
rulesThe rules.
fieldThe wire name.
lookupReads each operand.
Returns
False when hidden; Unknown presents as shown.

Definition at line 798 of file rules.hpp.

◆ readonlyVerdict()

Tri morph::forms::readonlyVerdict ( std::span< RuleExpr const > rules,
std::string_view field,
RuleLookup const & lookup )
inlinenodiscard

Whether field is frozen: as soon as one readonlyWhen naming it is true.

Parameters
rulesThe rules.
fieldThe wire name.
lookupReads each operand.
Returns
True when frozen; Unknown presents as editable.

Definition at line 808 of file rules.hpp.

◆ requiredVerdict()

Tri morph::forms::requiredVerdict ( std::span< RuleExpr const > rules,
std::string_view field,
RuleLookup const & lookup )
inlinenodiscard

Whether field is required by a rule: as soon as one requiredWhen naming it is true.

Parameters
rulesThe rules.
fieldThe wire name.
lookupReads each operand.
Returns
True when required; Unknown presents as not required.

Definition at line 818 of file rules.hpp.