dialect

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT, MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	TypeKindName     = "name"
	TypeKindList     = "list"
	TypeKindRange    = "range"
	TypeKindContext  = "context"
	TypeKindFunction = "function"
)

Type kinds of a TypeExpr, one per alternative of grammar rule 52.

View Source
const (
	TokenEOF               = "eof"
	TokenSpace             = "space"
	TokenCommentSingleLine = "comment/singleline"
	TokenCommentMultiline  = "comment/multiline"

	TokenName = "name"
	//TokenFuncall  = "funcall"
	TokenTemporal = "temporal"
	TokenString   = "string"

	TokenKeyword = "keyword"
	TokenNumber  = "number"
)
View Source
const (
	Prec = 34 * 8
)

Variables

View Source
var ErrDurationPrecision = errors.New("duration seconds finer than a nanosecond are not supported")

ErrDurationPrecision reports a days and time duration string in the DMN lexical form whose seconds are finer than a nanosecond.

View Source
var ErrDurationRange = errors.New("duration exceeds the supported range")

ErrDurationRange reports a duration string in the DMN lexical form whose value the fork cannot hold: a days and time duration longer than time.Duration's range (about 292 years), or a years and months duration over the int64 range of months.

View Source
var (
	ErrParseNumber = errors.New("fail to parse number")
)
View Source
var ErrParseTemporal = errors.New("fail to parse temporal value")
View Source
var ErrTimePrecision = errors.New("time seconds finer than a nanosecond are not supported")

ErrTimePrecision reports a time() second finer than a nanosecond: inside the built-in's domain, beyond what the fork can hold.

View Source
var ErrTimeZoneIDOnTime = fmt.Errorf("%w: a time cannot take a zone id whose offset varies by date; use an offset", ErrParseTemporal)

ErrTimeZoneIDOnTime reports a time string whose `@` zone id has more than one offset in its history, so a time of day alone cannot say which applies. It wraps ErrParseTemporal: time(from) yields null on it, and an at-literal naming it is a load error that says why.

VERDICT DIVERGENCE: DMN 1.5 does not say how a time, which has no date, takes its offset from a zone id whose rules depend on the date (§10.3.2.3.4). Resolving it at the evaluation's date would make one literal mean different instants in summer and winter, so the fork rejects it. A zone id with a single fixed offset (`UTC`, `Etc/GMT+5`) is unambiguous and accepted.

View Source
var ErrUnsupportedTimeZone = errors.New("time zone id not supported")

ErrUnsupportedTimeZone reports a time or date-and-time string in the DMN lexical form whose IANA zone id (`@Europe/Paris`) the fork cannot resolve. VERDICT DIVERGENCE: kept distinct from ErrParseTemporal so a conversion built-in raises on it instead of yielding null — the string is inside the domain, the fork is what falls short.

View Source
var Zero = N(0)

Functions

func Aggregate added in v0.4.0

func Aggregate(name string, list []any) (result any, ok bool)

Aggregate applies the §10.3.4.4 list aggregate name — count, min, max, sum, product, mean, median, stddev or mode — to list. ok is false only when name is not one of them; an argument outside the function's domain is a null result, never an error (§10.3.2.13.1).

It is the one implementation of these functions: the FEEL built-ins call it, and so may a decision table's COLLECT aggregation, which §10.3.2.10 defines through the same built-ins.

Empty lists follow Table 75: count is 0, mode the empty list, every other aggregate null. A list holding a null or a non-number is outside the domain of the arithmetic aggregates (sum, product, mean, median, stddev, mode), so they are null; count counts every item, null included; min and max follow extremum. Interpretation: Table 75 is silent on null items, and the TCK fixes only product([1,2,null,4]) = null (0094).

func CallFunction added in v0.4.0

func CallFunction(intp *Interpreter, fn any, args ...any) (any, bool, error)

CallFunction applies a FEEL function value to positional arguments under intp, so a call made from a built-in draws on the same iteration budget as the expression that invoked the built-in; a *FunDef's body resolves free names in the scope it was defined in (its closure, §10.3.2.13.2). ok is false when fn is not a function or does not take len(args) arguments; evaluation errors from the function's body are returned, as `sort` does.

VERDICT DIVERGENCE: fork-only; see NewNativeFuncI.

func CompareValues

func CompareValues(leftVal, rightVal any) int

func Equal added in v0.3.0

func Equal(a, b any) any

Equal implements FEEL's `=` for callers outside this package, and yields true, false or null. A pair the fork cannot compare at all (two functions) is false, as it is for valuesEqual and list membership.

VERDICT DIVERGENCE: upstream had no exported equality. pkg/feel used its own two-valued structural comparison for the ANY hit policy, unary-test equality and `duplicate values`, which disagreed with `=` on temporals and durations and could not say "unknown"; it now derives from this, so FEEL has one equality (DMN 1.5 §10.3.2.15, Tables 52 and 53).

func EvalString

func EvalString(input string) (any, error)

func EvalStringWithScope

func EvalStringWithScope(input string, scope Scope) (any, error)

func In added in v0.3.0

func In(leftVal, rightVal any) (any, error)

In implements FEEL's `e in container` for a range or a list container, or any other value as equality, and yields true, false or null. inOp evaluates its operands and delegates here.

VERDICT DIVERGENCE: upstream had no exported membership test. Verdict's unary-test layer (pkg/feel/unarytest.go) interprets a range or list cell as `? in cell` (DMN 1.5 §10.3.2.9, Table 49), and calling this rather than re-deriving membership keeps one implementation, so a decision-table cell and the `in` operator cannot disagree about a mixed-kind or unordered input.

func OrderValues added in v0.4.0

func OrderValues(leftVal, rightVal any) (int, bool)

OrderValues orders two values as `<` does and reports ok=false when FEEL defines no order between them (different kinds, such as a time and a date and time, or an unordered kind), where CompareValues would panic.

VERDICT DIVERGENCE: upstream exported only CompareValues. pkg/feel's Compare used it for any two temporals, which was safe while every temporal pair ordered; now that a time and a date and time do not (DMN 1.5 Table 54), it needs a form that reports the pair instead.

func ParseTemporalValue

func ParseTemporalValue(temporalStr string) (interface{}, error)

Types

type ArgSizeError

type ArgSizeError struct {
	// contains filtered or unexported fields
}

func (ArgSizeError) Error

func (self ArgSizeError) Error() string

type ArgTypeError

type ArgTypeError struct {
	// contains filtered or unexported fields
}

func (ArgTypeError) Error

func (self ArgTypeError) Error() string

type ArrayNode

type ArrayNode struct {
	Elements []Node
	// contains filtered or unexported fields
}

func (ArrayNode) Eval

func (arrNode ArrayNode) Eval(intp *Interpreter) (any, error)

func (ArrayNode) Repr

func (arrNode ArrayNode) Repr() string

func (ArrayNode) TextRange

func (arrNode ArrayNode) TextRange() TextRange

type Between added in v0.4.0

type Between struct {
	Expr Node
	Low  Node
	High Node
	// contains filtered or unexported fields
}

Between is `e1 between e2 and e3`, grammar rule 49.b.

func (Between) Eval added in v0.4.0

func (b Between) Eval(intp *Interpreter) (any, error)

Eval applies DMN 1.5 Table 55: `e1 between e2 and e3` is `e1 >= e2 and e1 <= e3`, inclusive at both ends. Each operand is evaluated once, then the two comparisons and the three-valued `and` are the ordinary operators, so incomparable or null operands give null exactly where the equivalent expression does: `"a" between 1 and 5` and `null between 1 and 5` are null, while `9 between null and 5` is `null and false`, which is false.

func (Between) Repr added in v0.4.0

func (b Between) Repr() string

func (Between) TextRange added in v0.4.0

func (b Between) TextRange() TextRange

type Binop

type Binop struct {
	Op    string
	Left  Node
	Right Node
	// contains filtered or unexported fields
}

Binop binary operator

func (Binop) Eval

func (binop Binop) Eval(intp *Interpreter) (any, error)

func (Binop) Repr

func (binop Binop) Repr() string

func (Binop) TextRange

func (binop Binop) TextRange() TextRange

type BoolNode

type BoolNode struct {
	Value bool
	// contains filtered or unexported fields
}

func (BoolNode) Eval

func (boolNode BoolNode) Eval(intp *Interpreter) (any, error)

Eval Evaluate bool node

func (BoolNode) Repr

func (boolNode BoolNode) Repr() string

func (BoolNode) TextRange

func (boolNode BoolNode) TextRange() TextRange

type DotOp

type DotOp struct {
	Left Node
	Attr string
	// contains filtered or unexported fields
}

DotOp function call

func (DotOp) Eval

func (dotop DotOp) Eval(intp *Interpreter) (any, error)

Eval is a path expression on a single value. DMN 1.5 §10.3.2.6 selects the entry named Attr from a context; a context without that entry has nothing to select, so the path is null (`{a: 1}.b` is null), and a path continuing from that null is null too (`{a: 1}.b.c`), as null propagates through every FEEL operator. A date, time, duration or range answers the properties Table 65 lists for its type; any other name on it, and any name on a value with no properties at all (`5.x`, `"abc".length`), selects nothing and is null — see selectProperty.

VERDICT DIVERGENCE: upstream raised "key not found" for a missing entry or attribute and "type mismatch, expect map" for a path on null or on a value with no attributes. See NOTICE.md.

func (DotOp) Repr

func (dotop DotOp) Repr() string

func (DotOp) TextRange

func (dotop DotOp) TextRange() TextRange

type EvalError

type EvalError struct {
	Code    int
	Short   string
	Message string
}

func NewErrBadInput

func NewErrBadInput(row int, column int, inputText string) *EvalError

func NewErrBadOp

func NewErrBadOp(leftType, op, rightType string) *EvalError

func NewErrIndex

func NewErrIndex(msg string) *EvalError

func NewErrKeyNotFound

func NewErrKeyNotFound(keyName string) *EvalError

func NewErrKeywordArgument

func NewErrKeywordArgument(argName string) *EvalError

NewErrKeywordArgument argument errors

func NewErrTooFewArguments

func NewErrTooFewArguments(required []string) *EvalError

func NewErrTooManyArguments

func NewErrTooManyArguments() *EvalError

func NewErrTypeMismatch

func NewErrTypeMismatch(expectType string) *EvalError

func NewErrUnknownArgument added in v0.4.0

func NewErrUnknownArgument(argName string) *EvalError

NewErrUnknownArgument is a named argument no parameter of the function has.

func NewEvalError

func NewEvalError(code int, short string, msgs ...string) *EvalError

func (EvalError) Error

func (evalError EvalError) Error() string

type EveryExpr

type EveryExpr struct {
	Varname    string
	ListExpr   Node
	FilterExpr Node
	// contains filtered or unexported fields
}

EveryExpr Every expression

func (EveryExpr) Eval

func (ee EveryExpr) Eval(intp *Interpreter) (any, error)

func (EveryExpr) Repr

func (ee EveryExpr) Repr() string

func (EveryExpr) TextRange

func (ee EveryExpr) TextRange() TextRange

type FEELDate

type FEELDate struct {
	// contains filtered or unexported fields
}

func ParseDate

func ParseDate(timeStr string) (*FEELDate, error)

func (*FEELDate) AddDuration added in v0.2.0

func (d *FEELDate) AddDuration(dur *FEELDuration) *FEELDate

AddDuration is date + duration. DMN 1.5 §10.3.2.15 (Table 57, date with a days and time or a years and months duration) evaluates it as the date of date and time(date, midnight) + duration, so a days-and-time duration moves whole days and drops any remainder of a day, and a years-and-months duration moves calendar months, pinning the day to the end of a shorter month.

func (FEELDate) Date

func (d FEELDate) Date() time.Time

func (FEELDate) GetAttr

func (d FEELDate) GetAttr(name string) (interface{}, bool)

GetAttr is the date row of DMN 1.5 §10.3.2.15 Table 65: `year`, `month`, `day` and `weekday` (see dateAttr).

func (FEELDate) MarshalJSON

func (d FEELDate) MarshalJSON() ([]byte, error)

func (FEELDate) String

func (d FEELDate) String() string

type FEELDatetime

type FEELDatetime struct {
	// contains filtered or unexported fields
}

FEELDatetime is a FEEL date and time. As for FEELTime, a zoneless value keeps its wall clock in t with the UTC location and hasOffset is false.

VERDICT DIVERGENCE: upstream read a zoneless date and time as UTC. DMN 1.5 §10.3.2.3.6: one without an offset is a local date and time, which has no UTC form; see FEELTime.

zoneID is as for FEELTime: t is then in the IANA location, whose rules give the offset at that date.

func MustParseDatetime

func MustParseDatetime(temporalStr string) *FEELDatetime

func ParseDatetime

func ParseDatetime(temporalStr string) (*FEELDatetime, error)

ParseDatetime parses a date and time string. An IANA zone id is resolved by its rules at that date and time, so `2026-01-01T10:00:00@Europe/Paris` is the instant `2026-01-01T09:00:00Z` (DMN 1.5 §10.3.2.3.6).

func (*FEELDatetime) Add

func (dt *FEELDatetime) Add(dur *FEELDuration) *FEELDatetime

Add is date and time ± duration (DMN 1.5 §10.3.2.15, Table 57); a negative duration subtracts. A years and months duration moves the calendar month and keeps the time of day and the location. Upstream built the result with time.Date, which normalises an out-of-range day forwards, so 2026-01-31 + P1M was 2026-03-03. The day is now pinned to the last day of the resulting month (2026-02-28), as XPath op:add-yearMonthDuration-to-dateTime does by the XSD 1.1 Part 2 Appendix E algorithm §9.4 names; see NOTICE.md. A days and time duration adds its exact length. Either way the result keeps the operand's offset, or its lack of one (Table 57 builds it from e1).

func (FEELDatetime) Compare

func (dt FEELDatetime) Compare(other FEELDatetime) int

func (FEELDatetime) Date

func (dt FEELDatetime) Date() time.Time

func (FEELDatetime) Equal

func (dt FEELDatetime) Equal(other FEELDatetime) bool

func (FEELDatetime) GetAttr

func (dt FEELDatetime) GetAttr(name string) (interface{}, bool)

GetAttr is the date and time row of DMN 1.5 §10.3.2.15 Table 65: the date components (dateAttr), `hour`, `minute`, `second` (a decimal, as for FEELTime), `time offset` and `timezone` (zoneAttr).

func (FEELDatetime) HasOffset added in v0.3.0

func (dt FEELDatetime) HasOffset() bool

HasOffset reports whether the date and time has a time offset or zone.

func (FEELDatetime) MarshalJSON

func (dt FEELDatetime) MarshalJSON() ([]byte, error)

func (FEELDatetime) String

func (dt FEELDatetime) String() string

String prints the date and time in its lexical form (see formatZoned): `2024-01-01T10:00:00`, `...Z`, `...+05:00` or `...@Europe/Paris`, so that date and time(string(dt)) is dt again.

VERDICT DIVERGENCE: upstream printed every offset through Go's `MST` layout, so `+05:00` printed as `@+0500` and `Z` as `@UTC`, neither of which is DMN's lexical form.

func (FEELDatetime) Time

func (dt FEELDatetime) Time() time.Time

type FEELDuration

type FEELDuration struct {
	Neg     bool
	Years   int
	Months  int
	Days    int
	Hours   int
	Minutes int
	Seconds int
	// Nanoseconds is the fraction of a second, 0 to 999999999.
	//
	// VERDICT DIVERGENCE: upstream held whole seconds only, so PT1.5S could
	// not be represented. A days and time duration's seconds are an
	// xs:decimal; the fork keeps them to the nanosecond, the resolution of
	// time.Duration and of every date and time it is added to.
	Nanoseconds int
	// contains filtered or unexported fields
}

func NewFEELDuration

func NewFEELDuration(dur time.Duration) *FEELDuration

NewFEELDuration carries a negative duration's sign in Neg and keeps every field non-negative, the form the parser produces for "-PT5H". Upstream left the sign in the fields (Hours: -5, Neg: false), so a negative Go duration or a negative date-and-time difference printed as "PT-5H" and survived abs and negation still negative.

The result is normalised (DMN 1.5 §10.3.2.3.7): days, hours under 24, minutes and seconds under 60, and the sub-second remainder, which upstream dropped. A zero duration is never negative.

func NewYearsMonthsDuration added in v0.3.0

func NewYearsMonthsDuration(months int64) *FEELDuration

NewYearsMonthsDuration is the normalised years and months duration of a signed month count (DMN 1.5 §10.3.2.3.8): P26M is P2Y2M, and zero months is P0M, a years and months duration, not PT0S.

func ParseDuration

func ParseDuration(temporalStr string) (*FEELDuration, error)

ParseDuration parses a days and time or a years and months duration string into its normalised value.

VERDICT DIVERGENCE: upstream capped each component (months at 12, hours at 24, minutes and seconds at 60) and raised over the cap, though xs:yearMonthDuration and xs:dayTimeDuration bound no component: P26M, PT36H and PT90M are valid. DMN 1.5 §10.3.2.3.7 and §10.3.2.3.8 normalise a duration so the sum of its components is minimised, so P26M is P2Y2M, PT36H is P1DT12H and P0DT25H is P1DT1H.

func (FEELDuration) Duration

func (duration FEELDuration) Duration() time.Duration

func (FEELDuration) GetAttr

func (duration FEELDuration) GetAttr(name string) (interface{}, bool)

GetAttr is the two duration rows of DMN 1.5 §10.3.2.15 Table 65: `years` and `months` for a years and months duration, `days`, `hours`, `minutes` and `seconds` for a days and time one, each the normalised component.

VERDICT DIVERGENCE: a property of the other kind is null, as Table 66 says of each ("returns null when invoked on a days and time duration value"), where upstream answered 0. It is not found either, since Table 65 does not list it for that kind, so `is defined(duration("P1D").years)` is false. **Interpretation:** a component carries the duration's sign (`duration("-P1Y2M").years` is -1, `.months` -2), as XPath F&O 3.1 §8.2 fn:years-from-duration and its siblings do; Table 66's intervals are silent on sign, and upstream returned the magnitude.

func (FEELDuration) IsYearsMonths added in v0.3.0

func (duration FEELDuration) IsYearsMonths() bool

IsYearsMonths reports whether the duration is a years and months duration (DMN 1.5 §10.3.2.3.8) rather than a days and time one (§10.3.2.3.7). A zero keeps the kind it was built with.

func (FEELDuration) MarshalJSON

func (duration FEELDuration) MarshalJSON() ([]byte, error)

func (FEELDuration) Negative

func (duration FEELDuration) Negative() *FEELDuration

func (FEELDuration) String

func (duration FEELDuration) String() string

type FEELTime

type FEELTime struct {
	// contains filtered or unexported fields
}

FEELTime is a FEEL time. A zoneless (local) time keeps its wall clock in t with the UTC location; hasOffset tells it apart from the same wall clock written with `Z`.

VERDICT DIVERGENCE: upstream had no hasOffset and read a zoneless time as UTC, so `time("10:00:00") = time("10:00:00Z")` was true and the two printed alike. DMN 1.5 §10.3.2.3.4: a time with an offset, 00:00 included, has a UTC form; one without is a local time of day whose relation to UTC is unknown. The operators use the flag as Tables 53, 54 and 57 require; see mixedZones in eval_binop.go.

zoneID is set when the offset came from an IANA zone id rather than being written out: the value then prints as `@zone-id` and has a `timezone`.

func ParseTime

func ParseTime(temporalStr string) (*FEELTime, error)

ParseTime parses a time string. A zone id whose offset varies by date is ErrTimeZoneIDOnTime.

func (*FEELTime) AddDuration added in v0.2.0

func (tm *FEELTime) AddDuration(dur *FEELDuration) *FEELTime

AddDuration is time ± days and time duration: valuet⁻¹(valuet(t) + valuedtd(dur)) (DMN 1.5 §10.3.2.15, Table 57), where valuet⁻¹ applies its argument modulo 86400 seconds (§10.3.2.3.4), so the result wraps within the day — 23:00:00 + PT2H is 01:00:00 — and keeps the time's offset, or its lack of one. The caller rules out a years and months duration, which Table 57 does not pair with a time.

func (FEELTime) GetAttr

func (t FEELTime) GetAttr(name string) (interface{}, bool)

GetAttr is the time row of DMN 1.5 §10.3.2.15 Table 65: `hour`, `minute`, `second`, `time offset` and `timezone` (see zoneAttr). VERDICT DIVERGENCE: `second` is a decimal (Table 66, "[0..60)"), so `time("10:00:00.5").second` is 0.5; upstream dropped the fraction.

func (FEELTime) HasOffset added in v0.3.0

func (t FEELTime) HasOffset() bool

HasOffset reports whether the time has a time offset or zone, rather than being a local time of day.

func (FEELTime) MarshalJSON

func (t FEELTime) MarshalJSON() ([]byte, error)

func (FEELTime) String

func (t FEELTime) String() string

String prints the time in its lexical form (see formatZoned): `10:00:00`, `10:00:00Z`, `10:00:00+02:00` or `10:00:00@Etc/UTC`, so that time(string(t)) is t again.

func (FEELTime) Time

func (t FEELTime) Time() time.Time

type ForExpr

type ForExpr struct {
	Varname    string
	ListExpr   Node
	ReturnExpr Node
	Continues  bool
	// contains filtered or unexported fields
}

ForExpr FOR expression. A `for` with several iteration contexts parses as nested ForExprs, one per context; every one but the innermost has Continues set, and its ReturnExpr is the next context's ForExpr.

func (ForExpr) Eval

func (fe ForExpr) Eval(intp *Interpreter) (any, error)

func (ForExpr) Repr

func (fe ForExpr) Repr() string

func (ForExpr) TextRange

func (fe ForExpr) TextRange() TextRange

type FunCall

type FunCall struct {
	FunRef Node
	Args   []funcallArg
	// contains filtered or unexported fields
}

func (FunCall) Eval

func (fc FunCall) Eval(intp *Interpreter) (any, error)

Eval invokes the function FunRef evaluates to.

VERDICT DIVERGENCE: upstream raised "type mismatch, expect function" when FunRef was not a function — a number (`5(1)`), null (`null(1)`), an unbound name (`nofn(a)`, a misspelt built-in) or a context entry holding a value (`{a: 1}.a(2)`). DMN 1.5 §10.3.2.13.2: "If f is not a function ... the result of the invocation is null". The arguments are not evaluated.

func (FunCall) EvalFunDef

func (fc FunCall) EvalFunDef(intp *Interpreter, funDef *FunDef) (any, error)

EvalFunDef invokes a user-defined function.

VERDICT DIVERGENCE: upstream raised on too few or too many arguments, and when the count matched it ignored a named argument no parameter had and bound the parameter it displaced to null, so `function(a, b)` called as `f(a: 1, z: 2)` ran with b null. DMN 1.5 §10.3.2.13.2: if the arguments do not conform to the argument list the result of the invocation is null; so a wrong count, or a name that is not a parameter, is null and the body is not run. An error evaluating an argument still propagates. So, too, is an argument that does not conform to its parameter's declared type (grammar rule 56; see FunDef.conformFrame).

func (FunCall) EvalMacro

func (fc FunCall) EvalMacro(intp *Interpreter, macro *Macro) (any, error)

EvalMacro binds a call's unevaluated arguments to a macro's parameters and calls it.

VERDICT DIVERGENCE: upstream raised on too few or too many arguments and on a missing keyword, and ignored a keyword no parameter had. DMN 1.5 §10.3.4 makes a built-in invoked outside its domain null, as EvalNativeFun does for native built-ins: so a standard (prelude) macro — `sort`, `is defined` — yields null for any of them, and an unknown keyword is a misfit too. An error raised by the macro itself, such as one from evaluating an argument or from inside a `sort` predicate's body, still propagates.

func (FunCall) EvalNativeFun

func (fc FunCall) EvalNativeFun(intp *Interpreter, funDef *NativeFun) (any, error)

EvalNativeFun binds a call's arguments to a native function's parameters and calls it.

VERDICT DIVERGENCE: upstream raised on a call whose arguments did not fit the parameters — too few, too many, a missing keyword — and ignored a named argument no parameter had, so `list replace(..., foo: 1)` ran as if foo were absent; a named variadic parameter (`count(list: [1, 2])`) was dropped. DMN 1.5 §10.3.4 makes a standard built-in invoked outside its domain null, and TCK 1140, 1145 and 1155 pin a wrong argument count and an unknown parameter name as null; §10.3.2.13.2 makes any invocation whose arguments do not conform to the parameters null, and an application function — which is how a BKM or decision service is invoked from FEEL — is "equivalent to a FEEL function". So every native function yields null for any of them, unknown names included. A named variadic parameter is passed through as its value. An error evaluating an argument, or raised by the function itself, still propagates.

func (FunCall) Repr

func (fc FunCall) Repr() string

func (FunCall) TextRange

func (fc FunCall) TextRange() TextRange

type FunDef

type FunDef struct {
	Args []string
	// ParamTypes holds the type declared on each parameter, parallel to Args
	// (DMN 1.5 grammar rule 56: parameter name [":" type]); an entry is nil
	// where none was declared, and the slice is nil when no parameter has a
	// type. An undeclared type is Any (§10.3.2.13.2).
	//
	// VERDICT DIVERGENCE: upstream did not parse parameter types. See
	// NOTICE.md.
	ParamTypes []*TypeExpr
	Body       Node
	// contains filtered or unexported fields
}

FunDef function definition

func (FunDef) Eval

func (fd FunDef) Eval(intp *Interpreter) (any, error)

Eval makes a function value that closes over the current scope. DMN 1.5 §10.3.2.13.2: FEEL(function(X1, ... Xn) body, s) is function(argument list, body, scope: s), and a call evaluates body in insert before(s, 1, c), c being the arguments — so a free name in the body resolves where the function was written, not where it is called. Only the stack's frame pointers are copied (one slice of len(ScopeStack)), never a frame's entries.

VERDICT DIVERGENCE: upstream kept only Args and Body, so a call resolved free names at the call site (dynamic scope). See NOTICE.md.

func (*FunDef) EvalCall

func (fd *FunDef) EvalCall(intp *Interpreter, args []any) (any, error)

EvalCall applies fd to positional arguments, as a built-in such as `sort` does. An argument that does not conform to its parameter's declared type makes the result null without running the body (§10.3.2.13.2).

func (FunDef) Repr

func (fd FunDef) Repr() string

func (FunDef) TextRange

func (fd FunDef) TextRange() TextRange

type HasAttrs

type HasAttrs interface {
	GetAttr(name string) (interface{}, bool)
}

type HasDate

type HasDate interface {
	Date() time.Time
}

type HasTime

type HasTime interface {
	Time() time.Time
}

type IfExpr

type IfExpr struct {
	Cond       Node
	ThenBranch Node
	ElseBranch Node
	// contains filtered or unexported fields
}

func (IfExpr) Eval

func (ifExpr IfExpr) Eval(intp *Interpreter) (any, error)

func (IfExpr) Repr

func (ifExpr IfExpr) Repr() string

func (IfExpr) TextRange

func (ifExpr IfExpr) TextRange() TextRange

type InstanceOf added in v0.4.0

type InstanceOf struct {
	Expr Node
	Type *TypeExpr
	// contains filtered or unexported fields
}

InstanceOf is `e instance of type`, grammar rule 51.

func (InstanceOf) Eval added in v0.4.0

func (io InstanceOf) Eval(intp *Interpreter) (any, error)

Eval applies DMN 1.5 Table 61: null when the type maps to no lattice node; true for a null value checked against `Null`; true when the value is not null and its type conforms to the type (§10.3.2.9.2); false otherwise. So `null instance of number` and `null instance of Any` are false.

func (InstanceOf) Repr added in v0.4.0

func (io InstanceOf) Repr() string

func (InstanceOf) TextRange added in v0.4.0

func (io InstanceOf) TextRange() TextRange

type Interpreter

type Interpreter struct {
	ScopeStack []Scope
	// MaxIterations is the iteration budget of one evaluation: the total
	// number of elements every iteration context of every for, some and
	// every may produce, nested and multi-context products included. Zero
	// means no budget, which is upstream's behaviour; the façade always sets
	// one. It is ignored when Budget is set.
	//
	// VERDICT DIVERGENCE: see NOTICE.md. The fork takes the budget as a
	// plain field rather than importing any Verdict configuration.
	MaxIterations int64

	// Budget, when set, is an iteration budget shared with other
	// evaluations — every expression of one Verdict request, including those
	// running concurrently on other goroutines. Charges go to it instead of
	// MaxIterations/iterations.
	//
	// VERDICT DIVERGENCE: see NOTICE.md.
	Budget *IterationBudget
	// contains filtered or unexported fields
}

func NewIntepreter

func NewIntepreter() *Interpreter

func (*Interpreter) Bind

func (i *Interpreter) Bind(name string, value any)

Bind the value to the name of current scope

func (Interpreter) Len

func (i Interpreter) Len() int

func (*Interpreter) Pop

func (i *Interpreter) Pop() Scope

func (*Interpreter) Push

func (i *Interpreter) Push(scp Scope)

func (*Interpreter) PushEmpty

func (i *Interpreter) PushEmpty()

func (Interpreter) Resolve

func (i Interpreter) Resolve(name string) (any, bool)

Resolve a name from the top of scopestack to bottom

func (Interpreter) Set

func (i Interpreter) Set(name string, value any) bool

Set the name and set to new value

func (Interpreter) String

func (i Interpreter) String() string

type IterationBudget added in v0.3.0

type IterationBudget struct {
	// Limit is the total number of elements the budget admits. Zero or
	// negative means no budget.
	Limit int64
	// contains filtered or unexported fields
}

IterationBudget is an iteration budget shared by several evaluations, possibly on different goroutines: every element any of them charges is drawn from one counter. Verdict creates one per request, so a business knowledge model invoked a thousand times from a `for`, or two sibling decisions evaluated in parallel, draw on the same budget rather than each starting afresh.

VERDICT DIVERGENCE: see NOTICE.md.

func NewIterationBudget added in v0.3.0

func NewIterationBudget(limit int64) *IterationBudget

NewIterationBudget returns a shared budget of limit elements.

func (*IterationBudget) Used added in v0.3.0

func (b *IterationBudget) Used() uint64

Used reports the elements charged so far.

type IterationBudgetExceededError added in v0.2.0

type IterationBudgetExceededError struct {
	Limit int64
}

IterationBudgetExceededError reports an evaluation whose iteration contexts would together produce more elements than Interpreter.MaxIterations allows, or than remain in its shared IterationBudget.

func (*IterationBudgetExceededError) Error added in v0.2.0

type IterationRange added in v0.2.0

type IterationRange struct {
	Start Node
	End   Node
	// contains filtered or unexported fields
}

IterationRange is the integer-range form of an iteration context, `name in Start .. End`, DMN 1.5 FEEL grammar rule 63. It is only ever the ListExpr of a ForExpr, SomeExpr or EveryExpr; a bare `a..b` is not an expression anywhere else.

func (IterationRange) Eval added in v0.2.0

func (ir IterationRange) Eval(intp *Interpreter) (any, error)

Eval yields the integers from Start to End inclusive, ascending or descending as the endpoints run, DMN 1.5 §10.3.2.14: `1..3` is [1, 2, 3] and `3..1` is [3, 2, 1]. The grammar requires both endpoints to be integers; any other endpoint, null included, is outside the semantic domain and the result is null, which the enclosing for, some or every turns into a null result of its own.

func (IterationRange) Repr added in v0.2.0

func (ir IterationRange) Repr() string

func (IterationRange) TextRange added in v0.2.0

func (ir IterationRange) TextRange() TextRange

type Macro

type Macro struct {
	// contains filtered or unexported fields
}

func NewMacro

func NewMacro(fn MacroDef) *Macro

func (*Macro) Help

func (self *Macro) Help(help string) *Macro

func (*Macro) Optional

func (self *Macro) Optional(argNames ...string) *Macro

func (*Macro) Required

func (self *Macro) Required(argNames ...string) *Macro

func (*Macro) Vararg

func (self *Macro) Vararg(argName string) *Macro

type MacroDef

type MacroDef func(intp *Interpreter, args map[string]Node, varArgs []Node) (interface{}, error)

type MapNode

type MapNode struct {
	Values []mapItem
	// contains filtered or unexported fields
}

func (MapNode) Eval

func (mapNode MapNode) Eval(intp *Interpreter) (any, error)

Eval builds a context literal. DMN 1.5 §10.3.2.6: an entry's value may refer to the entries before it in the same literal, so each finished entry is bound in a frame of its own before the next is evaluated. That frame sits above the caller's scope, so an entry shadows an outer variable of the same name, and nested literals see their enclosing literal's earlier entries. Upstream evaluated every entry against the outer scope alone, so `{c: 1, r: c}` gave r = null.

func (MapNode) Repr

func (mapNode MapNode) Repr() string

func (MapNode) TextRange

func (mapNode MapNode) TextRange() TextRange

type MultiTests

type MultiTests struct {
	Elements []Node
	// contains filtered or unexported fields
}

func (MultiTests) Eval

func (mt MultiTests) Eval(intp *Interpreter) (any, error)

func (MultiTests) Repr

func (mt MultiTests) Repr() string

func (MultiTests) TextRange

func (mt MultiTests) TextRange() TextRange

type NativeFun

type NativeFun struct {
	// contains filtered or unexported fields
}

func NewNativeFunc

func NewNativeFunc(fn NativeFunDef) *NativeFun

func NewNativeFuncI added in v0.4.0

func NewNativeFuncI(fn NativeFunDefI) *NativeFun

NewNativeFuncI is NewNativeFunc for an implementation that needs the interpreter — one that applies a function value argument through CallFunction, as `list replace(list, match, newItem)` does. Binding, overloads and the null rule for misfitting arguments are those of any native function.

VERDICT DIVERGENCE: upstream's NativeFun.Call dropped the interpreter, so only a Macro (which also loses argument binding) could call a function value; DMN 1.5 §10.3.4.4 defines `list replace` with a match function.

func (NativeFun) ArgNameAt

func (nativeFun NativeFun) ArgNameAt(at int) (string, bool)

func (*NativeFun) Call

func (nativeFun *NativeFun) Call(intp *Interpreter, args map[string]interface{}) (interface{}, error)

func (*NativeFun) Help

func (nativeFun *NativeFun) Help(help string) *NativeFun

func (*NativeFun) Optional

func (nativeFun *NativeFun) Optional(argNames ...string) *NativeFun

func (*NativeFun) Overloads added in v0.3.0

func (nativeFun *NativeFun) Overloads(signatures ...[]string) *NativeFun

Overloads declares the function's signatures, each a list of parameter names in order. A positional call binds the signature with as many parameters as it has arguments; a named call binds the signature whose names are exactly the ones given. The function body tells the overloads apart by which names are present.

VERDICT DIVERGENCE: upstream bound every argument by one parameter list, so a built-in could not have overloads whose parameters differ by name and position — DMN 1.5 §10.3.4.1 Table 72's date(from) and date(year, month, day), say — and named arguments could not reach them.

func (*NativeFun) Required

func (nativeFun *NativeFun) Required(argNames ...string) *NativeFun

func (*NativeFun) Vararg

func (nativeFun *NativeFun) Vararg(argName string) *NativeFun

type NativeFunDef

type NativeFunDef func(args map[string]interface{}) (interface{}, error)

NativeFunDef native function

type NativeFunDefI added in v0.4.0

type NativeFunDefI func(intp *Interpreter, args map[string]any) (any, error)

NativeFunDefI is a native function that also receives the interpreter evaluating the call, so it can apply a function value it was passed (see CallFunction).

VERDICT DIVERGENCE: fork-only; see NewNativeFuncI.

type Negation added in v0.2.0

type Negation struct {
	Operand Node
	// contains filtered or unexported fields
}

Negation implements FEEL's unary `-`, which upstream did not parse: a leading minus was only ever part of a numeric literal, so `-x` and `-(a + b)` were syntax errors. DMN 1.5 §10.3.2.15 defines negation over numbers and durations; anything else, null included, is null.

func (Negation) Eval added in v0.2.0

func (n Negation) Eval(intp *Interpreter) (any, error)

func (Negation) Repr added in v0.2.0

func (n Negation) Repr() string

func (Negation) TextRange added in v0.2.0

func (n Negation) TextRange() TextRange

type Node

type Node interface {
	Repr() string
	Eval(*Interpreter) (interface{}, error)
	TextRange() TextRange
}

func ParseString

func ParseString(input string) (Node, error)

type NullNode

type NullNode struct {
	// contains filtered or unexported fields
}

func (NullNode) Eval

func (nullNode NullNode) Eval(intp *Interpreter) (any, error)

func (NullNode) Repr

func (nullNode NullNode) Repr() string

func (NullNode) TextRange

func (nullNode NullNode) TextRange() TextRange

type NullValue

type NullValue struct {
}

func (NullValue) Equal

func (self NullValue) Equal(other NullValue) bool

func (NullValue) MarshalJSON

func (self NullValue) MarshalJSON() ([]byte, error)

type Number

type Number struct {
	// contains filtered or unexported fields
}

func N

func N(v interface{}) *Number

func NewNumber

func NewNumber(strn string) *Number

func NewNumberFromFloat

func NewNumberFromFloat(input float64) *Number

func NewNumberFromInt64

func NewNumberFromInt64(input int64) *Number

func ParseNumberWithErr

func ParseNumberWithErr(v interface{}) (*Number, error)

func (*Number) Add

func (n *Number) Add(other *Number) *Number

func (*Number) BigFloat added in v0.4.0

func (n *Number) BigFloat() *big.Float

BigFloat is a copy of the number's value at the working precision, for arithmetic the fork does not provide itself (Verdict's sqrt, log, exp, odd and even in pkg/feel/stdlib.go). VERDICT DIVERGENCE: upstream exposed the value only through Float64, Int64 and String, which lose digits.

func (*Number) Cmp

func (n *Number) Cmp(other *Number) int

func (Number) Compare

func (n Number) Compare(other Number) int

func (*Number) Div

func (n *Number) Div(other *Number) *Number

Div divides at the evaluator's working precision. It is the implementation behind FEEL's `/`; callers must reject a zero divisor first.

func (Number) Equal

func (n Number) Equal(other Number) bool

func (Number) Float64

func (n Number) Float64() float64

func (*Number) FloatDiv

func (n *Number) FloatDiv(other *Number) *Number

func (Number) Int

func (n Number) Int() int

func (Number) Int64

func (n Number) Int64() int64

func (*Number) IntDiv

func (n *Number) IntDiv(other *Number) *Number

func (*Number) IntMod

func (n *Number) IntMod(other *Number) *Number

func (*Number) IsZero

func (n *Number) IsZero() bool

IsZero reports whether the number is exactly zero.

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

func (*Number) Mul

func (n *Number) Mul(other *Number) *Number

func (*Number) Pow added in v0.2.0

func (n *Number) Pow(other *Number) (*Number, bool)

Pow raises n to the power other. It reports false when the result is not a finite number: a zero base with a negative exponent, a negative base with a fractional exponent, or an overflow. (VERDICT DIVERGENCE: upstream had no exponentiation; see NOTICE.md.)

func (Number) String

func (n Number) String() string

String prints the number rounded to 34 significant digits as a plain decimal, never in exponent form, with trailing fractional zeros and a trailing point trimmed: 10 is "10", 1.50 is "1.5", 10 ** -40 is "0.0000000000000000000000000000000000000001". Zero, negative zero included, is "0".

func (*Number) Sub

func (n *Number) Sub(other *Number) *Number

type NumberNode

type NumberNode struct {
	Value string
	// contains filtered or unexported fields
}

func (NumberNode) Eval

func (numberNode NumberNode) Eval(intp *Interpreter) (any, error)

Eval Evaluate Number node

func (NumberNode) Repr

func (numberNode NumberNode) Repr() string

func (NumberNode) TextRange

func (numberNode NumberNode) TextRange() TextRange

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(scanner *Scanner) *Parser

func (Parser) CurrentToken

func (p Parser) CurrentToken() ScannerToken

func (*Parser) Parse

func (p *Parser) Parse() (Node, error)

func (Parser) Unexpected

func (p Parser) Unexpected(expects ...string) *UnexpectedToken

type Prelude

type Prelude struct {
	// contains filtered or unexported fields
}

func GetPrelude

func GetPrelude() *Prelude

func (*Prelude) Bind

func (self *Prelude) Bind(name string, value interface{}) *Prelude

func (*Prelude) Load

func (self *Prelude) Load()

func (*Prelude) Resolve

func (self *Prelude) Resolve(name string) (interface{}, bool)

type RangeNode

type RangeNode struct {
	StartOpen bool
	Start     Node

	EndOpen bool
	End     Node
	// contains filtered or unexported fields
}

func (RangeNode) Eval

func (rangeNode RangeNode) Eval(intp *Interpreter) (any, error)

func (RangeNode) Repr

func (rangeNode RangeNode) Repr() string

func (RangeNode) TextRange

func (rangeNode RangeNode) TextRange() TextRange

type RangeValue

type RangeValue struct {
	StartOpen bool
	Start     any

	EndOpen bool
	End     any
}

func (RangeValue) Contains

func (rv RangeValue) Contains(p any) bool

func (RangeValue) GetAttr added in v0.4.0

func (rv RangeValue) GetAttr(name string) (interface{}, bool)

GetAttr is the range properties of DMN 1.5 Table 65: `start` and `end` are the endpoints, `start included` and `end included` whether each end is closed. `[1..5).end included` is false.

VERDICT DIVERGENCE: upstream gave a range no properties, so `[1..5].start` raised "type mismatch, expect map". See NOTICE.md.

func (RangeValue) HasNullEndpoint added in v0.2.0

func (rv RangeValue) HasNullEndpoint() bool

HasNullEndpoint reports whether either endpoint is null. A literal such as `[null..10]` has no defined start, and DMN 1.5 §10.3.2.15 makes every ordering comparison against it null, so membership in it, and every range built-in over it, is null rather than an answer computed from upstream's ordering of null below every value. The fork builds ranges only from range literals (`< 10` is a comparison, not a range), so a null endpoint here always came from the model, never from an internal encoding of an unbounded interval.

func (RangeValue) Position

func (rv RangeValue) Position(p any) (int, error)

Position and Contains are the `in` operator's (see In); the range built-ins use the three-valued within instead.

type ScanPosition

type ScanPosition struct {
	Row    int
	Column int
}

ScanPosition is a 0-based row and column in the scanned text; Column counts characters (runes), not bytes.

func (ScanPosition) String added in v0.3.0

func (pos ScanPosition) String() string

String is the position as a modeller reads it: 1-based, "line 2, column 3".

VERDICT DIVERGENCE: upstream printed the raw 0-based pair ("at 0 0"), which read as an unset position for an error at the start of an expression and was off by one everywhere else.

type Scanner

type Scanner struct {
	Pos   ScanPosition
	Eaten int
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(input string) *Scanner

func (Scanner) Current

func (scanner Scanner) Current() ScannerToken

func (*Scanner) Next

func (scanner *Scanner) Next() error

func (*Scanner) Tokens

func (scanner *Scanner) Tokens() ([]ScannerToken, error)

Tokens Find all tokens

type ScannerToken

type ScannerToken struct {
	Kind  string
	Value string
	Pos   ScanPosition
}

func (ScannerToken) Expect

func (token ScannerToken) Expect(tokenKinds ...string) bool

func (ScannerToken) ExpectKeywords

func (token ScannerToken) ExpectKeywords(words ...string) bool

func (ScannerToken) IsOp

func (token ScannerToken) IsOp() bool

type Scope

type Scope map[string]interface{}

type SomeExpr

type SomeExpr struct {
	Varname    string
	ListExpr   Node
	FilterExpr Node
	// contains filtered or unexported fields
}

SomeExpr some expression

func (SomeExpr) Eval

func (sexpr SomeExpr) Eval(intp *Interpreter) (any, error)

func (SomeExpr) Repr

func (sexpr SomeExpr) Repr() string

func (SomeExpr) TextRange

func (sexpr SomeExpr) TextRange() TextRange

type StringNode

type StringNode struct {
	Value string
	// contains filtered or unexported fields
}

func (StringNode) Content

func (stringNode StringNode) Content() string

func (StringNode) Eval

func (stringNode StringNode) Eval(intp *Interpreter) (any, error)

func (StringNode) Repr

func (stringNode StringNode) Repr() string

func (StringNode) TextRange

func (stringNode StringNode) TextRange() TextRange

type TemporalNode

type TemporalNode struct {
	Value string
	// contains filtered or unexported fields
}

func (TemporalNode) Content

func (tempNode TemporalNode) Content() string

func (TemporalNode) Eval

func (tempNode TemporalNode) Eval(intp *Interpreter) (any, error)

func (TemporalNode) Repr

func (tempNode TemporalNode) Repr() string

func (TemporalNode) TextRange

func (tempNode TemporalNode) TextRange() TextRange

type TextRange

type TextRange struct {
	Start ScanPosition
	End   ScanPosition
}

type TypeExpr added in v0.4.0

type TypeExpr struct {
	Kind string
	// Name is the qualified name of a TypeKindName.
	Name string
	// Elem is the parameter of a list or range type.
	Elem *TypeExpr
	// Keys and Fields are a context type's entries, in order.
	Keys   []string
	Fields []*TypeExpr
	// Params and Result are a function type's signature.
	Params []*TypeExpr
	Result *TypeExpr
}

TypeExpr is a parsed FEEL type, grammar rule 52: a qualified name, or one of the parameterised types `list<T>`, `range<T>`, `context<k: T, …>` and `function<T, …> -> T`.

func (*TypeExpr) Repr added in v0.4.0

func (t *TypeExpr) Repr() string

Repr is the type as FEEL spells it.

type UnexpectedToken

type UnexpectedToken struct {
	// contains filtered or unexported fields
}

func NewUnexpectedToken

func NewUnexpectedToken(token ScannerToken, callers []string, expects []string) *UnexpectedToken

func (UnexpectedToken) Callers

func (self UnexpectedToken) Callers() []string

Callers returns the parser frames captured when the error was raised.

func (UnexpectedToken) Error

func (self UnexpectedToken) Error() string

VERDICT DIVERGENCE: Error() no longer appends the parser's Go call stack. The message reaches a modeller through a VERDICT_LOAD_013 diagnostic about a cell in their decision table, and ten frames of dialect.(*Parser) internals there are noise that obscures the one line they can act on. The stack is still captured; Callers exposes it for debugging this package.

type Var

type Var struct {
	Name string
	// contains filtered or unexported fields
}

Var variable

func (Var) Eval

func (v Var) Eval(intp *Interpreter) (any, error)

func (Var) Repr

func (v Var) Repr() string

func (Var) TextRange

func (v Var) TextRange() TextRange

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL