hcl
hcl copied to clipboard
Prototype: Namespaced functions
This introduces a new syntax which allows function names to have namespace prefixes, with the different name parts separated by a double-colon ::
as is common in various other C-derived languages which need to distinguish between scope resolution and attribute/field traversal. (For example: C++, Rust, Ruby, and Perl.)
Because HCL has separate namespaces for functions and variables, we need to use different punctuation for each to avoid creating parsing ambiguity that could be resolved only with infinite lookahead.
We cannot retroactively change the internal representation of function names to be a slice of names without breaking the existing API, and so we instead adopt a convention of packing the multi-part names into single strings which the parser guarantees will always be a series of valid identifiers separated by the literal ::
sequence. That means that applications will make namespaced functions available in the EvalContext
by naming them in a way that matches this convention.
This addition should change nothing for any existing applications that only place single-identifier names in the EvalContext
function table, but allows applications to begin defining such functions when they are ready, with whichever namespaces they deem appropriate.