Bindings.h header

#include <ew/core/Bindings.h>

Namespace ew::core

Bindings class

class ew::core::Bindings

What the names in an expression mean.

The expression language is one language everywhere in the product; only the names change. A spreadsheet's names are cells and ranges (A1, $C$5, A1:B2), a branching condition's are the story variables (gold, hasKey), a validation rule's are the fields of the object being checked and of the objects it references (price, owner.name). Everything else – the operators, the precedence, the functions, the error tokens – is shared, so an author who learns it in the spreadsheet already knows it in a rule.

Members

ew::core::expression::Bindings::Bindings()=default

Constructs bindings. Subclasses hold whatever they resolve against.

ew::core::expression::Bindings::Bindings(const Bindings &)=delete

Not copied: bindings are referred to for the length of one evaluation, never handed around.

ew::core::expression::Bindings::Bindings(Bindings &&)=delete

Not moved, for the same reason.

Bindings & ew::core::expression::Bindings::operator=(const Bindings &)=delete

Not copy-assigned.

Bindings & ew::core::expression::Bindings::operator=(Bindings &&)=delete

Not move-assigned.

virtual ew::core::expression::Bindings::~Bindings()

Destroys the bindings.

virtual bool ew::core::expression::Bindings::isNameStart(QChar character) const

Whether character may BEGIN a name here. Letters always may; a spreadsheet also admits '$' so a pinned reference ($A$1) is one name rather than an operator and a name.

virtual bool ew::core::expression::Bindings::isNameCharacter(QChar character) const

Whether character may appear INSIDE a name here, after the first character. Letters, digits and '_' always may; a spreadsheet adds '$' and ':' (so A1:B2 is one name), and a field context adds '.' (so owner.name is one name).

virtual std::optional< std::vector< Value > > ew::core::expression::Bindings::resolve(QStringView name, QString &error) const =0

The value or values name contributes to the expression: exactly one for a scalar, several for a collection (a spreadsheet range, a list-valued field), none for an empty collection.

Returns std::nullopt and sets error when the name cannot be resolved. The message is shown to the author as-is, so a context with real names should say which one is wrong ("There is no field called 'pirce'.") rather than repeat a token.

virtual QStringList ew::core::expression::Bindings::names() const

Every name an author may type here, for autocomplete – shortest and most useful first is not required, the editor sorts. An empty list means the context cannot enumerate its names (a spreadsheet's cells are not worth listing), which suppresses autocomplete rather than claiming there are none.