neon
neon copied to clipboard
RFC: Anchors, References, Extend
Prologue
I'd like to propose a new NEON features. I named them anchors, references, extend. It basically came from YAML (https://en.wikipedia.org/wiki/YAML#Syntax, https://blog.daemonl.com/2016/02/yaml.html).
When you are using NEON in nette-like applications, you are probably using it for service definitions. I consider current syntax as complete and don't miss anything.
However, when you are using NEON as standalone tool for some kind of definition schema, I found myself to miss some features like extending and referencing. I have 1000+ rows in one NEON file and DRY principle comes very handy in here.
Anchors & References
YAML
foo: &anchor
K1: "One"
K2: "Two"
bar: *anchor
Result
{
"foo": {
"K1": "One",
"K2": "Two"
},
"bar": {
"K1": "One",
"K2": "Two"
}
}
NEON
# A
foo: &anchor
bar: *anchor
# B
foo: &(anchor)
bar: $(anchor)
# C
foo: =$(anchor)
bar: $(anchor)
& and * has no special meaning in NEON, am I right?
Extending
YAML
foo: &anchor
K1: "One"
K2: "Two"
bar:
<<: *anchor
K2: "I Changed"
K3: "Three"
Result
{
"foo": {
"K1": "One",
"K2": "Two"
},
"bar": {
"K1": "One",
"K2": "I Changed",
"K3": "Three"
}
}
NEON
# A
foo: # depends on anchor
bar: <<$anchor
# B
foo: # depends on anchor
bar: ...$anchor
It's an idea of adding extra features to NEON. Maybe someone think the same way. Thanks for a feedback.
List of resources
- https://ne-on.org/
- https://en.wikipedia.org/wiki/YAML#Syntax
- https://blog.daemonl.com/2016/02/yaml.html
- https://docs.gitlab.com/ee/ci/yaml
- http://blogs.perl.org/users/tinita/2019/05/reusing-data-with-yaml-anchors-aliases-and-merge-keys.html
I have to say, I don't like this about YAML at all.
- I feel like this doesn't belong in a text format. It's like asking a *.txt file to spell check.
- The syntax is completely unintuitive and I wouldn't be able to write it without documentation.
So let me ask you the other way around. What do you need it for?