jomini
jomini copied to clipboard
Writer support unknown container type and to query it
While being able to parse data iteratively has its benefits, there's the downside that one doesn't know if '{' represents an object, an array, or a combination of the two. This has posed a problem to downstream melters as we often need to strip the quotes on object keys, but we don't know if we're in an object! Melters have worked around this problem by hardcoding keys.
This isn't a great workaround as new keys added with a patch will need to be tested.
Instead this commit introduces this unknown state to the writer with write_start
. Behaviorally, writers will still act the same (assuming it is an array until an equal is written), but this also allows for downstream melters to query the writer and stash away a quoted value until the next token (if it is an equal we know to strip quotes, otherwise the quoted value can written as usual).
Alternatively the melters could keep track of this state themselves, but since it's a low-lift to track this with writers, it seemed like a good fit.