Documents starting with a triple dash #237
-
I came across a behaviour I am not sure is expected or an issue: When a yaml document starts with a triple dash (---) the parser seems to return an empty document. So, ---
test: 1 Has no children with a key of test. The reason I came across this is ansible yaml documents start with three dashes and a new line. I am using the python API. Is this expected? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yes, this is expected behavior -- but not exactly like you describe. The explanation is this: documents must be nested in a stream node. So when a To be clear: ryml::Tree withoutStream = ryml::parse_in_arena("test: 1\n");
// node0 MAP
// ` node1 KEYVAL "test" "1"
ryml::Tree withStream = ryml::parse_in_arena("---\ntest: 1\n");
// node0 STREAM
// ` node1 DOCMAP
// ` node2 KEYVAL "test" "1" By the way, to get at the document, you can use the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response, this was what I suspected but wasn't sure of the why |
Beta Was this translation helpful? Give feedback.
Yes, this is expected behavior -- but not exactly like you describe. The explanation is this: documents must be nested in a stream node. So when a
---
token appears, aSTREAM
node is created as the tree's root, and the document is provided as a child of the root node. This is because a---
token has a semantic role, so its presence/absence will have an impact in the tree.To be clear:
By the way, to get at the document, you can use the
Tree::docref()
me…