summaryrefslogtreecommitdiff
path: root/hclsyntax/token.go
diff options
context:
space:
mode:
authorMartin Atkins <mart@degeneration.co.uk>2022-06-09 16:29:19 -0700
committerJames Bardin <j.bardin@gmail.com>2023-10-24 10:54:03 -0400
commit83c95d29eef525594a70dd05027d93ff2f8f7c55 (patch)
tree8f71f3f29c232535af4aded55860fe4190496b5f /hclsyntax/token.go
parentd23a20ac41349e5f1cc7b60e76d1408069db498b (diff)
hclsyntax: Initial work on 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. 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 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 is still a subtle compatibility break for any implementation of the syntax-agnostic HCL API against another syntax, because it may now encounter function names in the function table that are not entirely valid identifiers. However, that's okay in practice because a calling application is always in full control of both which syntaxes it supports and which functions it places in the function table, and so an application using some other syntax can simply avoid using namespaced functions until that syntax is updated to understand the new convention. This initial commit only includes the basic functionality and does not yet update the specification or specification test suite. It also has only minimal unit tests of the parser and evaluator. Before finalizing this in a release we would need to complete that work to make sure everything is consistent and that we have sufficient regression tests for this new capability.
Diffstat (limited to 'hclsyntax/token.go')
-rw-r--r--hclsyntax/token.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/hclsyntax/token.go b/hclsyntax/token.go
index afde5f3..47648b8 100644
--- a/hclsyntax/token.go
+++ b/hclsyntax/token.go
@@ -63,8 +63,9 @@ const (
TokenDot TokenType = '.'
TokenComma TokenType = ','
- TokenEllipsis TokenType = '…'
- TokenFatArrow TokenType = '⇒'
+ TokenDoubleColon TokenType = '⸬'
+ TokenEllipsis TokenType = '…'
+ TokenFatArrow TokenType = '⇒'
TokenQuestion TokenType = '?'
TokenColon TokenType = ':'