Expand description
Port of internal/variables/expand.go: shell-like ${VAR}/$VAR
expansion of config values and variable definitions.
The Go original parses each string as a mvdan.cc/sh/v3 shell document
word and walks/rewrites that AST. There is no equivalent Rust crate with
this exact operator set, so this is a hand-rolled scanner/parser scoped
exactly to the grammar caproni uses: $VAR/${VAR} references, the
${VAR:-default}/${VAR:?message}/${VAR:+alternate} (and their
unset-only ${VAR-x}/${VAR?x}/${VAR+x} variants) operators for
variable definitions, ${#VAR} length, ${!VAR} indirection,
${VAR:off:len} slicing, ${VAR/pat/repl}/${VAR//pat/repl}
replacement, and ${VAR#pat}/${VAR##pat}/${VAR%pat}/${VAR%%pat}
prefix/suffix removal – plus verbatim (never evaluated) preservation of
$(...), `...`, $((...)) and <(...)/>(...).
Pattern arguments to /, # and % are matched as literal substrings,
not shell globs, because nothing in caproni’s config surface uses glob
metacharacters there; this is a deliberate scope reduction from the Go
original’s full glob matching.
Structs§
- Unresolved
- Records the references in one config value that resolved to nothing.
Enums§
Functions§
- expand_
definition - Expands a variable definition, where the
${VAR:-default},${VAR:?message}and${VAR:+alternate}operators are available on top of the bare references config values take. - expand_
map - Walks a parsed config mapping and expands references in every string
value, in place. The top-level
"variables"subtree is left untouched. - expand_
string - Expands
${VAR}/$VARreferences ins. A reference that resolves to nothing becomes the empty string.