-
Notifications
You must be signed in to change notification settings - Fork 349
Description
With @yaml(,tag) (b1a58bd), CUE can emit custom YAML tags on struct fields. However, nested tags (tags on individual sequence elements) cannot be expressed because the grammar doesn't allow attributes on list elements.
Example: Authentik blueprints use !Format [pattern, !Env VAR]:
oidc_well_known_url: !Format
- https://login.microsoftonline.com/%s/v2.0/.well-known/openid-configuration
- !Env AZURE_TENANT_IDThe natural CUE would be:
oidc_well_known_url: [
"https://login.microsoftonline.com/%s/v2.0/.well-known/openid-configuration",
"AZURE_TENANT_ID" @yaml(,tag="!Env"),
] @yaml(,tag="!Format")This is a syntax error today.
Prior issues
- Allow attributes for list elements #774 @mpvl: "it arguably should" be allowed, "list elements are almost indistinguishable from struct fields, so this would be consistent"
ElemAttrTODO incue/attribute.goandinternal/attrs.goplanned but never implemented- Support attributes in let declaration #949 -- same limitation for
letdeclarations
Proposal
Extend ElementList to allow trailing attributes, mirroring Field:
Element = Embedding { attribute } .
AST: a general AnnotatedExpr wrapper (reusable for future positions like let per #949):
type AnnotatedExpr struct {
X Expr
Attrs []*Attribute
}Parser: in parseListElement(), call parseAttributes() after the expression and wrap in AnnotatedExpr if present.
YAML encoder: in encode(), unwrap AnnotatedExpr and apply extractYAMLTag() to the resulting node.
This pattern also appears in CloudFormation (!Join containing !Ref) and other YAML-based config formats.
Purely additive, all existing CUE files remain valid, no change to evaluation semantics.