Documentation
¶
Overview ¶
Package fmtstring resolves Open Job Description (OpenJD) format strings.
OpenJD templates embed format-string references delimited by double braces, for example "{{ Param.FrameStart }}" or "{{Param.FrameStart}}" (surrounding whitespace inside the braces is trimmed, so the two forms are equivalent). Text outside the braces is literal and copied verbatim. There is no backslash escape in OpenJD: every "{{" begins a reference, and a "}}" with no preceding "{{" is literal text.
A reference names a dotted OpenJD identifier such as Param.Foo, RawParam.Foo, Task.Param.Frame, Task.RawParam.Frame, Task.File.script, Env.File.env, Session.WorkingDirectory, Session.HasPathMappingRules, or Session.PathMappingRulesFile. Each dot-separated segment is an OpenJD identifier matching [A-Za-z_][A-Za-z0-9_]*.
The package is intentionally a self-contained leaf with no dependencies on other internal packages, because it is used by BOTH the server (at job submit/expansion time) and the worker (at task-run time). It does not hardcode the available variable namespaces; instead callers supply a Scope that maps fully-qualified names (for example "Task.Param.Frame") to values.
The two core operations are Resolve (substitute every reference) and References (list the names a string refers to without resolving them).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func References ¶
References returns the distinct variable names referenced by input, in order of first appearance. It returns a *MalformedError if input contains a syntactically invalid reference.
func Resolve ¶
Resolve replaces every "{{ name }}" reference in input with the value returned by scope.Lookup for the trimmed name. Literal text outside braces is copied verbatim.
Resolve returns a *MalformedError if input contains a syntactically invalid reference, and a *UnresolvedError naming every distinct unknown variable if any reference names a variable the scope does not provide.
Types ¶
type MalformedError ¶
type MalformedError struct {
// Ref is the offending reference text, including the surrounding braces
// when they are present (for an unclosed reference it is the text from
// "{{" to the end of the input).
Ref string
// Reason describes why the reference is malformed.
Reason string
}
MalformedError is returned when an input contains a syntactically invalid format-string reference: an unclosed "{{", an empty or whitespace-only name, or a name that is not a valid dotted OpenJD identifier.
func (*MalformedError) Error ¶
func (e *MalformedError) Error() string
type MapScope ¶
MapScope is a Scope backed by a plain map from fully-qualified variable name to value.
type Scope ¶
Scope resolves a fully-qualified OpenJD variable name (for example "Task.Param.Frame") to its string value. Lookup reports ok=false when the name is not present in the scope; callers must distinguish a missing name from a name whose value is the empty string.
func MultiScope ¶
MultiScope composes scopes into a single Scope. Lookup consults the scopes in the order given and returns the value from the first scope that contains the name, so earlier scopes take precedence over later ones.
type UnresolvedError ¶
type UnresolvedError struct {
Names []string
}
UnresolvedError is returned by Resolve when one or more references name variables that the Scope does not provide. Names lists every distinct unknown variable in order of first appearance.
func (*UnresolvedError) Error ¶
func (e *UnresolvedError) Error() string