Documentation
¶
Overview ¶
Package expr implements OneGov's Expression V2 language and transition conditions, including the parts of the real engine that surprise people: references are pasted into the text before parsing, and how they are pasted is configurable (see Policy) until replay against real instances settles it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConditionResult ¶
type ConditionResult struct {
Pass bool
// Unresolved lists references in the condition that had no value. The
// condition still evaluates (they count as blank), but a transition
// that depends on a value nobody produced is worth a look.
Unresolved []string
Err error
}
ConditionResult is an evaluated transition condition.
func EvalCondition ¶
func EvalCondition(src string, ctx Context, p Policy) ConditionResult
EvalCondition evaluates a transition condition. An empty condition passes.
type Context ¶
Context resolves references. Paths are dotted, without the "$." prefix: "applicantID", "n9.output.total", "n20.form-slug.field".
type EvalError ¶
EvalError is a runtime failure: wrong types, an unknown function, a division by zero.
type Hazard ¶
type Hazard struct {
Code string
Ref string // the reference involved, if any
Message string
Fails bool // true if it fails the instance, false if it is silently wrong
}
Hazard is a pattern in an expression's source that is known to break, or to quietly give the wrong answer, in the live engine.
type MapContext ¶
MapContext is a Context over a plain map, for tests and fixtures.
type Mode ¶
type Mode int
Mode says which language is being parsed.
const ( // ExpressionMode is Expression V2 after substitution: no references may // remain, and a leftover $.{...} is a syntax error. ExpressionMode Mode = iota // ConditionMode is a transition condition: bare $.n12.state references // are allowed and AND / OR work as well as && / ||. ConditionMode )
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is a parsed expression.
type Policy ¶
type Policy struct {
// Quote wraps string values pasted into Expression V2. The live engine
// uses a double quote; test_workflow_expression uses a single quote,
// which is why the sandbox hides nested-quote failures.
// (workflow-expressions SKILL.md, core rule 8)
Quote byte
// QuoteNull: whether a null value is pasted as "" or as nothing.
// Confirmed on a recorded Recorded instance: with dob2 null,
// ifCondition( $.{dob2} == ”, ”, ... ) produced ” and did not
// fail, which only parses if the null arrived as "". (The docs' "bare
// empty substitution is a parse error" does not apply to nulls.)
QuoteNull bool
// Templates: an expression that is one double-quoted string with
// references inside is filled in as plain text, not quoted values. Core
// rule 1 recommends exactly that pattern for text outputs, and it could
// not parse otherwise.
Templates bool
// LooseEquality for Expression V2 ==. The function reference says both
// operands must be the same type, so 5 == '5' is false.
LooseEquality bool
// ConditionLooseEquality for transition conditions. Conditions compare
// counts as $.n3.count != "0" while the context stores the number 0;
// those workflows run correctly in production, so the engine must treat
// them as equal.
ConditionLooseEquality bool
// Location for currentDate and friends. Maldives time unless set.
Location *time.Location
// Now is the clock. time.Now unless set; fix it in tests and fixtures.
Now func() time.Time
}
Policy holds the engine behaviours that the documentation describes but that have not yet been confirmed against recorded instances. Each field names the source it comes from. Replay against real runs (milestone 4) will either confirm the defaults or change them.
type Result ¶
type Result struct {
Value Value
Substituted string // the text the parser actually saw
Subs []Sub
Err error
}
Result is one evaluated Expression V2 output.
type Sub ¶
type Sub struct {
Ref string // path inside $.{...}
Found bool
Value Value
Rendered string // what went into the text
}
Sub records one reference replacement, for traces.
func Interpolate ¶
Interpolate fills references in plain text (task titles, SMS bodies, DataHub values): no quoting, and a missing value becomes blank, as on every control other than Expression V2.
type SyntaxError ¶
SyntaxError is a parse failure. In the live engine this fails the instance.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type Value ¶
Value is a value in an expression or in the workflow context.