biojppm/rapidyaml

Parsing map keys with '?' (explicit key) in event-based parser does not call actually_val_is_first_key_of_new_map_block

Closed this issue · 3 comments

I encountered an issue while using the event-based parser in rapidyaml. When parsing map keys that use the '?' key (explicit key), the function actually_val_is_first_key_of_new_map_block is not called.

Steps to reproduce:

  1. I used tools/ryml-yaml-events to verify the behavior.
  2. To make the output clearer, I applied the patch from this commit.
$ cat ng.yaml
? {foo: bar}
: hoge
$ ./build/tools/ryml-yaml-events ng.yaml
+STR
+DOC
+MAP
+MAP {}
=VAL :foo
=VAL :bar
-MAP
=VAL :hoge
-MAP
-DOC
-STR

When not using the explicit key, actually_val_is_first_key_of_new_map_block is called:

$ cat ok.yaml
{foo: bar}
: hoge
$ ./build/tools/ryml-yaml-events ok.yaml
+STR
+DOC
+MAP actually_val_is_first_key_of_new_map_block
+MAP {}
=VAL :foo
=VAL :bar
-MAP
=VAL :hoge
-MAP
-DOC
-STR

Thanks for reporting! Allow some time to investigate.

There is nothing wrong here, except that

{foo: bar}
: hope

is invalid YAML. On the other hand, both {foo: bar}: hoge and

? {foo: bar}
: hope

are valid, and equivalent.

As for rapidyaml's behavior with the leading ?, the question mark enables the parser to enter into a state where it knows any map is a key as soon as it starts, so no later call to actually_ is needed.

BUT there is an actual problem with rapidyaml in that it tolerates the invalid YAML. It should error out. This issue will track that.

Thank you for the reply, investigation, and for adding the test cases.
I apologize for presenting invalid YAML.
I understand why actually_val_is_first_key_of_new_map_block was not being called.
Upon reviewing the code I wrote, I found a bug.
After fixing the bug, the behavior was as intended.
Therefore, I will close this issue.