(?) YEP-1: Adding reserved name for anchor
Not sure where proposals for new YAML features reside so I post this YEP (YAML enhancement proposal) here.
It would be useful to have an easier way of defining anchor with the same name as node key. I often find myself writing
someKey: &someKey
It's time/type consuming to write and a possible source of typos.
I propose a reserved name for the anchor which will denote that the name of the anchor will be the same as of the node key. Its alias will stay the same.
Some reserved name proposals:
-
_like name for last returned value in Python's interactive shell -
?same as Bash shell variable holding exit status of last command
Usage in YAML would then be someKey: &_ or someKey: &?
Thanks for contributing. We don't have a proper RFC process set up yet, so for now an issue is fine.
Some initial thoughts:
- Both
&_and&?are currently valid anchor names. What would happen if there were an anchor*_or*?in the document? - Currently, aliases and anchors are identified as the first step of composition, before tags are resolved and the canonical form of scalar content is available, so the anchor name would have to be based on the key node's formatted content.
- What if the mapping key is not a scalar node? What if it's a scalar, but its formatted content is not a valid anchor name?
What about just allowing the anchor symbol to precede keys — so they key doubles as key and anchor — you can differentiate them from non-key anchors because they are followed by a :
&someKey:
blah: 1