Skip to content

Documents starting with a triple dash #237

Answered by biojppm
stevebleazard asked this question in Q&A
Discussion options

You must be logged in to vote

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, a STREAM 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:

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 Tree::docref() me…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by stevebleazard
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants