kubkon/zig-yaml

[feature]: support parsing comments in documents

ssteinbach opened this issue · 7 comments

I'm trying to open a yaml document like:

test_string: "hello!"
# this is a comment
other_thing: 12

If I remove the comment, the parse is successful, but if it is present, the parser errors with an unexpected token. Looking through the code it definitely seems to have references to comments, but I didn't see any in the yaml files in the repo, so I thought I would ask.

The error:

zig-yaml/src/parse.zig:339:21: 0x103042b55 in .yaml.parse.Parser.doc (visualizer)
                    return error.UnexpectedToken;

Thanks!

Hi @ssteinbach, thanks for submitting an issue! Yes, support for comments is not really there yet. Is that something you'd like to add to the parser perhaps? I'll be more than happy to help you out ofc if you choose to work on this! :-)

Hi @kubkon, I ended up falling back to the built in JSON parser. Unfortunately I don't have bandwidth to take that on at the moment. Sorry about that!

Not at all! That's also my problem, hahaha. I'll try to commit some more time to this though, and will keep you posted if something interesting develops!

awesome! Will check out the new parser!

awesome! Will check out the new parser!

Please do, and if you run into bugs (which you most likely will), please do flood me with issues! I will be doing more development on this parser in the coming weeks as I've neglected it long enough :-)

yay definitely works now! Only thing I noticed is that simple.yaml is missing a comment (for testing purposes) if you want to catch this kind of regression in the future. Thanks again for fixing this!

yay definitely works now! Only thing I noticed is that simple.yaml is missing a comment (for testing purposes) if you want to catch this kind of regression in the future. Thanks again for fixing this!

We test for comments in the main test suite

test "comments" {
so I don't think there is any value in adding comments into simple.yaml unless I'm missing something?