Can't use anchor for anchor
This YAML will fail:
test-list:
- &1
a: 1
b: 2
- &2 <<: *1
- &3 <<: *1
- <<: *2
Replacing “2” to “1” in last line will fix it. Why?
I сhoose this priority because this functionality is needed for my project, but I can use “1” even though it is not convenient.
Comments (10)
-
reporter -
reporter it’s works here for example
-
I think you found a bug. It will not be easy to fix.
The problem is that the node “<<: *2” is parsed as scalar but it represents a mapping.
The same bug is in PyYAML.
-
reporter Maybe you can use another interpreter? I have found this comparison (if it can be helpful).
-
reporter more realistic example:
settings-list: - &1 a: 1 b: 2 c: 3 #and many more params. - &2 <<: *1 a: 11 b: 22 - &3 <<: *2 c: 5 some-object: properties: *2 another-object: properties: *3
-
What is “another interpreter“ ?
-
Please be aware that merging is very controversial feature.
It has been removed in the next spec. YAML 1.2 does not have the merge.That is why the SnakeYAML Engine does not implement merging.
-
I added a test.
-
reporter What is “another interpreter“ ?
never mind, I was wrong.
YAML 1.2 does not have the merge.
Here is how! I did not know.
Ok and how do I use anchors correctly?
I added a test.
not understood. where?
-
Ok and how do I use anchors correctly?
you use them correctly. But you use merge tag “<<“ together with aliases. This tag is deprecated and removed in the next spec YAML 1.2
not understood. where?
check the latest source code
- Log in to comment
@Andrey Somov буду рад диалогу на русском)