expr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 21 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

Overview

Package expr reads and evaluates the OpenJD EXPR extension's expression language.

The package is a leaf with respect to internal/openjd: its only intra-openjd import is internal/openjd/intrange, a leaf shared between the two (see the intrange bullet below). internal/openjd and internal/worker/fmtres import expr, so expr can be tested with no template machinery present.

Usage

e, err := expr.Parse("Param.Frame * 2")
v, err := e.Eval(expr.MapSymbols{"Param.Frame": expr.Int(21)}, expr.TAny)
// v.String() == "42"

Parse reports syntax errors; Eval reports evaluation errors. Both return an *Error carrying a byte offset into the source, rendered as a line and column, so a template author can see which part of an expression failed.

Behavior and rulings

This package implements the spec's full type system: a recursive Type with all sixteen type codes (the Recommended Library Interface's Type Codes table; section 1.2.1 itself lists twelve rows and omits any, noreturn and the type variables), automatic coercion between them (section 1.2.3), and static type checking against placeholders for values that do not exist yet (section 1.3.1's unresolved[T]). "Param.Frame + 1" type-checks to unresolved[int] before any parameter has a value, and "Param.Name + 5" is rejected as a type error the same way, with Param.Name declared but still unbound. Every literal form, list literals included, dotted names and the full ten-level operator grammar are implemented on top of that type system. Several behaviors look like bugs when tried by hand and are intended:

  • "1 + 2.5" evaluates to 3.5, and "1 < 2.5" to true: section 2.1.1's int-to-float promotion is implemented, and an operator is selected by trying an exact-type match first and a promoting one second. Promotion only uses a conversion that cannot fail on any value (int-to-float, path-to-string, range_expr-to-string, range_expr-to-list[int]), never one that can, such as string-to-int. That is why "'a' + 1" is an error rather than "a1": section 1.2.3's single-scalar catch-all conversion applies when a context (a target type, a coercion) demands a specific type and is prepared for the value not to fit, not when the language is choosing which operator overload to run. "true + true" is an error for the same reason: no shape accepts (bool, bool), and bool has no promoting route into one that does.

  • Equality and ordering differ in how far they reach across types. Section 1.2.5 defines equality for every pair of types, so "5 == 5.0" is true and "'5' == 5" is false; equality never fails. A list or range_expr value follows the same cross-type rule: "[1, 2] == [1.0, 2.0]" is true, and a range_expr compares equal to the list of integers it expands to. Section 2.1.4 permits ordering to cross only two named compatible pairs, int/float and string/path; every other cross-type comparison is an error, so "5 < 'a'" fails with "unsupported operand types" while "5 == 'a'" evaluates to false. List ordering (lexicographic, section 1.2.5) reaches across element types by those same two pairs, applied elementwise: "[1] < [1.0]" is false, and so is "[[1]] < [[1.0]]" one level down, while "['a'] < [1]" stays an "unsupported operand types" error because string/int is not one of the pairs. That composes section 1.2.5 (list ordering is elementwise and says nothing about the elements' types) with section 2.1.4 (an ordering operator's operands "may differ for compatible pairs"). The unification happens during shape matching (shape.go's orderingUnified), so both operands are coerced to the common element type before any element is compared. Ordering also reaches the empty list, in either operand position and at any nesting depth: section 1.2.6 rule 6 makes list[nulltype] convertible to list[T] for any T, so "[] < [1]" is true, "[1] < []" is false, and "[[]] < [[1]]" and "[[1]] < [[]]" answer the same way one level down. The empty literal's binding of the shared element-type variable is provisional (shape.go's emptyListBinding), and the exception applies in both directions (an empty binding meeting a real argument, and a real binding meeting an empty argument), which is what makes the orders agree.

  • List literals, subscripts and slices are implemented, and list[T] has real values. A literal with no target type infers its element type from its own elements per section 1.2.6's unification rules; a list[T] target instead coerces every element to T directly. "x[0]" and "x[1:3]" work on a list, a string or a range_expr (sections 2.1.7 and 2.1.8); a subscript is bounds-checked and errors out of range, while a slice clamps like Python. Both also work on a union of those, which this package produces itself: slicing a range_expr whose length is not yet known is typed "range_expr | list[int]", and section 1.3.1's unknown-condition rule types a conditional as the union of both branches. Every member is indexed and the results combined, so "Param.Range[:][0]" is an int and "([1, 2] if Param.Flag else [3.0])[0]" a float; the operation is rejected only when some member cannot be indexed. list[T] also has its own operators: concatenation ("+"), repetition ("*" by an int, section 2.1.3) and membership ("in"/"not in"), plus list comprehensions (section 1.3.7), described in the next bullet.

  • List comprehensions (section 1.3.7) parse and evaluate: "[x for x in [1, 2, 3] if x > 1]". The loop variable follows the section's shadowing rule ("a loop variable that shadows an existing binding is an error"), checked against the caller's symbol table (comp.go's evalListComp), on top of the parser's <UserIdentifier> casing rule that already keeps a loop variable from colliding with a spec-defined symbol like Param. This package carries no scope information of its own, so the shadowing check is only as precise as the table it is handed: a caller that binds a name not in scope at this expression produces a false rejection. internal/openjd's checkTemplateExpressions hands it a per-position table built from section 3.6.2's scope model, so a step's own "let" is visible in its own script but not in a sibling step's (internal/openjd/exprcheck_let_test.go). The iterable and the filter are both parsed at the or level (parser.go's parseOr), not as the full <ConditionalExpr> section 1.1.2's grammar names for them, because that grammar is ambiguous there: parseConditional consumes a bare "if" expecting an "else", so "[x for x in y if c]" would fail looking for one. A conditional in either position therefore needs parentheses ("[x for x in (a if b else c)]"), which is how Python resolves the same ambiguity (comp_for and comp_if both take an or_test). A string is not iterable: the spec never defines iterating one, and section 2.1.2 gives "in" over a string a different meaning, a substring test, so "[c for c in 'abc']" is a "cannot be iterated" error. A union iterable follows the rule a subscript and a slice apply to a union receiver: it is iterable only when every member is, with the members' element types unified per section 1.2.6. So "range_expr | list[int]" is iterable as int, while "list[int] | nulltype" and "range_expr | list[string]" are rejected. An empty iterable produces "[]" with the element expression never evaluated, and therefore never type-checked: "[Bogus for i in Param.Empty]" is "[]", not an unknown-symbol error. The spec requires no static check of a body that never runs, and the reference implementation answers the same way. Each rejected with its own parser error: a second "for" clause and a second "if" filter (Python's multi-generator and multi-filter forms) and a generator expression ("(x for x in y)"). A dict or set comprehension ("{k: k for k in y}", "{x for x in y}") is rejected in the lexer: "{" is not a token this grammar defines. Nesting one comprehension inside another's element expression multiplies the inner work by the outer iteration count at every level, the same growth "[[0]*10000000]*10" has. checkElementCount (limits.go's maxElements) bounds one comprehension's result, not the cumulative work of producing every nested level; section 1.3.10's operation limit bounds that: runComp (comp.go) charges rule 2 for every element the comprehension iterates, at every nesting level, so the multiplied work spends against the same operation budget as the rest of the expression and the limit fires before it runs away (TestOperationLimit_CatchesANestedComprehension). See the bounded evaluation bullet below for the limits themselves.

  • Function, method and property calls parse and resolve ("len([1])", "[1,2].upper()" and "Param.Name.stem") through the registry functionShapes (funcs.go, assembled by mergeFuncs), which holds 80 entries: general conversions (len, bool, string, int, float, list, range_expr; funcsconv.go); validation (fail, in the same file but its own RFC 0006 category); math (abs, min, max, sum, floor, ceil, round; funcsmath.go); list functions (range, flatten, sorted, reversed, unique, any, all; funcslist.go); the string library, across four files: case transforms and classification (upper, lower, capitalize, title, isdigit, isalpha, isalnum, isspace, isupper, islower, isascii; funcsstrcase.go), trim, affix and search/replace (strip, lstrip, rstrip, removeprefix, removesuffix, startswith, endswith, count, find, rfind, index, rindex, replace; funcsstrfind.go), split, rsplit and join (funcsstrsplit.go) and padding (ljust, rjust, center, zfill; funcsstrpad.go); regular expressions (re_match, re_search, re_findall, re_sub, re_escape, re_split; funcsre.go, over its own translated dialect in repattern.go, see the regex rulings below); repr_* (repr_sh, repr_cmd, repr_pwsh in funcsreprshell.go, and repr_py, repr_json in funcsreprdata.go, see the repr_* rulings below); the path engine, all of it in funcspath.go over the three-flavor pure-path engine in pathval.go: construction and predicates (path, as_posix, is_absolute), the six properties, registered under their __property_*__ spellings and so six of the 80 (__property_name__, __property_stem__, __property_suffix__, __property_suffixes__, __property_parent__, __property_parts__), the with_* family and the relative pair (with_name, with_stem, with_suffix, is_relative_to, relative_to), and with_number, whose substitution scanner lives in pathnumber.go; and apply_path_mapping, registered from its own pathMappingFuncs group beside the engine it wraps (pathmapping.go) rather than from pathFuncs, because it is the one function in the registry that reads session state, the path-mapping rules WithPathMapping threads through evalCtx (see the path mapping bullet below). Section 2.1.5's "/" and "+" path operators are operator-table rows (ops.go), not registry entries, so they are not among the 80.

    Section 2.2's library of roughly 100 functions is entirely registered. An unknown call fails at runtime with "unknown function", not a parse error: "no_such_function('/mnt/share')" reports `unknown function "no_such_function"`. (The example names something that is not a library function; a real library name would demonstrate a different mechanism. "with_suffix('/foo/bar.txt', '.png')" reports `no signature of "with_suffix" accepts (string, string)` (overload selection), and "apply_path_mapping('/mnt/share')" returns the path "/mnt/share".) Not every call reaches the registry: a dunder callee like "__add__(1, 2)" is rejected before lookup with "is a specification naming convention and is not directly callable", and a callee whose whole dotted name resolves to a symbol ("Param.Name()" when Param.Name is bound) fails "Param.Name is not a function".

    The six classification predicates other than isascii, and title() and capitalize(), have the semantics of the Python str methods of the same name over the Unicode Character Database (RFC 0006 §2.2.4's two notes). Three consequences are easy to mistake for bugs. isdigit('٣') and isdigit('²') are true (Numeric_Type Decimal or Digit) even though int() accepts neither, so isdigit is not a guard for int(). isalnum is broader than isalpha || isdigit: it admits any Numeric_Type, so isalnum('½') is true while isalpha('½') and isdigit('½') are both false. And title() starts a word after any uncased character, so title('a1b c') is "A1B C" and title('1st') is "1St", and both title() and capitalize() titlecase rather than uppercase a word's first character: capitalize('fine day') is "Fine day". The Go standard library has no Numeric_Type or Case_Ignorable table; funcsstrcase.go carries the data it needs. Results can differ from CPython 3.14 on code points whose Unicode 16 data postdates Go's Unicode 15 tables, which the specification permits.

    Uniform function call syntax (section 1.3.3) makes "x.f(a)" resolve through the same callFunction as "f(x, a)", with the receiver prepended to the argument list, except that section 1.2.4 suppresses implicit coercion on a method receiver (callFunction's methodStyle). The registry shows it: round's single-argument row is declared over TFloat alone, so "round(3)" resolves in function position by promoting the int argument to float (returning the int 3, since that row returns int), while "Param.N.round()" with Param.N bound to the same int fails with "no signature of \"round\" accepts (int)", because the receiver never gets the promotion the argument position receives. TestReceiverCoercionRestriction (call_internal_test.go) uses the spec's own worked example, startswith(path, string), against startswith in funcsstrfind.go: a path receiver must fail to coerce into its (string, string) signature. [].len() and len([]) both resolve and both return 0 (TestLen_EmptyListReceiver) because there is nothing for the restriction to restrict: binding list[T]'s unbound element variable T to nulltype (the empty literal's own type) converts no value, and section 1.2.4 suppresses a coercion on the receiver, which binding a type variable is not. The restriction applies to a property receiver as well (resolve.go's evalProperty passes methodStyle): section 1.3.3 defines "x.p" as method syntax over "__property_p__", and section 1.2.4 suppresses coercion on the receiver of a method call, so a property's receiver is not coerced either. For the path engine's properties this makes "Param.S.stem" on a string parameter an error instead of a silent string-to-path conversion; the reference implementation agrees ("'/a/b.txt'.stem" reports "'stem' property is not available for string. Available for: path"). TestPropertyReceiverCoercionRestriction pins it with a path receiver against a "(string)" property signature registered locally by the test, the only receiver type where the flag is observable: every other type that reaches a string parameter does so by a conversion overload selection would refuse anyway. Property syntax is sugar for a call to __property_p__, dispatched through the same registry, so a property access to a name nothing has registered fails through the same unknown-function mechanism, reworded to "unknown property" (resolve.go's evalProperty) so that a runtime error inside a property that does exist is never relabeled as a missing one. "Param.Name.nosuchprop" (Param.Name bound to a string) reports `unknown property "nosuchprop" on string`, not `unknown function "__property_nosuchprop__"`. "Param.Name.stem" on that same string receiver takes the other branch: __property_stem__ exists, so it reports `no signature of "__property_stem__" accepts (string)`, the receiver-restriction message. A dotted name that reaches a method or property call is split by longest-prefix resolution against the caller's symbol table (resolve.go's resolveName): "Param.Name.upper()" tries "Param.Name.upper" as a bound symbol first, then "Param.Name", stopping at the first prefix the caller's table binds. This package hardcodes no namespaces of its own (the caller's table is authoritative, as it is for the comprehension shadowing check above), so a caller that binds both "a.b" and "a.b.c" gets "a.b.c" resolved to the symbol rather than to a property "c" of "a.b". The type-variable codes (CodeVarT and friends) and the matcher's binding of them live in shape.go; the list[varT] rows (len(), bool(), string()'s list row, and flatten(), sorted(), reversed() and unique() from the list-function group) bind that variable for polymorphic signatures.

    Five regular-expression and repr_* rulings look like bugs when tried by hand and are intended. RFC 0006 defines none of them precisely enough to settle by reading alone; each is compared with Go's regexp package, Python's re module and the reference implementation, and recorded in test/oracle/baseline.txt where it diverges from the reference.

    The accepted regex dialect is narrower than the reference's. RFC 0006 defines the dialect as "the intersection of Python's re module and Rust's regex crate", and sqi enforces that stated rule rather than only the spec's explicit list of rejected constructs, so re_search('3', r'\p{Nd}'), re_search('ab', r'(?<n>a)b') and re_search('a', r'[[:alpha:]]') are all rejected, although the reference accepts all three. Python's re module rejects \p{Nd} ("bad escape \p") and (?<n>a) ("unknown extension ?<n") outright, as sqi does, but it does not reject [[:alpha:]]: it reads the bracket expression literally, as a class holding '[', ':', 'a', 'l', 'p', 'h' followed by a literal ']', so "a" alone does not match it and "a]" does. sqi refuses to compile the pattern; Python compiles it into something that matches almost nothing anyone intended. That disagreement between the two engines is why RFC 0006 excludes POSIX classes from the intersection.

    \W and \S inside a negated character class are rejected, a stated compliance gap: re_search('a!', r'[^\Wa]') errors with "\W inside a negated character class needs set subtraction, which Go's engine cannot express", because "not a word character, minus 'a'" is set subtraction and RE2 (which backs Go's regexp, and the reference's own engine) has no operator for it. The reference does not reject this pattern but returns null (no match) for every input, which is not a well-formed reading of the dialect either; see test/oracle/baseline.txt. Inside a positive class the same shorthand works, by rewriting the class into an alternation rather than emitting it in place (re_search('a!', r'[\Wa]') matches), and a class may hold any number of \W/\S occurrences this way, each distinct shorthand becoming its own alternation branch (scanClass, classNeedsAlternation).

    \d, \w and \s are Unicode-aware, unlike Go's ASCII-only defaults: every pattern is translated by translatePattern (repattern.go) before it reaches Go's engine, and that translation is what makes them Unicode. re_search('٣', '\d') matches the Arabic-Indic digit ٣, which Go's own \d does not.

    repr_sh and repr_py follow the Python functions RFC 0006 names them after, shlex.quote and repr, which produce different text from the reference implementation for the same input: repr_sh("it's") is 'it'"'"'s' here (shlex.quote's close-quote/literal-quote/reopen-quote splice) and "it's" there (a different, shell-safe, quoting strategy); repr_py("it's") is "it's" here (Python repr()'s quote-switching rule: prefer a single quote, switch to double when the string holds a single quote and no double) and 'it\'s' there (always single-quote, escape instead of switching). repr_sh's difference is textual only: both forms are shell-equivalent and safe, which is why funcsreprshell.go lives apart from the serialization functions in funcsreprdata.go (see its own comment). Both divergences are baselined in test/oracle/baseline.txt as the reference's bug: RFC 0006 names the Python function, and sqi's output is what that function produces.

    repr_json does not share writeJSONValue, string()'s list-rendering helper (funcsconv.go): string(list) and repr_json differ on non-ASCII input, in the reference too. string(['café']) is ["café"] (non-ASCII left literal, as the reference does) while repr_json('café') is "caf\u00e9" (ASCII-only output with a four-hex-digit escape, Python's json.dumps default ensure_ascii behavior, which the reference also follows). RFC 0006 calls string()'s list row "the JSON string representation" with no ensure_ascii qualification and separately names repr_json after json.dumps, whose default is ensure_ascii=True: two specified behaviors in two functions.

  • flatten()'s row order matters; listFuncs (funcslist.go) is the first table in the package where it does. "flatten([[1],[2]])" matches both its nested row (list[list[T]] -> list[T]) and its flat row (list[T] -> list[T]) at cost 0, since [[1],[2]] is a list[list[int]] (T = int) and also a list[T] with T = list[int]; matchShapesExactFirst breaks an exact-cost tie to the earliest registered shape. The nested row is listed first for that reason: reversing the two would make flatten() the identity on every argument, with no type error to catch it.

  • path and range_expr exist as types: TPath and TRangeExpr participate in Type, coercion and cross-type equality, and a declared parameter can be typed as either. path has no literal syntax of its own, but a value is produced by evaluation: string -> path is section 1.2.3's own coercion rule, so Eval(src, syms, expr.TPath) returns a path value for any expression that evaluates to a string. path has semantics of its own on top of that (its three flavors, its URI awareness, its properties and functions, and section 2.1.5's "/" and "+"), described in the path engine bullet below; apply_path_mapping has the path mapping bullet to itself. range_expr has no operator of its own beyond what coercion gives it. The range_expr -> list[int] conversion (section 1.2.3) is implemented (coercing a range_expr value to a list[int] target expands it), and so is section 1.2.5's list/range_expr cross-type equality rule. What coercion gives a range_expr operand is narrow, by ruling: section 1.2.3's range_expr -> string rule reaches a string parameter only for the operators whose own tables name a range_expr row, which is "+" alone. Sections 2.1.2 and 2.1.3 write those rows out explicitly, and would not need to if the coercion fired on its own during overload selection. So "Param.Range + '!'" concatenates as text, while "Param.Range * 2" and "'1' in Param.Range" are "unsupported operand types" errors, not the string repetition "1-101-10" or a substring test over "1-10". The reference implementation rejects both as well.

  • range_expr has real values, and range_expr() (funcsconv.go) constructs one. Its value is its list of values, and its string form is the canonical form of Template Schemas §3.4.1.1.1 (openjd-specifications #202): runs of a constant difference taken greedily from the left, so range_expr("1-10:2") is "1-9:2", range_expr("1,3,5,7") is "1-7:2", and every path that writes one as text (interpolation, string(), "+", the repr_* functions) agrees. When the elements' spans are disjoint, intrange.Canonical computes it from their arithmetic progressions without listing the values, so a billion-value range costs what a three-value one does. Overlapping elements are listed up to canonicalOverlapBound values; past that the text keeps its written form (rangeexpr.go). A CHUNK[INT] task parameter's value also keeps the text it was given (TaskParamType types it range_expr): RFC 0005 §1.2.2 gives a chunk its own string form, "<N>-<M>" for a contiguous chunk even with one or two values, so ValueFromText binds it as written, while a range_expr computed from it (a slice, range_expr(string(...))) is canonical.

  • The path engine implements three flavors, every path property and function RFC 0006 defines, and section 2.1.5's "/" and "+" operators. apply_path_mapping has the path mapping bullet below to itself, because its source matching is not this engine's path equality. A path value here is pure (no filesystem is touched, nothing is resolved or stat'ed) and normalized by construction, because Value.Path re-parses its text. That is what makes RFC 0006 line 767's guarantee, path(p.parts) == p, hold for every shape, and it is why "/" and "+" re-normalize their results where the reference implementation stores the joined text raw.

    path_format is an evaluation option (WithPathFormat, eval.go), not a property of the host, and its default here is POSIX, which differs from the specification's default of host-native. sqi parses templates on the server, so a host-derived default would let one template expand into different tasks depending on which machine submitted it; the spec names POSIX as what template scope wants, "to ensure consistent behavior regardless of the submission machine's OS", and template parsing is that scope. PathNative resolves to the running GOOS; internal/worker/fmtres selects it for host-context evaluation on the worker. With no option, path('C:/a') renders "C:/a" and its is_absolute() is false (a drive letter means nothing to POSIX), while WithPathFormat(PathWindows) gives "C:\a" and true.

    A URI is not a flavor. It is detected from the text under every path_format, by the spec's scheme grammar, and a URI normalizes nothing: consecutive slashes, "." segments and a trailing slash all survive, because a URI path component is an opaque identifier and "a//b" and "a/b" may name different objects in a store. path('s3://bucket/a//b/./c') renders back verbatim under both filesystem flavors, and its parts are ["s3://bucket", "a", "", "b", ".", "c"]: the empty component and the "." are real components, where a POSIX or Windows path would collapse both.

    "+" on a path returns a path. RFC 0006's section 2.1.5 table declares __add__(path, string) with a path return, so "path('/a/b') + 'c'" is the path "/a/bc". path + path reaches that same row through section 1.2.3's path -> string coercion at cost 1, beating the (string, string) row at cost 2, so it is typed path too; the reference types it string, and the divergence is baselined. A caller that wants a string result must ask for one (a string target, or string()).

    The rulings below look like bugs when tried by hand and are intended. Each is adjudicated against third_party/openjd-specifications/ and, where it diverges from the reference, recorded case by case in test/oracle/baseline.txt, which is the place to check an individual row.

    Path comparison is byte-exact and case-sensitive for every flavor, Windows included. path('C:/A') == path('c:/a') is false here under WithPathFormat(PathWindows); CPython's PureWindowsPath casefolds and answers True. The specification is silent, and the reference agrees with sqi. The reason is the same as for the POSIX path_format default: an expression evaluated on the server must not answer differently because of a host convention, and a case-folding equality would make two templates that differ only in the case of a path literal expand into the same tasks on one flavor and different tasks on another.

    as_posix is flavor-aware: it replaces the flavor's own separator with "/", so it is the identity under POSIX and on a URI, and a "\" -> "/" rewrite only under Windows. path('/renders/shot_a\b.exr').as_posix() is therefore unchanged. An unconditional backslash rewrite would contradict this engine's own values: under POSIX a backslash is an ordinary filename character, so that path's parts are ["/", "renders", "shot_a\b.exr"] and its name is "shot_a\b.exr", while such a rewrite answers "/renders/shot_a/b.exr", a different path with different parts. It would also rewrite a URI object key ("s3://bucket/a\b" to the different key "s3://bucket/a/b"), contradicting the rule that a URI normalizes nothing. CPython settles the direction: PurePath.as_posix() is str(self).replace(self.parser.sep, '/'), and RFC 0006 line 857 names as_posix among the functions that "match Python's pathlib API", the same clause that settles stem/suffix below. The reference does the unconditional rewrite and has the same contradiction (its parts keep the backslash too), so this is a baselined divergence, argued case by case in test/oracle/baseline.txt.

    with_number replaces the last match, per RFC 0006 line 822: "searches the filename stem from the end for these patterns and replaces the last match". A match is one bounded run of one placeholder kind (a printf specifier, a '#' run, a digit run), not everything from where a run starts to the end of the stem, so "##a3" holds two candidates and only the digits are replaced: with_number('##a3', 7) is "##a7". The reference lets a '#' run swallow the remainder of the stem and answers "07", destroying the literal "a" the caller wrote, which contradicts its own specification's wording. Do not change sqi to match it; corpus.txt also carries the rows where the two agree, so an overcorrection fails there.

    stem, suffix and suffixes follow current CPython pathlib, which strips the whole leading dot run before splitting (and therefore treats a trailing dot as a suffix); the reference implements the older rule, which guarded only a single leading dot. So path('a.').stem is "a" with suffix "." and suffixes ["."], and path('/a/..b').stem is "..b" with no suffix. The same splitStemSuffix backs with_stem, with_suffix and with_number, so the rule reaches those too. RFC 0006 says "matches Python pathlib.PurePath behavior" and links the current documentation, which settles it in favor of the current rule.

    A trailing empty component on the base of relative_to/is_relative_to is consumed. Section 2.1.5 rules that "a trailing slash on the left operand is consumed by the join (matching pathlib behavior)", and the base of these two functions is an operand of that kind, so an operator-written prefix like "s3://renders/" must match the objects under it. Parsing preserves an empty component verbatim (Expression-Language lines 754-755), the URI rule above. Together the two rules produce a result that looks like a bug: path('s3://b//') == path('s3://b') is false (their parts differ: ["s3://b", "", ""] against ["s3://b"]), and yet each is relative to the other and relative_to returns "." in both directions. Equality compares the parsed values; relative_to consumes a boundary run on the base before comparing. The reference consumes the same run everywhere the receiver has something after the base, and then does not consume it in the self case, which makes its answers internally inconsistent.

    The oracle evaluates the reference under POSIX only (scripts/expr-oracle.py pins PathFormat.POSIX), so it does not adjudicate the Windows flavor: under POSIX the reference accepts a backslash as a replacement name, and never switches on a drive even for a drive-looking receiver like "C:/a/b". Every Windows expectation in this engine is therefore pinned by this package's own unit tests against CPython's PureWindowsPath, not by make test-expr-oracle, and the corpus carries no Windows-flavor case. URI behavior is covered by the oracle, because a URI is detected under POSIX too.

    Three smaller divergences, each recorded beside the code that produces it:

    The "\\?\UNC\" extended-length prefix is not parsed. pathlib gives that one literal prefix its own start-at-offset-8 parsing, splitting a further server+share out of what follows, so "\\?\UNC\srv\share\x" is one opaque root plus "x" to Python; here it runs through the ordinary offset-2 UNC algorithm and comes out with root "\\?\UNC\" and "srv", "share", "x" as ordinary components. That is a different split, not only a different rendering, and the only extended-length or device shape known to diverge (a plain "\\?\a\b" or "\\.\a\b" agrees with CPython). Reserved device names ("NUL", "CON") are not special-cased either, and neither are they by pathlib's pure paths. See parseWindows.

    path('//srv/share/x') / '//srv/share' anchors here, giving "\\srv\share\", where CPython keeps the parent's "x" and answers "\\srv\share\x". sqi follows section 2.1.5, which says an absolute right operand replaces the left entirely, and "//srv/share" is_absolute() is true in both engines. The mechanical cause is that splitRootWindows also ports pathlib's root-synthesis heuristic, which ntpath.splitroot does not have, so a complete server+share pair carries a root here and the join's anchor arm fires. See pathJoin.

    A URI scheme is at least two characters, per the specification's ^[a-zA-Z][a-zA-Z0-9+.-]+:// , so "C://scenes/a.ma" is a filesystem path (a Windows drive with a doubled separator) under every path_format, never a URI with scheme "c". See splitURI.

  • Path mapping. apply_path_mapping runs over a prefix-mapping engine local to this package (pathmapping.go's mapPath). It is registered flat, resolvable in every scope, from its own pathMappingFuncs group rather than from pathFuncs, because it is the only function in the registry that reads session state: the rules WithPathMapping (eval.go) threads through evalCtx.

    With no rules it passes its input through, normalized as a path value in the evaluation's flavor: apply_path_mapping('/mnt/share') evaluates with no option to the path "/mnt/share". "Passthrough" names the mapping outcome (no rule rewrote the text), not a verbatim string return: the result is always re-parsed by boundedPath in ec.pathFormat, so apply_path_mapping('/a//b/') is the path "/a/b" and apply_path_mapping('/a/b') under WithPathFormat(PathWindows) is "\a\b". That normalization is required: the vendored fixture expr2.3.2--apply-path-mapping's output_windows line for its POSIX_UNMAPPED case expects a slash-shaped input that matched no rule to come back with Windows separators, which happens only because the passthrough is re-parsed. internal/worker/fmtres supplies the session's rules through WithPathMapping. Rules are tried in order of decreasing SourcePath length and the first match wins, so the more specific rule wins whatever order the caller listed them in: with "/a" -> "/short" listed before "/a/b" -> "/long", apply_path_mapping('/a/b/c') is "/long/c".

    A WINDOWS source matches case-insensitively and separator-insensitively, unlike the path engine's equality. Path equality (==) and relative_to/is_relative_to compare components byte-exactly and case-sensitively on every flavor including Windows (the path engine bullet above explains why). The contrast is with those operations only: the / operator folds case, because pathJoin (pathval.go) compares the two operands' drives with strings.EqualFold, as ntpath.join does, so path('C:/a') / 'c:b' keeps the parent and gives "c:\a\b", where path('C:/a') / 'd:b' discards it and gives "d:b" (both under WithPathFormat(PathWindows)). That drive test is the only case-insensitive comparison the path engine makes, and the package's only strings.EqualFold outside pathmapping.go. Source matching is a different operation from path equality, and the two answers disagree on the same pair of paths: a WINDOWS rule whose SourcePath is `C:\studio` maps 'c:/STUDIO/project/scene.ma', while path('C:/Studio') == path('c:/studio') is false and is_relative_to(path('C:/Studio/a'), path('c:/studio')) is false, both under WithPathFormat(PathWindows). The insensitivity is confined to the rule comparator (applyFileRule passes strings.EqualFold to relativeParts, otherwise the same function is_relative_to uses); a POSIX rule does not casefold, so a "/Projects" rule leaves '/projects/a.exr' untouched.

    Its parameter is a string and its result is a path, which makes the section 1.2.4 receiver restriction visible: the result chains, so apply_path_mapping('/projects/shot01/out.exr').stem is "out", but a path receiver is refused (path('/projects/a').apply_path_mapping() reports `no signature of "apply_path_mapping" accepts (path)`), because a method receiver is not coerced. Both are pinned by TestApplyPathMapping_ResultChainsButAPathReceiverIsRefused. Two calls therefore do not compose directly; ask for a string in between.

    It has no oracle coverage: the reference's evaluation entry points that scripts/expr-oracle.py calls accept no host context, so there is no channel for session mapping rules, and no case in test/oracle/corpus.txt names this function. Everything above is pinned by unit tests in this package, as the path engine's Windows semantics are.

    Some of those unit tests carry the specification's expectations rather than sqi's own reading. The conformance suite ships three fixtures written against apply_path_mapping: EXPR/jobs/expr2.3.2--apply-path-mapping.test.yaml and its --uri-source-path-mapping-posix and --uri-source-path-mapping-windows siblings, carrying 31 expected strings across their expected.output/output_posix/output_windows blocks, rules included. The scored harness does not read them: collectTemplateFixtures (test/conformance/suite_test.go) keeps only the job_templates and env_templates kinds and skips job-execution fixtures, which need a live session runtime. They are transcribed into TestApplyPathMapping_VendoredFixtureExpectations (35 assertions; the four flavor-independent ones run under both formats), the only external check this function has.

    sqi has two path-mapping implementations. internal/worker/pathmap does a strings.ReplaceAll substring swap anywhere in a command string; this engine matches a prefix on component boundaries and rebuilds the remainder in the destination flavor. They serve different jobs, and this leaf package cannot import that one.

    Host-context enforcement is not here. RFC 0006 makes apply_path_mapping valid only in host-context (@fmtstring[host]) scopes and an error anywhere else; this package has no scope model to enforce that with, and internal/openjd's checker does (exprcheck.go's hostOnlyFunctions).

  • Bounded evaluation implements the specification's two configurable resource limits, section 1.3.9's memory-bounded evaluation and section 1.3.10's operation-bounded evaluation, both through meter.go.

    Two options, on by default, with no unlimited mode. WithMemoryLimit(bytes) bounds the live memory, in bytes, that one evaluation's values hold at once; it defaults to 100,000,000. WithOperationLimit(ops) bounds the number of section 1.3.10 operations one evaluation may perform; it defaults to 10,000,000 (meter.go). Both apply with no option passed, so a caller that forgets the option is not left unbounded. A non-positive value to either option is a caller error, reported by Eval: WithMemoryLimit(0) and WithOperationLimit(-1) both fail with "... must be positive, got ...".

    The floor. limits.go's five hard, non-configurable bounds (maxElements, maxStringBytes, maxParseDepth, maxEvalDepth and maxSourceBytes, described in the hard-bound bullet below) sit underneath these two configurable ones and are not raised by them: raising WithMemoryLimit does not raise what one operation may allocate. Evaluating "'a' * 20000000" under WithMemoryLimit(1_000_000_000) still fails, with the same error as with no option: "col 5: the result is too large: repeating 1 elements 20000000 times exceeds the limit of 10000000", with errors.Is(err, errTooLarge) true and errors.Is(err, errMemoryLimit) false. checkRepeat's maxStringBytes ceiling (limits.go) is checked before any WithMemoryLimit accounting sees the string.

    Limits are per Eval, not per template. Each call to Expression.Eval (and Eval, EvalWithMetrics, EvalForBalanceCheck, which route through it) starts a fresh meter with its own budget; nothing here accumulates a total across the expressions evaluated for one template. The cumulative, template-wide budget is internal/openjd's (exprcheck.go's templateBudget).

    Unresolved operands. A dispatched call whose argument is still unresolved (the type-check path taken before a parameter is bound to a value) charges section 1.3.10 rule 1 only, the single operation for the call itself (call.go's callFunction, plus three mirroring sites in ops.go: binary, unary and the fast-path equality check; four unresolved-operand charge sites in all). Rules 2 and 3 do not apply: the call was dispatched, but no list was iterated and no string was processed, because nothing downstream of the unresolved operand ran. The reference implementation has no comparable unresolved-operand evaluation path to compare against.

    Rule 2's enumeration is open. The two specification documents disagree about it, and it is settled here once so that the package cites one reading:

    wiki/2026-02-Expression-Language.md lines 1080-1087 introduces rule 2's function list with "such as", an open enumeration. rfcs/0005-expression-language.md lines 1173-1182 introduces the same list with "This applies to:", read literally a closed one.

    The ruling is open, on four grounds. (1) The wiki page is the specification for this package (see the closing note at the bottom of this file); RFC 0005 is the proposal that produced it, and where the two disagree the specification governs. (2) Both documents state the same operative sentence first ("When a function or the evaluator iterates through every element of a list, the number of elements is added to the operation count"), and both introduce rule 3's parallel list with "and similar", the RFC included. A closed rule 2 beside an open rule 3, on two rules of identical construction, is not a reading either document argues for. (3) A closed reading makes rule 2's words "or the evaluator" inoperative for anything unnamed: no evaluator-performed iteration except the list comprehension is in the enumeration, and the comprehension is listed separately because the evaluator, not a function, performs it, so the general clause must reach further than the list or it says nothing. (4) A closed reading defeats the rule's stated purpose: five constructs that do O(receiver) work would be charged a flat 1, so an expression like "len([range_expr('1-1000000')[0] for x in range(500)])" would do millions of elements of work for about 2,000 counted operations.

    What the open reading does not license. It is not a mandate to charge everything: each row still answers whether the work is element-count-dominated or byte-scan-dominated, and whether the implementation provably does that work. split() stays uncharged for rule 2 because its work is byte-dominated; "not", unary minus and unary plus stay uncharged because they touch no list and no string; min/max's fixed-arity 2- and 3-argument overloads stay uncharged because they take no list-typed parameter. Being unnamed by the enumeration is not a reason to charge nothing, and being named is not required to charge.

    Five constructs do O(receiver) work and are charged for it. Each expands or decodes its whole receiver inside a single call, and each is charged as the slice form of the same expression is:

    subscript of a string receiver (list.go's evalIndex) — indexValue does []rune(recv.AsStr()), decoding every byte of the receiver to find rune boundaries. Charges rule 3 on the receiver, before the decode: a 500,000-byte receiver costs 1,954, not 1. subscript of a range_expr receiver (same) — indexValue calls rangeInts, which fully expands. Charges rule 2 on the receiver's element count, from rangeExprCount (arithmetic for a single sub-range, a bounded expansion for two or more): a 1,000,000-element receiver costs 1,000,001, not 1. "in"/"not in" with a range_expr container (ops.go) — containsRangeInt calls rangeInts. Cost{ArgElements: {1}}, index 1 being the container, matching the string and list rows beside it. min() and max() over a range_expr (funcsmath.go) — both bodies are byte-identical rangeInts calls, and both charge Cost{ArgElements: {0}}, as sum()'s range_expr row one table over does for the same body.

    A subscript of a list stays at a flat 1: AsList returns the backing slice with no copy (value.go), so a list subscript touches one element and iterates nothing. The receiver-kind split is the same one slice.go's sliceValue makes, matching the asymmetry the implementations have.

    List ordering charges its walk, like list equality. "[...] < [...]" and "[...] == [...]" run the same compareLists/valuesEqual walk over the same operands. Rule 2 names "list/range equality comparisons" by token and does not name ordering, but under the open reading the general sentence covers both, and charging only equality would let a large list compared many times under "<" cost a small fraction of the identical "==" expression. orderingShapes' list/list row declares Cost{ArgElements: {0}}, charging the left operand as applyBinary's equality path does. The four scalar ordering rows charge rule 1 only; they iterate nothing.

    Counting rulings. Where sqi's operation counter and the reference's diverge on a corpus case, the case is adjudicated and recorded in test/oracle/baseline-ops.txt, grouped under root-cause families (its "# ── " section headers enumerate them; that file is where to check one entry). Most are the reference over-counting by a flat +1 on operators RFC 0005's AST-transformation table routes around section 1.3.10 rule 1 rather than through a function call (ordering, equality, "not", "and"/"or", the ternary, "in"/"not in"), adjudicated as the reference's bug. A second class is the two pricing the same call differently (string(list), the repr_* family, unique()'s per-comparison charge, see below), or sqi charging nothing where the reference charges (round(x, ndigits>0), min/max's fixed 2- and 3-arg rows), each argued from the RFC 0006 text in that file's section for it.

    The section 1.3.10 worked example's arithmetic is wrong. The specification states 'a' * 100000 costs 393 operations; the correct total is 392: ceil(100000/256) is 391 (256*390 = 99840, leaving 160), plus 1 for the repetition call. EvalWithMetrics("'a' * 100000", nil, TString) reports 392, as the reference implementation does. The rule (meter.go's ceilDiv256) is right; only the specification's addition is off, and meter.go records the correction beside the function.

    Value.String() and string(list) render a list identically, quoting and escaping included. openjd-specifications#176 requires format-string interpolation to use "this same conversion" as string() and the result to "parse as JSON"; Go's spelling of a control character (\x01, and \a/\v for two JSON does not name) is not JSON. Both renderers call funcsconv.go's jsonQuoteElement, so they agree for every input. TestValueString_VersusStringFunction checks thirteen cases (an embedded double quote, non-ASCII, angle brackets and an ampersand, a newline, a backslash, tab, backspace, formfeed, carriage return, an emoji, U+2028/U+2029, and the empty string), and TestValueString_ListQuotingIsJSONEverywhere pins six more where strconv.Quote and encoding/json disagree (the C0 controls, vertical tab, DEL and invalid UTF-8). The separator differs from internal/openjd's canonical storage form ("," there, ", " here), and paramjson.go states that difference where it lives.

    unique() charges per comparison, not per element. A registry-level Cost{ArgElements: {0}} charge prices only the input length, while unique's work is quadratic: unique(range(20000)) runs on the order of 4*10^8 valuesEqual comparisons. uniqueList (funcslist.go) is an FnCtx function charging one operation per valuesEqual comparison, and the charge fires before the comparison it prices, so the limit stops the quadratic work while it is in progress (TestUnique_IsBoundedByTheOperationLimit).

    The top-level coercion is metered. coerceTop (eval.go), which every public entry point (Expression.Eval, Eval, EvalWithMetrics, EvalForBalanceCheck) runs on the whole expression's result, releases the pre-coercion value and allocates the coerced result with WithMemoryLimit's bound checked. Coercion (coerce.go) can turn a small live range_expr into an arbitrarily large list[int]; unmetered, that materialization would be bounded only by the fixed maxElements floor (10,000,000 elements, roughly 640MB at 64 bytes a value).

    Untrusted expressions. With both limits on by default (TestOperationLimit_*, TestMemoryLimit_* and TestUnique_IsBoundedByTheOperationLimit), this package may be handed untrusted expressions, with three residuals: the fixed floor (limits.go) still bounds what a single operation may allocate, unchanged by either configurable limit; maxParseDepth and maxSourceBytes guard parsing, a phase no evaluation-time budget can reach, so what a hostile expression may spend before the first operation charge is whatever those two hard bounds allow; and limits are per Eval, so a template with many expressions gets one independent budget per expression evaluated (the cumulative per-template budget is internal/openjd's).

    None of it bounds parsing. Every limit named in this bullet (the two configurable ones, the floor beneath them, the template-wide budget internal/openjd layers on top and the deadline below) is consulted from two places, meter.charge and meter.reserve, and both run during evaluation. Parse runs first: tokenize builds the entire token slice and the parser the entire tree before any budget exists to be spent. maxParseDepth does not help, because it bounds recursive-descent stack frames and a flat left-associative chain is read in a loop; a multi-megabyte "1+1+1+…" expression would parse into hundreds of megabytes of tokens and nodes, and an expired deadline would not stop it, since nothing reads the clock during the parse. maxSourceBytes (limits.go, 10,000 bytes, checked at the top of Parse before tokenize) closes it: it is the one bound in this package that applies before evaluation begins. It is a 4xx verdict, not a 503: a source that is too long is a deterministic property of the template, so it reaches a caller as an ordinary parse error (a ValidationError through internal/openjd) rather than through ErrDeadlineExceeded.

    The wall-clock deadline (WithDeadline) is a bound of a different shape. Everything above bounds work: bytes held, operations performed, elements built, nesting depth. None of them bounds time, and they cannot: section 1.3.10 prices 256 bytes at one operation, so '("x" * 900000).title()' spends about 7,000 of a 10,000 operation budget while doing far more CPU work than that count suggests, and a request that stays inside every budget above can still run for minutes. WithDeadline(t) sets an absolute wall-clock instant after which evaluation stops. The zero time, the default, means no deadline and reads no clock.

    It differs from every other bound here in three ways:

    (1) It is wall-clock, and therefore non-deterministic. The same template on the same input breaches it on a loaded host and not on an idle one. Every other bound in this section is a function of the expression alone.

    (2) It is per request, not per Eval. The option takes an absolute time rather than a duration so that one deadline spans the many evaluations a template walk performs; a per-evaluation duration would let each of hundreds of positions spend the whole allowance. That is also why meter.charge checks it on the first charge of every evaluation and not only on the interval: a template built entirely from cheap expressions must still stop, and each of those expressions gets a fresh meter.

    (3) A breach means the server gave up, not that the template is invalid. Every other bound here is a verdict about the expression, and a caller is right to reject the submission (422). ErrDeadlineExceeded is exported, and distinct from every budget error, so that a caller can tell the two apart with errors.Is rather than by reading a message, and report it as a transient server condition (503).

    Precedence, when a single charge breaches both: the operation limit wins. meter.charge checks it first: the deterministic verdict is the more useful one, and reporting an over-budget template as a transient server condition would invite a client to retry something that can never succeed (TestDeadline_OperationLimitBeatsTheDeadline). meter.reserve orders the two the same way.

    It is a backstop, not a budget, and its granularity is coarse. The clock is sampled, on the first charge and every deadlineCheckInterval (1024) charges thereafter, because charge is the hot path of every expression and a time.Now() on each call taxes evaluations that are nowhere near a deadline. So the guarantee is "the deadline plus at most one evaluation's remaining operation budget": up to 1023 further charge calls may run, each of them potentially a bulk operation, and the call count is held to the operation budget only because a charge that prices bulk work adds at least one operation to it. meter.reserve narrows the worst of that window by checking unconditionally, with the count in hand, immediately before each large materialization, so the single biggest construction inside the window never starts. The rest of the window is not closed here.

  • A union target that names a value's own type exactly admits it unchanged, list types included: Eval("[1.0, 2.0]", nil, expr.UnionOf(expr.ListOf(expr.TFloat), expr.ListOf(expr.TInt))) returns the list rather than failing with "list[float] cannot be coerced to list[float] | list[int]". coerce() (coerce.go) checks satisfaction first (a value whose type the target already admits is returned unchanged), comparing whole types rather than type codes, since a code-only test cannot tell a list[int] from a list[string] inside a union. Do not conflate that with coercible(), which answers a different question: whether an implicit conversion rule carries a type to the target while a function call is being resolved. coercibleToTarget answers the target-type question under RFC 0005's coercion rules, so the two disagree on purpose (coerce.go).

    nulltype is the one case where satisfaction and coercible() coincide: coercible(nulltype, to) reports true whenever `to` admits null (coerce.go), because there is no separate null-to-something conversion rule to ask about, only whether the target's union names null. coercible(nulltype, "string?") is true because the target admits it; TestCoercible's nulltype rows pin this, alongside the negative boundary ("nulltype does not reach a union that does not name null") showing the rule still checks target membership.

  • A hard, fixed bound (limits.go's maxElements and maxStringBytes, both 10,000,000) applies to any list, string or range_expr this package produces, whether by repetition ("'x' * 3", "[0] * 3") or by concatenation ("'a' + 'b'", "[1] + [2]"). Both producers are checked on both types; without the string-concatenation check, a chain of individually legal repetitions can grow many times past the bound. A third bound, maxParseDepth (500), applies before any value exists: the parser's recursive descent is depth-limited, because exhausting the Go stack is a runtime.throw that recover() cannot catch, and a 200,000-deep list literal would kill the process rather than return an error. Every recursion cycle in the descent is counted, not only the entry production: parsePower reads its exponent through parseUnary, and parseUnary falls through to parsePower, so an unguarded cycle would let "2**2**2**…" a million operators long kill the process (parser.go's enter carries the full enumeration). A fourth bound, maxEvalDepth (10,000), does the same for evaluation, which the parse guard cannot cover: a left-associative run like "true or true or …" or "1 + 1 + …" is built by a loop, so it costs the parser no recursion and passes maxParseDepth however long it is, while the left-deep tree it produces is then walked recursively by evalNode, which would overflow the stack at a few hundred thousand operators without the bound. A fifth bound, maxSourceBytes (10,000 bytes), applies earlier than any of them, at the top of Parse before tokenize reads a byte, because the four above leave the parse unmetered: a flat chain passes maxParseDepth for the reason the fourth bound's sentence gives, and reaches maxEvalDepth only after every byte has been tokenized and turned into nodes. It bounds source length rather than node count; see limits.go for why, and for the headroom over real templates (the largest expression in any vendored fixture, sample or preset is 99 bytes). None of the five is the spec's configurable memory and operation limits (sections 1.3.9 and 1.3.10), which are a separate mechanism, covered in the bounded evaluation bullet above. The five bounds here stop one operation from allocating unbounded memory, stop the parser and the evaluator from overflowing the stack, and stop one expression's source from being large enough that reading it costs hundreds of megabytes, a narrower job than the configurable limits, which stop a pathological expression from doing unbounded total work across many operations. The one remaining walk over a parsed tree, ast.go's walk, which Expression.Names uses, needs no bound: it is iterative, with an explicit stack, so its Go stack depth is constant however deep the tree is. Names returns []string with no error channel, and a tree that parsed cannot fail to be walked.

  • A float literal in expression source does not preserve the text it was parsed from: "1.100" evaluates to a value that renders as "1.1", not "1.100". Value.String is a rendering for diagnostics and tests, not section 1.3.4's pass-through, and no producer sets the literal path's carry. Value has an optional rendered form (value.go's fs field, exported construction via FloatText), set by round(x, ndigits) for a positive ndigits because RFC 0006 requires round(3.5, 2) to render "3.50", a form no float64 carries on its own (TestRound_CarryIsRoundOnlyAndDoesNotPropagate), and by ValueFromText (paramtypes.go) for the other half of section 1.3.4: a FLOAT job parameter's submitted text, which sqi has verbatim because parameters are stored as map[string]string. internal/openjd's phase-2 concreteJobParamValue (exprcheck.go) and the worker both bind through it, so Param.<name> for a submitted "3.500" carries that text and Value.String reports it. internal/worker/fmtres renders phase-3 values onto a real command line, and pins that a submitted "3.500" arrives as 3.500 through both plain substitution and repr_py. Value.String quotes a list's string elements as string()'s JSON row (funcsconv.go) does; the bounded evaluation bullet above states how far the two renderings agree.

  • Nothing here touches a job template. Parsing a template, binding its parameters, and interpolating an expression's result back into template text are all outside this package; it evaluates expression text handed to it directly.

  • Section 1.1.5's escape table is narrower than its opening claim that "all Python escape sequences are supported": \a, \b, \f, \v, \0, octal escapes and a backslash-newline line continuation are absent from the table, so this package keeps them verbatim, backslash included, rather than decoding them: "'\a'" evaluates to the two characters "\a". This follows the table over the prose.

A target type propagates into a sub-expression from exactly four node kinds, and nowhere else. The rule is not visible from outside the package, so it is spelled out here:

Cond, the chosen branch (or both, under an unknown condition)  forwards the target
Logical ("and"/"or"), both operands                            forwards the target
ListLit, each element (through listElemTarget)                 forwards the target
ListComp, the element expression (through listElemTarget)      forwards the target
ListComp, its iterable; its filter                             always TAny; always TBool
Unary / Binary / Compare, all operands                         always TAny instead
Index / Slice, the receiver being indexed or sliced             always TAny instead
Index's own index; Slice's start/stop/step                     always TInt instead
Call, its receiver and every argument                          always TAny instead
Access, the receiver being accessed                             always TAny instead

The four "forwards" rows compute a value that is one of the sub-expression's values, so the caller's target applies to it directly. ListComp's element expression joins ListLit's for the same reason: each of a comprehension's produced elements is the element expression's value, one per iteration, as each of a literal's elements is. Everything else computes a new value from its operands, so forwarding the target would leak context across an operator or call boundary (a string target reaching into "Param.Count + 1" would concatenate its operands into "11" rather than add them), and a subscript's index or a slice's bound is fixed at TInt because that position must be an int whatever the whole expression is being coerced to. A call's return type is fixed by the signature callFunction selects, not by the caller's target, so a target reaching into an argument would let the caller's context change which overload the callee resolves to.

  • Compiled regular expressions are cached for the lifetime of one evaluation, and for that lifetime only (recache.go). Without the cache, every re_match/re_search/re_findall/re_sub/re_split invocation runs translatePattern's full byte scan and regexp.Compile again, so a pattern inside a comprehension is compiled once per element while section 1.3.10 charges it roughly one operation plus ceil(len/256), under-priced by about three orders of magnitude, and on the worker there is no wall-clock deadline to backstop it.

    It changes no result and no count. Section 1.3.10's charges are applied by callShape (ops.go) around the whole call, before Fn or FnCtx runs, so a cached compile is charged exactly what an uncached one is. A failing pattern is cached too, and its error value is returned unchanged on every hit, so an invalid pattern in a comprehension is rejected with the same message each time.

    It is capped at maxCachedPatterns entries. A pattern is an arbitrary string from a submitted template, not necessarily a literal, so "[re_match(s, s) for s in Param.Files]" presents one distinct pattern per element; an uncapped map would retain one compiled program per element and turn a comprehension into a memory amplifier. Past the cap the cache stops storing (nothing is evicted and the map does not grow), so what it retains is a constant, not a function of the input. Being per-evaluation is what makes that bound hold across requests, and is also why the cache needs no eviction policy and no lock.

  • This package imports internal/openjd/intrange for range_expr's grammar, section 3.4.1.1.1's <IntRangeExpr>. internal/openjd expands the same grammar for a different purpose, a step's task parameter space, with its own divergences from both this package and the spec: it orders values first-seen rather than increasing, rejects a range whose start exceeds its end where the spec yields a single value, and rejects a negative step the spec permits. Both callers share intrange's Range type but use different entry points (Parse here, ParseWithPolicy there) because they disagree about what to accept; see the intrange package doc for the full comparison.

  • Test coverage. The OpenJD conformance suite's EXPR/job_templates group is scored by make test-conformance. The protected-fixture tests (TestConformance_*Fixtures in test/conformance/suite_test.go) also assert by name that specific .invalid fixtures are rejected: a construct this comment describes as rejected, such as the comprehension shadowing check or a parser/lexer rejection of a form Python allows; the conversion and math functions rejecting an invalid argument (an empty list or path into bool(), an unrecognized string into bool(), an empty list to min/max, an unrepresentable float-to-int, NaN and infinity into float(), an empty string or list into range_expr()); the string functions rejecting an invalid argument (an empty substring into count/find/replace, an empty separator into split/rsplit, a missing substring into index/rindex); the regex scanner and re_sub replacement check rejecting an unsupported construct (an empty pattern, \z, lookahead, lookbehind, a named backreference, and re_sub's four group-reference spellings); and the path functions (relative_to's errNotRelative, with_number's errPaddingTooWide, section 1.2.4's receiver restriction refusing to coerce a path receiver into a string method, and bool()'s path row). Each must be rejected by real validation rather than by an accidental "unknown function", so that one fixture starting to pass for the wrong reason while another regresses cannot hide inside an unchanged aggregate score. Such a test asserts the fixture is still rejected, not which mechanism rejected it, so an entry pins a specific check only where no second mechanism rejects the same input. The differential oracle (make test-expr-oracle) compares values against the reference implementation over test/oracle/corpus.txt, and, on every case whose value agrees, operation counts (EvalWithMetrics against the reference's evaluate_with_metrics; a case with a value divergence is reported once and not double-counted). Value divergences are adjudicated in test/oracle/baseline.txt, count divergences in test/oracle/baseline-ops.txt (see the counting rulings paragraph of the bounded evaluation bullet). The path corpus is large and its divergences are the reference's, argued family by family in test/oracle/baseline.txt (its non-normalizing "/" and "+", its flavor-blind as_posix, its older pathlib stem/suffix split, its with_number hash-swallow, its inconsistent trailing-slash consumption on a relative_to base, and its treatment of a bare "scheme://" as a wildcard authority). The baselined value entries include several round() cases. One is the return type: sqi returns int for round(x, ndigits) when ndigits <= 0, per RFC 0006's signature table, while the reference returns a float (round(1234.5, -1) is "1230 : int" here and "1230.0 : float" there). The specification outranks the reference (it is Beta, 0.x, with breaking changes permitted in minor releases), so this is adjudicated as the reference's bug and recorded in test/oracle/baseline.txt. Also baselined are two of the regex and repr_* rulings argued above, the [^\W...] set-subtraction gap and repr_sh's textual difference from the reference; \d/\w/\s's Unicode semantics are not, since the oracle checks agreement on them, and neither is repr_json's non-ASCII escaping, since the reference matches it. The path rulings above are baselined where they diverge; case-sensitive path comparison is not, because the reference agrees with sqi there and CPython's PureWindowsPath disagrees with both, which the oracle does not see because it runs the reference under POSIX only. apply_path_mapping has no oracle case (see the path mapping bullet above). Most baselined divergences are the reference's bugs, adjudicated against the spec text and recorded one by one; those files are the place to check any individual ruling.

Anything unimplemented fails rather than misbehaving, with one exception: the escape sequences named above pass through verbatim instead of erroring or being decoded. The grammar is EXPR's own rather than borrowed from a Python parser so that failure runs in that direction: a borrowed parser would accept syntax this package cannot evaluate.

Extending it

Two shapes carry the weight and should not be reshaped:

  • Type is a code plus its type parameters (Params), built through normalizing constructors (UnionOf, ListOf, UnresolvedOf and the rest) rather than as struct literals, so that two types meaning the same thing always have the same shape and Equal is sufficient everywhere downstream. Value carries a Type rather than inferring one from which payload field is set; an unresolved value carries no payload at all, which is what makes a typed-but-valueless result possible.
  • Operator behavior is an ordered list of Shapes per operator (shape.go, ops.go), not a switch or a map keyed on operand types; a Type containing a slice cannot be a map key. Each Shape declares the types it takes and the type it returns, which is what lets a missing operand value still produce a typed result. New signatures are new Shape entries; a candidate list with no admissible match is reported as "unsupported operand types".

The specification is the OpenJD wiki page "Expression Language [Extension: EXPR]", pinned in the third_party/openjd-specifications submodule. Section numbers cited in this package's comments refer to it.

Index

Constants

This section is empty.

Variables

View Source
var (
	TNull      = Type{Code: CodeNull}
	TBool      = Type{Code: CodeBool}
	TInt       = Type{Code: CodeInt}
	TFloat     = Type{Code: CodeFloat}
	TString    = Type{Code: CodeString}
	TPath      = Type{Code: CodePath}
	TRangeExpr = Type{Code: CodeRangeExpr}
	TAny       = Type{Code: CodeAny}
	TNoReturn  = Type{Code: CodeNoReturn}
)

The predeclared types that take no parameters.

View Source
var ErrDeadlineExceeded = errors.New("expr: evaluation deadline exceeded")

ErrDeadlineExceeded reports that an evaluation stopped because its wall-clock deadline passed.

It is exported and distinct from every budget error. A budget error means the template asked for more than it is allowed and is therefore invalid; this means the server gave up, and the same template might well succeed on an idle machine. Callers that turn errors into HTTP status codes must be able to tell those apart structurally rather than by reading a message — see internal/api's submission handler, which maps this to 503 and every budget error to 422.

The wrapped message adds how far past the deadline the check landed and nothing else ("... exceeded by 1.2s"). It must add information rather than restate this sentence: %w concatenates the two, and a 503 body shows the result verbatim.

Functions

func CanonicalRangeExpr added in v0.4.0

func CanonicalRangeExpr(text string) string

CanonicalRangeExpr writes range expression text in its canonical form (Template Schemas §3.4.1.1.1). internal/openjd binds a RANGE_EXPR job parameter's value through it, so the value a worker receives is the one every range_expr is written as here. Text that does not parse is returned unchanged; validation reports it.

func EvalForBalanceCheck

func EvalForBalanceCheck(src string, target Type) (live, resultSize int64, err error)

EvalForBalanceCheck evaluates src and reports the live memory remaining afterward alongside the result's own size. The two must be equal: after a top-level evaluation nothing but the result is live.

It exists for the differential oracle, which asserts the identity over the whole corpus rather than over hand-picked cases. That breadth is the point: a release bug in one rarely-exercised function is what a written-out test set misses. It routes through coerceTop like every other public entry point, so the invariant covers the top-level coercion too; without that, it would be blind to a leak or a missing bound check in the region WithMemoryLimit most needs to reach (see coerceTop's own doc comment).

What the corpus-wide sweep does not reach: this function takes no Symbols and passes MapSymbols(nil), and test/oracle/corpus.txt contains no symbol references. So no corpus case produces an unresolved value, and the sweep touches none of the roughly thirteen release sites on the unresolved paths (evalIndex's and evalSlice's unresolved branches, sliceComponent, condResult, applyBinary's and callFunction's unresolved-operand returns, and their siblings) and no symbol-backed receiver. That is a coverage gap, not a known correctness one. Closing it needs a corpus that binds symbols.

func LineCol

func LineCol(src string, offset int) (line, col int)

LineCol converts a byte offset into 1-based line and column numbers. Columns are counted in runes, not bytes, so a caret placed at the returned column lands under the intended character. An out-of-range offset is clamped to the start or end of src rather than reported as an error: a bad offset must never turn a real diagnostic into a panic.

func ParseFloatString added in v0.4.0

func ParseFloatString(s string) (float64, error)

ParseFloatString reads a <floatstring> (Template Schemas §7.5): a number with any white space around it ignored.

func ParseIntString added in v0.4.0

func ParseIntString(s string) (int64, error)

ParseIntString reads an <intstring> (Template Schemas §7.5): a base-10 integer with any white space around it ignored.

func SizeOf

func SizeOf(v Value) int64

SizeOf reports the section 1.3.9 size, in bytes, that this package charges for holding v live -- the same figure [meter.alloc] adds to an evaluation's memory budget.

It exists for callers that retain values across evaluations, which the per-Eval meter by construction cannot bound: each Eval starts with a fresh budget, so a caller that keeps N results alive is exposed to N times the per-Eval limit no matter how tight that limit is. internal/worker/fmtres' let: evaluator (an EXPR let: block binds up to 50 values into one symbol table and holds them for the whole task) and internal/openjd's template checker, which charges what every let: block retains against the template-wide budget, are such callers.

The figure is implementation-defined by section 1.3.9's own admission ("try to match the actual memory usage of each value as closely as practical"), so treat it as a budgeting unit, not as a Go heap measurement.

func TrimNumericSpace added in v0.4.0

func TrimNumericSpace(s string) string

TrimNumericSpace removes the white space a numeric string may carry around its number. Template Schemas §7.5 allows it on every <intstring>, <floatstring> and their positive forms, and RFC 0005 §1.2.3 on a string converted to int or float, so " 7 " is 7 and "2.5\n" is 2.5. White space inside the number is not removed, so "1 000" still fails to parse.

White space is the Unicode White_Space property, which is exactly the set unicode.IsSpace tests. It is not what the isspace() function tests: that one is Python's str.isspace and also accepts U+001C–U+001F, which §7.5 names as not white space here.

Every package that reads a numeric string uses this one definition, so the worker, the server and the expression evaluator agree on what a number is.

Types

type Access

type Access struct {
	// Offset is the byte offset of the ".".
	Offset int
	X      Node
	Attr   string
}

Access is a property access, "X.Attr" (spec section 1.3.3, where a property p resolves to the function __property_p__).

It is produced only when the receiver is not a Name — "[1,2].len" or "(x).y". A dotted name keeps all its segments inside one Name node, and resolution splits it, so "Param.File.stem" produces no Access.

func (*Access) Pos

func (n *Access) Pos() int

Pos returns the byte offset of this property access's dot.

type Binary

type Binary struct {
	Offset int
	Op     Op
	L, R   Node
}

Binary is an arithmetic, string or comparison operation whose behavior comes from the dispatch table in ops.go.

func (*Binary) Pos

func (n *Binary) Pos() int

Pos returns the byte offset of this binary operation's operator.

type BoolLit

type BoolLit struct {
	Offset int
	Val    bool
}

BoolLit is True/true or False/false (spec sections 1.1.1 and 1.1.4).

func (*BoolLit) Pos

func (n *BoolLit) Pos() int

Pos returns the byte offset in the source where this literal begins.

type Call

type Call struct {
	// Offset is the byte offset of the "(".
	Offset int
	Callee Node
	Args   []Node
}

Call is a call, "Callee(Args...)" (spec section 1.3.3).

Callee carries the un-split callee: a Name whose segments resolution walks, or an Access whose X is the receiver. Which of those it is decides whether section 1.2.4's receiver coercion restriction applies, so the distinction must survive parsing rather than being desugared away here.

func (*Call) Pos

func (n *Call) Pos() int

Pos returns the byte offset of this call's opening parenthesis.

type Code

type Code int

Code is the base of a Type: which type constructor it is, independent of any type parameters. The Recommended Library Interface's Type Codes table lists all sixteen codes this discriminates between; section 1.2.1 itself lists only the twelve the language surfaces to a template author, omitting any, noreturn and the type variables, which exist only in a function signature.

const (
	CodeNull Code = iota // nulltype
	CodeBool
	CodeInt
	CodeFloat
	CodeString
	CodePath
	CodeRangeExpr
	CodeList       // Params[0] is the element type
	CodeUnion      // Params are the members
	CodeUnresolved // Params[0] is the constraint
	CodeAny
	CodeNoReturn
	CodeVarT // type variables: function signatures only, never a concrete value
	CodeVarT1
	CodeVarT2
	CodeVarT3
)

The type codes. Params carries the type parameters each one takes: none for the scalars, an element type for CodeList, the members for CodeUnion, and the constraint for CodeUnresolved.

func (Code) String

func (c Code) String() string

type Compare

type Compare struct {
	// Offset is the byte offset of the first comparison operator in the
	// chain. It is what Pos() returns and is unrelated to which link, if any,
	// fails during evaluation — see OpOffsets for that.
	Offset    int
	Ops       []Op
	Operands  []Node
	OpOffsets []int
}

Compare is a comparison chain (spec section 1.3.6). "1 < 2 < 3" holds three operands and two operators; len(Operands) is always len(Ops)+1. Chains are one node rather than nested Binary nodes because each intermediate value must be evaluated exactly once.

OpOffsets holds the byte offset of each operator in Ops, in order, so len(OpOffsets) is always len(Ops) too: OpOffsets[i] is where Ops[i] sits in the source, letting the evaluator blame the specific link in the chain that failed rather than the chain's first operator.

func (*Compare) Pos

func (n *Compare) Pos() int

Pos returns the byte offset of this comparison chain's first operator.

type Cond

type Cond struct {
	Offset         int
	Then, If, Else Node
}

Cond is the conditional expression "Then if If else Else" (spec section 1.3.5).

func (*Cond) Pos

func (n *Cond) Pos() int

Pos returns the byte offset of this conditional expression's "if".

type Cost

type Cost struct {
	// ArgElements are parameter indices charged by element count (rule 2:
	// "when a function or the evaluator iterates through every element of a
	// list, the number of elements is added").
	ArgElements []int
	// ArgBytes are parameter indices charged by ceil(len/256) (rule 3: "when a
	// function processes a string or path value, the length of the value
	// divided by 256, rounded up, is added").
	ArgBytes []int
	// ResultElements charges the element count of the value produced. Rule 2
	// covers generators as well as consumers: range(1000) iterates a list it
	// created rather than one it was given.
	ResultElements bool
	// ResultBytes charges the byte length of the value produced, for a function
	// whose work scales with what it built rather than with what it read.
	ResultBytes bool
}

Cost declares a Shape's section 1.3.10 rule-2 and rule-3 charges.

The single per-call operation of rule 1 is charged by callShape for every shape and is not declared here: making it declarative would let a forgotten entry silently un-count a call, which is the one charge that can never legitimately be zero.

The zero value charges nothing beyond that call, which is correct for the functions section 1.3.10 explicitly exempts -- "simple lookups like len() that do not process the string content".

type Error

type Error struct {
	// Msg describes what went wrong, without any position prefix.
	Msg string
	// Offset is the byte offset into Src where the problem starts.
	Offset int
	// Src is the expression source the offset refers to.
	Src string
	// contains filtered or unexported fields
}

Error is a syntax or evaluation error in an expression. It carries the byte offset in the source text at which the problem was found, together with the source itself, so the rendered message can name a line and column.

The spec requires errors to point at the failing part of an expression, so offsets are recorded on tokens by the lexer, carried onto tree nodes by the parser, and used by the evaluator to blame the operator that failed rather than the start of the expression.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped cause, or nil when there is none.

type Expression

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

Expression is a parsed expression, ready to evaluate.

func Parse

func Parse(src string) (*Expression, error)

Parse reads an expression and returns its tree, or an *Error naming the position at which the source stopped making sense.

The grammar implemented here is EXPR's, not Python's. Anything outside it — bitwise operators, dict and set literals, assignment, and the rest of section 1.1's exclusion list — is rejected. That is the safe direction: a reader borrowed from a full Python parser would silently accept syntax this package cannot evaluate, whereas anything unimplemented here fails to parse. The first thing it does is bound the source's length (limits.go's maxSourceBytes). That check has to come before tokenize, not after it and not inside the parser: every other bound this package and its callers have — the section 1.3.9/1.3.10 budgets, the template-wide budget, the operator limits, the wall-clock deadline — is metered during evaluation, so until this check runs nothing at all is watching. See maxSourceBytes for what an unbounded parse costs.

func (*Expression) CalledFunctions

func (e *Expression) CalledFunctions() []string

CalledFunctions returns the external set of function and method names this expression calls, sorted and de-duplicated. It is the counterpart to Names: where Names collects the symbol a callee's leading segments name, this collects the trailing segment that names the function or method itself (section 1.3.3). "len(x)" yields "len"; "Param.Name.upper()" yields "upper"; "s.apply_path_mapping()" yields "apply_path_mapping".

It is external in the same sense Names is, and for the same reason: a comprehension loop variable called directly is bound by section 1.3.7, not by the function registry, so "[x() for x in Param.L]" yields the empty set rather than {"x"}. The exclusion is narrow — it applies only to a single-segment callee, where the called name is the bound identifier. In "[x.foo() for x in Param.L]" the called name is the method "foo", which the loop variable x does not shadow, so "foo" is reported; and the binding ends with its comprehension, so "[x for x in Param.L] + [x()]" reports {"x"} again. (Names diverges from the reference implementation on that last point and explains why above; the same reading applies here.)

internal/openjd's template checker uses it, with CallsAny, to spot a host-context call (notably apply_path_mapping) in a submission-time scope and reject it. This package enforces no such rule itself — see pathMappingFuncs.

func (*Expression) CallsAny

func (e *Expression) CallsAny(names map[string]struct{}) bool

CallsAny reports whether the expression calls any of the named functions or methods — the membership question CalledFunctions is otherwise used to answer, without building the answer.

It applies exactly CalledFunctions's collection rule, node for node: the same callee positions, the same trailing-segment rule for a dotted callee, the same Access arm for a parenthesized receiver, and the same narrow section 1.3.7 exclusion of a single-segment callee a comprehension binds. Read that doc comment for the adjudication of each; this one restates none of it, precisely so the two cannot drift apart in the telling. CalledFunctions is the enumeration, this is the predicate, and they agree by construction — which is pinned by TestCalledFunctions, whose every case asserts both.

It exists because the only consumer is a predicate. internal/openjd's checker asks "does this call a host-only function?" once per expression on the submission path, against a set with a single member (apply_path_mapping), and CalledFunctions would answer it by walking the whole tree into a de-duplicating map, allocating a slice, and sorting it. This walks with early termination — it stops at the first match — and allocates nothing but the walk stack.

An empty or nil set is false without walking anything.

func (*Expression) Eval

func (e *Expression) Eval(syms Symbols, target Type, opts ...Option) (Value, error)

Eval evaluates the parsed expression against syms, coercing the result to target. syms may be nil for an expression that references no symbols; pass TAny as the target to accept the expression's natural result type.

The target guides implicit coercion (section 1.3.1). It applies here, at the boundary, and inside operator dispatch when a shape is matched. It propagates into a sub-expression from exactly four node kinds and no others — the package doc's forwarding table is the single statement of which, and of why each row is what it is; do not restate it here, and consult it rather than this comment when the question is whether some position takes a target. Section 1.3.1 leaves the question open, and the table's governing rule is that a node forwards only when its result is a sub-expression's value: propagating a string target into "Param.Count + 1" would concatenate its operands into "11" rather than adding them, and section 1.3.2's own example of "Count: {{ len(myList) }}" yielding "Count: 5" describes evaluating naturally and converting afterward.

func (*Expression) Names

func (e *Expression) Names() []string

Names returns every external dotted value reference the expression makes — for example {"Param.Frame", "Task.Param.Chunk"} — sorted and deduplicated.

This is the spec's accessed_symbols set, which the Recommended Library Interface defines as "the external symbols referenced by the expression as full dotted paths including properties" — so "Param.File.stem" is collected whole, trailing property and all. Callers use it to decide which symbols an expression needs before evaluating it, for example to scope-check a template's expressions without binding values.

Two kinds of identifier are therefore not names, and are excluded rather than reported:

  • A function or method name. The spec keeps those in a separate called_functions set, so the trailing segment of a call's callee is dropped: "len(Param.Items)" collects {"Param.Items"} and "Param.Name.upper()" collects {"Param.Name"}, not {"len"} and {"Param.Name.upper"}. The spec's called_functions set is CalledFunctions below; it collects exactly the segment this one drops.
  • A comprehension loop variable, and anything rooted at one. Section 1.3.7 binds it inside the comprehension, so it is not external: "[x for x in Param.Items]" collects {"Param.Items"} and "[x.stem for x in Param.Files]" collects {"Param.Files"}. The binding covers the element expression and the filter but not the iterable, which is evaluated before the variable exists — "[x for x in x]" does collect the iterable's own external {"x"}.

Both exclusions matter to the only consumer this set has: a scope check of the form "every name here must be in scope" would otherwise reject every comprehension and every plain function call in the language. The reference implementation answers every case above identically.

It does not answer identically once the binding ends. A loop variable is bound to its own comprehension and no further, so a later mention is external again: "[x for x in Param.A] + [x]" collects {"Param.A", "x"}, where the reference collects {"Param.A"} alone, as if the name were removed from the whole expression. The spec is on this side — section 1.3.7 binds the variable inside the comprehension, and the Recommended Library Interface asks for the external symbols — so sqi keeps the divergence. It is also the safer direction: a scope check sees the free "x" here and would miss it under the reference's answer.

One narrowing remains, and it is safe in that direction: a property chain whose receiver is not a bare name — "(Param.File).stem", where the parentheses make the parser build an Access rather than one Name — collects the receiver "Param.File" alone, where the reference collects "Param.File.stem". A scope check sees a name that is in scope either way.

func (*Expression) Root

func (e *Expression) Root() Node

Root returns the tree's root node.

func (*Expression) Source

func (e *Expression) Source() string

Source returns the text this expression was parsed from.

type FloatLit

type FloatLit struct {
	Offset int
	Val    float64
}

FloatLit is a floating-point literal.

func (*FloatLit) Pos

func (n *FloatLit) Pos() int

Pos returns the byte offset in the source where this literal begins.

type Index

type Index struct {
	// Offset is the byte offset of the "[", so an out-of-bounds error blames
	// the subscript rather than the start of the expression.
	Offset int
	X, Idx Node
}

Index is a subscript, "X[Idx]" (spec section 2.1.7).

func (*Index) Pos

func (n *Index) Pos() int

Pos returns the byte offset of this subscript's opening bracket.

type IntLit

type IntLit struct {
	Offset int
	Val    int64
}

IntLit is an integer literal.

func (*IntLit) Pos

func (n *IntLit) Pos() int

Pos returns the byte offset in the source where this literal begins.

type ListComp

type ListComp struct {
	// Offset is the byte offset of the opening "[".
	Offset int
	Elem   Node
	// Var is the loop variable, which section 1.3.7 requires to be a
	// <UserIdentifier> so it cannot shadow a spec-defined symbol like Param.
	Var string
	// VarOffset is where Var sits in the source, so a shadowing error blames
	// the variable rather than the opening bracket.
	VarOffset int
	Iter      Node
	Cond      Node
}

ListComp is a list comprehension (spec section 1.3.7): "[" Elem "for" Var "in" Iter ("if" Cond)? "]".

Cond is nil when the comprehension has no filter. Section 1.3.7 permits exactly one filter and no second "for" — Python's multi-generator form is rejected by the parser, not represented here.

func (*ListComp) Pos

func (n *ListComp) Pos() int

Pos returns the byte offset of this comprehension's opening bracket.

type ListLit

type ListLit struct {
	// Offset is the byte offset of the opening "[".
	Offset int
	Elems  []Node
}

ListLit is a list literal (spec section 1.1.2). Elems is empty for "[]", whose type is list[nulltype] (section 1.2.6).

func (*ListLit) Pos

func (n *ListLit) Pos() int

Pos returns the byte offset of this list literal's opening bracket.

type Logical

type Logical struct {
	Offset int
	Op     Op
	L, R   Node
}

Logical is "and" or "or" (spec section 2.1.6). These are not in the dispatch table: they short-circuit and return one of their operands rather than a bool, so they cannot be expressed as a Shape with a fixed return type.

func (*Logical) Pos

func (n *Logical) Pos() int

Pos returns the byte offset of this logical operation's operator.

type MapSymbols

type MapSymbols map[string]Value

MapSymbols is a Symbols backed by a map keyed on fully qualified dotted names, for example {"Param.Frame": Int(7)}. A nil MapSymbols is a valid empty table.

func (MapSymbols) Lookup

func (m MapSymbols) Lookup(name string) (Value, bool)

Lookup implements Symbols.

type Name

type Name struct {
	Offset int
	Parts  []string
}

Name is a dotted value reference such as Param.Foo or Task.Param.Frame. Parts holds the dot-separated segments in order and is never empty.

func (*Name) Pos

func (n *Name) Pos() int

Pos returns the byte offset in the source where this name begins.

func (*Name) String

func (n *Name) String() string

String returns the fully qualified dotted name.

type Node

type Node interface {
	// Pos returns the byte offset in the source where this node begins.
	Pos() int
	// contains filtered or unexported methods
}

Node is one node in a parsed expression tree.

Every node records the byte offset in the source it came from, so an evaluation error can blame the operator that failed rather than the start of the expression. For an operation node the offset is the operator's own.

type NullLit

type NullLit struct {
	Offset int
}

NullLit is None or null (spec sections 1.1.1 and 1.1.4).

func (*NullLit) Pos

func (n *NullLit) Pos() int

Pos returns the byte offset in the source where this literal begins.

type Op

type Op int

Op identifies an operator. The same value names an operator in the tree and keys the dispatch tables in ops.go, so there is one operator vocabulary rather than two that can drift.

const (
	OpAdd Op = iota
	OpSub
	OpMul
	OpDiv
	OpFloorDiv
	OpMod
	OpPow
	OpNeg
	OpPos
	OpNot
	OpAnd
	OpOr
	OpLt
	OpGt
	OpLe
	OpGe
	OpEq
	OpNe
	OpIn
	OpNotIn
)

The operator constants. Each names one operator that a tree node can carry.

func (Op) String

func (o Op) String() string

type Option

type Option func(*evalCtx)

Option configures one evaluation.

It is variadic so that a call needing no settings passes none, and so every setting, the section 1.3.9 and 1.3.10 limits included, shares one channel.

func WithClock

func WithClock(now func() time.Time) Option

WithClock replaces the clock the deadline check reads. It exists for tests, which advance a fake clock rather than sleeping. Production never calls it; nil means time.Now.

func WithDeadline

func WithDeadline(t time.Time) Option

WithDeadline sets an absolute wall-clock deadline for this evaluation.

The zero time, the default, means no deadline and costs nothing: the meter short-circuits before reading any clock.

It is absolute rather than a duration, so one deadline can span a whole request. An accepted template's expressions are walked twice (phase 1 in ValidateWithOptions, phase 2 in checkExpressionsAtSubmit) across many evaluations, and a per-evaluation duration would let each one spend the full allowance.

func WithMemoryLimit

func WithMemoryLimit(bytes int64) Option

WithMemoryLimit bounds the live memory, in bytes, of the values one evaluation holds at once (section 1.3.9). It defaults to 100,000,000.

There is no unlimited mode: a non-positive limit is a caller error, reported by Eval. A value that reads like "off" must not be off in a package reachable from POST /api/v1/jobs. Tests wanting effectively-unbounded evaluation pass a large number.

limits.go's fixed bounds sit underneath this one and are not configurable, so raising this limit does not raise what a single operation may allocate: "'a' * 20000000" still fails on maxStringBytes with errTooLarge, not on errMemoryLimit.

func WithOperationLimit

func WithOperationLimit(ops int64) Option

WithOperationLimit bounds the number of operations one evaluation may perform (section 1.3.10). It defaults to 10,000,000. A non-positive limit is a caller error, for the same reason WithMemoryLimit's is.

func WithPathFormat

func WithPathFormat(f PathFormat) Option

WithPathFormat selects the path semantics for this evaluation.

func WithPathMapping

func WithPathMapping(rules []PathMapRule) Option

WithPathMapping supplies the session's path-mapping rules to apply_path_mapping. Absent, apply_path_mapping passes its input through, normalized as a path value in the evaluation's flavor — passthrough means "no rule rewrote it", not "the text is returned verbatim", so '/a//b/' still comes back as the path "/a/b". The worker's host-context evaluation (internal/worker/fmtres) supplies the session's rules; no other production caller sets this.

type PathFormat

type PathFormat int

PathFormat selects the semantics the path type uses during evaluation.

The specification makes this an evaluator setting rather than a property of the host. sqi parses templates server-side, so deriving it from the running machine would let one template expand into different tasks depending on which OS submitted it.

const (
	// PathPOSIX is Python's PurePosixPath. It is the default, which differs
	// from the specification's default of host-native: the spec names POSIX
	// as what template scope wants, "to ensure consistent behavior regardless
	// of the submission machine's OS", and template parsing is that scope.
	PathPOSIX PathFormat = iota
	// PathWindows is Python's PureWindowsPath.
	PathWindows
	// PathNative is the specification's own default: the host's semantics.
	// The worker selects it for host-context evaluation
	// (internal/worker/fmtres).
	PathNative
)

type PathMapRule

type PathMapRule struct {
	SourceFormat    PathMapSourceFormat
	SourcePath      string
	DestinationPath string
}

PathMapRule is one source→destination path-mapping rule. It mirrors the OpenJD pathmapping-1.0 schema but is independent of internal/worker/protocol, which this leaf package cannot import; internal/worker/fmtres translates a protocol.PathMapRule into this type at the injection boundary.

type PathMapSourceFormat

type PathMapSourceFormat int

PathMapSourceFormat is the format of a path-mapping rule's SourcePath, the OpenJD pathmapping-1.0 "source_path_format" enum (URI is the EXPR extension's addition).

const (
	// PathMapPOSIX matches SourcePath using POSIX path semantics.
	PathMapPOSIX PathMapSourceFormat = iota
	// PathMapWindows matches SourcePath using Windows path semantics
	// (case-insensitive, separator-insensitive — see applyFileRule).
	PathMapWindows
	// PathMapURI matches SourcePath by string prefix on a "/" path-segment
	// boundary, with no path normalization — see applyURIRule.
	PathMapURI
)

type Shape

type Shape struct {
	// Params are the declared parameter types, one per argument.
	Params []Type
	// Ret is the declared result type. It may be a union: the spec's own
	// __pow__(int, int) -> float | int is one.
	Ret Type
	// RetOf, when set, computes the declared result from the match's variable
	// bindings instead of substituting them into Ret.
	//
	// It exists for a result type that is a unification of the operands rather
	// than a copy of one of them. List concatenation is the case: its two
	// element variables are independent (they must be, or "[1] + [2.0]" would
	// not match at all), so no substitution into Ret can say what section
	// 2.1.3's "common type" of the two is — "[] + list[int]" reads the left
	// variable and answers list[nulltype], and "list[int] + []" answers
	// list[int], for the same concatenation. concatLists computes the real
	// answer from the values, which is no help on the path where there are no
	// values; this is that same computation over types.
	RetOf func(b bindings) Type
	// Fn computes the result. It is called only with arguments that matched
	// Params, so it may use the payload accessors without checking.
	Fn func(args []Value) (Value, error)
	// FnCtx is Fn for the few implementations that need the evaluation's
	// settings rather than only their arguments.
	//
	// The rule for which rows use it is not a tally, it is a question: does
	// this row need something the evaluation holds that its arguments cannot
	// give it? There are two answers, unrelated to each other.
	//
	// The first is the path flavor. All three of path()'s rows must choose one
	// at construction time — path(string), path(list[string]) and
	// path(list[nulltype]) — because constructing a path is the only operation
	// that ever has to decide; every other path operation reads the flavor off
	// its receiver.
	//
	// The second is the compiled-pattern cache (recache.go), which every
	// re_ row that compiles a pattern reaches through ec.re. That one is a
	// speed property and nothing else: the cache changes no result, no error
	// and no section 1.3.10 charge, since callShape applies every charge around
	// the call before Fn or FnCtx runs.
	//
	// Adding a parameter to Fn instead would change every other row, which
	// needs neither; RetOf is the existing precedent for an optional
	// alternative field.
	//
	// A Shape sets Fn or FnCtx, never both.
	FnCtx func(ec evalCtx, args []Value) (Value, error)
	// Promote narrows which conversions this shape's parameters will accept to
	// admit an argument of a different type. The zero value accepts every
	// lossless conversion coerce.go allows, which is right for most operators
	// and wrong for ordering — see promotion.
	Promote promotion
	// Cost declares this signature's section 1.3.10 charges beyond the single
	// per-call operation. See Cost.
	Cost Cost
}

Shape is one accepted signature of an operator or function: the types it takes, the type it gives back, and the code that computes it.

It is a declared signature rather than a map entry keyed by operand kind, for two reasons. A Type contains a slice, so it cannot be a Go map key at all. And a map entry does not record what it returns, which makes it impossible to answer "what would this produce?" for an operand that has no value — the question at the center of the spec's static type checking. A declared Ret answers it without executing anything.

Params and Ret may contain type variables (CodeVarT and friends), bound at match time and substituted into Ret afterward, so that a signature like __getitem__(list[T], int) -> T returns the element type. The function library (funcs.go) registers into this same structure.

type Slice

type Slice struct {
	// Offset is the byte offset of the "[".
	Offset int
	X      Node
	Start  Node
	Stop   Node
	Step   Node
}

Slice is a slice, "X[Start:Stop:Step]" (spec sections 1.3.8 and 2.1.8).

An absent component is nil, which is distinct from an explicit one: section 1.3.8 defaults start to 0 or to the end and stop to the length or to -length-1, depending on the sign of the step, so a zero value could not carry the distinction.

func (*Slice) Pos

func (n *Slice) Pos() int

Pos returns the byte offset of this slice's opening bracket.

type StringLit

type StringLit struct {
	Offset int
	Val    string
}

StringLit is a string literal, with escape sequences already expanded.

func (*StringLit) Pos

func (n *StringLit) Pos() int

Pos returns the byte offset in the source where this literal begins.

type Symbols

type Symbols interface {
	// Lookup returns the value bound to a fully qualified dotted name, and
	// whether it is bound at all.
	Lookup(name string) (Value, bool)
}

Symbols resolves the dotted names an expression references — Param.Frame, Task.Param.Chunk, Session.WorkingDirectory and the like.

The package hardcodes no namespaces: the caller decides what is in scope, exactly as fmtstring.Scope does for base-spec format strings.

type Type

type Type struct {
	// Code is which type constructor this is. Always meaningful.
	Code Code
	// Params are the type parameters, whose meaning depends on Code. Empty for
	// the scalars.
	Params []Type
}

Type is a type in the expression language: a code plus its type parameters.

Because Params is a slice, Type is not comparable — "==" on two Types is a compile error and a struct containing a Type cannot be a Go map key. Use Equal. That single fact is why operator dispatch is a list of shapes (shape.go) rather than a map keyed on kinds.

Construct Types through the constructors below rather than as literals: they normalize, and everything downstream relies on structural equality being sufficient, which only holds for normalized types.

func JobParamTypes

func JobParamTypes(declared string) (paramType, rawType Type)

JobParamTypes maps a declared OpenJD job-parameter type ("STRING", "PATH", "INT", "FLOAT", "LIST[PATH]", ...) to the expression types of Param.<name> and RawParam.<name>, per section 1.2.2's job-parameter table.

PATH and LIST[PATH] are the two rows where the raw form differs from the resolved form, because the raw value may be a path for another operating system that cannot be parsed locally: Param.<name> is a path (or list of paths), RawParam.<name> stays a string (or list of strings). Every other declared type binds Param and RawParam to the same type. That rule is stated in as many words by Template Schemas §7.3.1's value-reference table — "This is the same as RawParam.<ParamName> for all parameter types except PATH" (wiki/2023-09-Template-Schemas.md:1993) — not by Expression-Language §1.2.2. §1.2.2's own contribution is the type table above plus the PATH prose ("Param.<name> has type path with path mapping rules applied, while RawParam.<name> has type string containing the original unmapped value"). So an INT job parameter's RawParam.<name> is int, not string. Do not special-case RawParam to string uniformly; that would contradict the specification for every non-PATH type.

An unrecognized spelling floors to "any" rather than leaving the name unbound — an unbound name would make a valid template fail as "unknown symbol", which is worse than typing it loosely.

This is the single, shared definition of the mapping. internal/openjd's phase-1/phase-2 symbol-table builder (exprcheck.go's jobParamTypes) and the worker's phase-3 builder (internal/worker/fmtres/exprsyms.go) both call this function rather than each keeping their own copy. internal/openjd itself cannot be imported by the worker binary — it pulls in internal/store, which the worker must never depend on — so the mapping lives here, in the one package both sides already import (internal/openjd/expr imports only internal/openjd/intrange). A second, independently maintained copy of this table could drift from this one.

func ListOf

func ListOf(elem Type) Type

ListOf builds a list type. An unresolved element type hoists outward — a list of unresolved elements is an unresolved list — which keeps unresolved as the outermost constructor, the canonical form the ExprType section requires.

Section 1.2.1's constraints on the element type (no third level of nesting, no optional element) are enforced by ParseType, where untrusted text enters. Internal callers pass programmer-controlled types, so an error return here would add an unfailing check to every call site.

func OptionalOf

func OptionalOf(t Type) Type

OptionalOf builds the type of a value that may also be null. The spec has no separate optional code: "int?" is exactly the union of int and nulltype, and UnionOf's normalization means applying this twice changes nothing.

func ParseType

func ParseType(s string) (Type, error)

ParseType reads a type in the notation String produces: "int", "list[string]", "int?", "int | string", "unresolved[int]".

This is where untrusted text becomes a Type — declared parameter types arrive as strings — so it is also where section 1.2.1's constraints on a list's element type are enforced.

func TaskParamType

func TaskParamType(declared string) Type

TaskParamType maps a declared OpenJD task-parameter type per section 1.2.2's task table. CHUNK[INT] is range_expr, not list[int], so that a frame range need not be expanded. Task.Param.<name> and Task.RawParam.<name> share this same type for every declared task- parameter type, including PATH. §1.2.2's task table gives one expression type per declared type, with no Param/RawParam split at all; the value-versus-type distinction comes from Template Schemas' own task- parameter definitions, which describe Task.Param.<name> as "the value of the parameter with relevant path mapping rules applied to it" and Task.RawParam.<name> as "the value of the parameter as it was defined, with no path mapping rules applied" (wiki/2023-09-Template-Schemas.md:1248-1249). It is a value difference, not a type difference; both remain path.

An unrecognized spelling floors to "any", for the same reason JobParamTypes does. See that function's doc comment for why this mapping is shared rather than duplicated per caller.

func UnionOf

func UnionOf(ts ...Type) Type

UnionOf builds a union type, applying every normalization rule the ExprType section requires: nested unions flatten, noreturn collapses to nothing, any absorbs everything, duplicates are removed, members sort with nulltype last, a single member unwraps, and an unresolved member hoists to wrap the whole union.

Normalizing here rather than at each use site is what makes Equal sufficient downstream. Dispatch, coercion and the conformance path all rely on two types that mean the same thing having the same shape.

func UnresolvedOf

func UnresolvedOf(t Type) Type

UnresolvedOf builds the type of a value whose type is known but whose value is not, per the spec's static-type-checking model. Nested unresolved types flatten, so unresolved is idempotent.

The value-level counterpart is Unresolved, which builds a Value; the -Of suffix on the type constructors keeps the two apart.

func (Type) Equal

func (t Type) Equal(o Type) bool

Equal reports whether two types are structurally identical.

For normalized types this is also semantic equality — that is the property the constructors exist to guarantee, and it is what lets dispatch, coercion and the conformance path avoid a semantic type comparison entirely.

func (Type) String

func (t Type) String() string

String renders the type in the spec's own notation, and is the exact inverse of ParseType. Type errors quote it, declared parameter types arrive as it, and UnionOf orders a union's members by it.

type Unary

type Unary struct {
	Offset int
	Op     Op
	X      Node
}

Unary is a prefix operation: OpNeg, OpPos or OpNot.

func (*Unary) Pos

func (n *Unary) Pos() int

Pos returns the byte offset of this unary operation's operator.

type Value

type Value struct {
	// Type is the value's type. Always set.
	Type Type
	// contains filtered or unexported fields
}

Value is an evaluated expression result.

Type is always meaningful. The payload fields are valid only for their corresponding type code, and reading the wrong one panics. An unresolved value — a placeholder whose type is known but whose value is not — carries no payload at all, which is the case the type-tag-separate-from-payload shape exists to make possible.

Because Type contains a slice, Value is not comparable: use Equal, not "==".

func Bool

func Bool(b bool) Value

Bool returns a boolean value.

func Coerce

func Coerce(v Value, target Type) (Value, error)

Coerce converts v to target per section 1.2.3's implicit type coercion -- the same conversion an evaluation's own target type applies to its result, exported so a caller that has already evaluated can convert once more without re-parsing and re-evaluating the source.

It exists for one caller. internal/openjd's task-parameter range resolver (resolve.go's evalRangeExprField) must evaluate a whole-field range expression against exactly the type section 1.3.12 gives that field -- "int | string | range_expr | list[int]" for an INT parameter -- because anything else would make its accept/reject verdict differ from the checker's. But those four union members mean different things downstream: an int or a string becomes range text, while a range_expr or a list becomes the range's values. So the resolver evaluates against the union, then converts the range_expr arm -- and only that arm -- into list[int].

Doing that second step through this function reuses section 1.2.3's own range_expr -> list[int] rule (coerceByListDestination's rangeInts call, which expands in increasing, de-duplicated order per section 3.4.1.1.1). The alternative would be a second, independent implementation of "take the integers out of a range_expr" living in internal/openjd, whose ordering policy could drift from this package's, and internal/openjd already has a different <IntRangeExpr> policy (first-seen order, no negative step, no start > end), so a second expansion there would differ by default.

Errors carry no position, exactly as coerce's do: the caller is expected to attach whatever position it has.

func Eval

func Eval(src string, syms Symbols, target Type, opts ...Option) (Value, error)

Eval parses and evaluates src in one step. Prefer Parse plus Expression.Eval when the same expression is evaluated more than once.

func EvalWithMetrics

func EvalWithMetrics(src string, syms Symbols, target Type, opts ...Option) (Value, int64, error)

EvalWithMetrics evaluates src and reports the section 1.3.10 operation count alongside the result, mirroring the reference implementation's ParsedExpression.evaluate_with_metrics. It exists for the differential oracle (test/oracle), which cannot read a package-private counter.

It reports operations only. Section 1.3.9's memory figure is not exposed: value sizing is implementation-defined, so a differential comparison of it could only be suppressed, never adjudicated.

func Float

func Float(f float64) Value

Float returns a 64-bit IEEE floating-point value.

func FloatText

func FloatText(f float64, text string) Value

FloatText returns a float value that renders as text instead of through the default float formatting.

It exists for section 1.3.4: a FLOAT job parameter submitted as "3.500" must keep that exact text rather than the canonical "3.5". sqi stores submitted parameters as map[string]string, so the original text is available verbatim wherever a concrete value is bound from it. ValueFromText (paramtypes.go) is the call site, and internal/openjd's concreteJobParamValue and the worker bind through it. See the fs field's comment for the invariants this carry keeps — including the repr_* exception to "no operation propagates it".

Contract the caller must uphold, unchecked at runtime: text must be a textual representation of f, e.g. the exact source strconv.ParseFloat(text, 64) produced f from -- as ValueFromText's call does, parsing the trimmed text into f and then passing that same text back. Nothing here verifies this. A mismatched pair (say, FloatText(3.5, "9000")) builds a Value whose number is 3.5 -- what Equal, arithmetic, and every other operation compare and compute with -- but whose text is "9000" -- what String() (and therefore repr_py/repr_json/repr_pwsh) reports. The two would silently disagree for as long as the value's fs form is read instead of computed.

func Int

func Int(i int64) Value

Int returns a 64-bit signed integer value.

func List

func List(elem Type, vals []Value) Value

List returns a list value with the given element type and elements.

The element type is passed explicitly rather than inferred from vals because an empty list still has one: "[]" is list[nulltype] (section 1.2.6), and section 1.2.6's inference rules can also give a list an element type no element has exactly — [1, 2.0] is list[float] after its elements are coerced.

func Null

func Null() Value

Null returns the null value.

func Path

func Path(text string, f PathFormat) Value

Path returns a path value with the given flavor, normalized on the way in.

func RangeExpr

func RangeExpr(text string) (Value, error)

RangeExpr returns a range_expr value from its text, which must satisfy the base specification's <IntRangeExpr> grammar (2023-09 Template Schemas, section 3.4.1.1.1).

The text is what the value carries; the integers are expanded only when an operation needs them. That is the point of section 1.2.2 giving CHUNK[INT] the type range_expr rather than list[int] — a frame range need not be expanded to be passed around — and it is what lets range_expr -> string (section 1.2.3) answer without materializing anything: the canonical text is computed from the elements' arithmetic, not from their values.

This constructor is what the language's own range_expr(string) function calls (funcsconv.go), the way an expression can produce a range_expr with no symbol table involved. A CHUNK[INT] task parameter bound through ValueFromText is built by rangeExprAsWritten instead, so it keeps its text.

The value is written in its canonical form (Template Schemas §3.4.1.1.1, as RFC 0005 §1.2.2 makes it a range_expr's string form): a range_expr's value is its list of values, so how the text spelled it (element order, how the values were split into elements, white space) is not kept. range_expr("1-10:2") is written "1-9:2", and range_expr("1,2,3") equals range_expr("1-3") down to its text. Text whose elements overlap and name more than canonicalOverlapBound values keeps its written form (see canonicalRangeText). A value bound through ValueFromText, such as a CHUNK[INT] task parameter, keeps the text it was given (see rangeExprAsWritten).

func String

func String(s string) Value

String returns a string value.

func Unresolved

func Unresolved(constraint Type) Value

Unresolved returns a placeholder for a value that is not yet known but whose type satisfies the given constraint.

This is the mechanism the spec's static type checking is built on: an expression is evaluated with placeholders in the symbol table, operations propagate the type, and a type error surfaces without any value existing. It is safe because the language is side-effect free.

The type constructor with the -Of suffix, UnresolvedOf, builds the Type; this builds the Value.

func ValueFromText

func ValueFromText(t Type, raw string, pathFlavor PathFormat) Value

ValueFromText converts a parameter's submitted raw text into a concrete Value of type t. It returns Unresolved(t) in two distinct situations, which are easy to conflate:

  1. Parse failure, for a type this function does make concrete. INT and FLOAT go concrete when raw parses and fall back to Unresolved(t) when it does not: this function is not a validator, so a value that fails to parse here is reported as still-unknown rather than causing a panic or a lie about what was bound. Validating a submitted value against its declared type happens upstream, before this is called. STRING and PATH always go concrete — every string parses as either.

  2. By construction, for a type this function never makes concrete at all. There is no such type: bool and list are handled. A type added to the table must add its cases here, or its parameters will never resolve past a placeholder in phase 3 — an unhandled type reaches the default branch and returns Unresolved(t), which is a legitimate phase-1 result, so nothing errors and nothing logs. TestValueFromText_ResolvesTheRFC0007Types guards it by asserting concreteness rather than correctness, and any future type must join that table. This is the one place the mapping lives, since phase 2 and phase 3 share it (see JobParamTypes' doc comment).

range_expr (CodeRangeExpr) is made concrete, via RangeExpr(raw) with the same parse-failure-falls-back-to-Unresolved rule as INT/FLOAT. CHUNK[INT] task parameters are one producer: internal/openjd/expand.go stores a CHUNK[INT] task parameter's value as a range-expression string like "1-5", reachable in production from Task.Param.<chunked-name> in the worker's phase-3 table. Phase 2 cannot observe this case: internal/openjd's bindTaskParamSymbols binds every Task.Param./ Task.RawParam. entry as Unresolved(t) directly and never calls this function for task parameters at all (task parameters are per-task, not per-template — see that function's own doc comment).

pathFlavor selects the flavor for a CodePath result, so callers evaluating in different contexts get a Path value that matches their own evaluation's flavor rather than a fixed one: internal/openjd hardcodes PathPOSIX here for submission-time job-parameter binding (a known gap — nothing server-side sets a PathFormat other than the default), while the worker's phase-3 table (a host context) uses PathNative.

The CodeFloat case binds raw as the value's rendered form (FloatText), per section 1.3.4: submitting "3.500" to a FLOAT parameter must preserve that exact text, not the canonical "3.5" strconv.ParseFloat's companion FormatFloat would produce. Callers that store submitted parameters as plain strings (both internal/openjd and the worker do) already have the original text in raw — no separate capture is needed.

func (Value) AsBool

func (v Value) AsBool() bool

AsBool returns the boolean payload. It panics if v is not a bool.

func (Value) AsFloat

func (v Value) AsFloat() float64

AsFloat returns the floating-point payload. It panics if v is not a float.

func (Value) AsInt

func (v Value) AsInt() int64

AsInt returns the integer payload. It panics if v is not an int.

func (Value) AsList

func (v Value) AsList() []Value

AsList returns the list payload. It panics if v is not a list.

func (Value) AsRangeExpr

func (v Value) AsRangeExpr() string

AsRangeExpr returns the range expression text. It panics if v is not a range_expr.

func (Value) AsStr

func (v Value) AsStr() string

AsStr returns the string payload. It panics if v is not a string.

Named AsStr rather than AsString because String is the fmt.Stringer rendering; two methods one letter apart would be a standing trap.

func (Value) Equal

func (v Value) Equal(o Value) bool

Equal reports whether two values have the same type and the same payload.

Value is not comparable with "==" because Type contains a slice, so this is the only way to compare two values for identity. It is not the language's "==" operator: section 1.2.5 makes that cross-type, so 5 == 5.0 is true there while Int(5).Equal(Float(5)) is false here.

func (Value) IsNull

func (v Value) IsNull() bool

IsNull reports whether v is the null value.

func (Value) IsUnresolved

func (v Value) IsUnresolved() bool

IsUnresolved reports whether v is a placeholder rather than a known value.

func (Value) String

func (v Value) String() string

String renders the value as text.

Floats use the shortest representation that round-trips, with a ".0" added when the result would otherwise look like an integer, so a float never renders indistinguishably from an int. Null renders as "null" and booleans as "true"/"false" — the JSON/YAML spellings, matching the aliases in spec section 1.1.4 and the string(nulltype) -> "null" rule in section 2.2.1.

It is also the rendering format-string interpolation uses (internal/openjd's resolve.go and internal/worker/fmtres), except that a null result there becomes the empty string rather than "null".

Jump to

Keyboard shortcuts

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