biojppm/rapidyaml

Question: filter utility use case

Closed this issue · 3 comments

I want to parse a series of input yamls (either enclosed each to regular JSON {"config": ...} or [] or delimited by --- (except probably last)), parse them by the library and output something further in a pipe. I.e. to make a program, that acts like a filter. Each input yaml is a new config specific for each step. At some step stdin should be closed. Can parser be used in this manner? Seems it should not be like SAX vs DOM, I think, but some rough granularity of input should be maintained from the library side.

I'm not sure I understand your question. However, this flow outline may help:

  1. Is it a single input? yes->2 or no->5
  2. input is valid YAML? yes->3 or no->4
  3. Parse, and apply the input.
  4. Split the input until each of its parts is valid yaml. ->5
  5. For each input -> 2

ryml can help you in all steps. To split strings (if needed) you can use the split facilities in ryml::csubstr which are very efficient for general use.

More importantly, if you parse a sequence of inputs, you can choose where the new input should go to (ie you can choose the target node) by using the appropriate parse overload or parser method.

You can also merge branches as needed using the tree merge facilities.

To be more specific, I would need a clearer example of your use case.

BTW, you may also want to look at http://github.com/biojppm/c4conf which does a similar thing.

Closing now. Feel free to reopen with a more concrete question.