pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
241 stars 74 forks source link

Comment parsing doubts #45

Closed jlblancoc closed 2 years ago

jlblancoc commented 2 years ago

Hi @pantoniou :

I did some "stress tests" to the latest comment-parsing code, and found some edge cases (perhaps you were already familiar with them):

Parsing this block:

myMap:
  e1: 10.0  # Right comment for e1 value
myMap2:
  # Top comment for e2
  e2: 10.0
myMap3:
  # Top comment for e3
  e3: 10.0 # right comment for e3 value
# Top comment for myMap4
myMap4:
  ~
# Top comment for myMap5
myMap5:
  # top comment for a4
  a4: 1

generates these events:

>> Event: Stream start
>> Event: Doc start
>> Event: MAP START
>> token: 0x55a486fbd8d0 Scalar: implicit=0 tag: 0 anchor: 0 value: myMap
>> Event: MAP START
>> token: 0x55a486fbdde0 Scalar: implicit=0 tag: 0 anchor: 0 value: e1
>> token: 0x55a48705bcd0 Scalar: implicit=0 tag: 0 anchor: 0 value: 10.0
>> token: 0x55a48705bcd0 comment [1]: 'Right comment for e1 value'
>> Event: MAP END
>> token: 0x55a486fbdde0 Scalar: implicit=0 tag: 0 anchor: 0 value: myMap2
>> Event: MAP START
>> token: 0x55a486fbd8d0 Scalar: implicit=0 tag: 0 anchor: 0 value: e2
>> token: 0x55a486fbd8d0 comment [0]: 'Top comment for e2'
>> token: 0x55a48705bcd0 Scalar: implicit=0 tag: 0 anchor: 0 value: 10.0
>> Event: MAP END
>> token: 0x55a486fbd8d0 Scalar: implicit=0 tag: 0 anchor: 0 value: myMap3
>> Event: MAP START
>> token: 0x55a486fbdde0 Scalar: implicit=0 tag: 0 anchor: 0 value: e3
>> token: 0x55a486fbdde0 comment [0]: 'Top comment for e3'
>> token: 0x55a48705bcd0 Scalar: implicit=0 tag: 0 anchor: 0 value: 10.0
>> token: 0x55a48705bcd0 comment [1]: 'right comment for e3 value'
>> Event: MAP END
>> token: 0x55a486fbdde0 Scalar: implicit=0 tag: 0 anchor: 0 value: myMap4
>> token: 0x55a486fbdde0 comment [0]: 'Top comment for myMap4'
>> token: 0x55a486fbd8d0 Scalar: implicit=0 tag: 0 anchor: 0 value: ~
>> token: 0x55a486fbd8d0 comment [1]: 'Top comment for myMap5'
>> token: 0x55a486fbdde0 Scalar: implicit=0 tag: 0 anchor: 0 value: myMap5
>> Event: MAP START
>> token: 0x55a48705bcd0 Scalar: implicit=0 tag: 0 anchor: 0 value: a4
>> token: 0x55a48705bcd0 comment [0]: 'top comment for a4'
>> token: 0x55a486fbd8d0 Scalar: implicit=0 tag: 0 anchor: 0 value: 1
>> Event: MAP END
>> Event: MAP END

Note how "Top comment for myMap5" is reported as being a comment on the right of scalar ~, instead of its correct top comment of the next item, the map key "myMap5".

Hope this test case helps finding the issue...

pantoniou commented 2 years ago

Thanks for the test case. Yes, some times comment tracking is 'lost'. I'll try to see what's going on.

pantoniou commented 2 years ago

Fixed by c1fbdc699c73cf1f29ac3b46d4ee38709f8041f7

Let me know if this works for you and if it does please close the issue.

jlblancoc commented 2 years ago

Yep, fantastic, thanks! :100:

Whenever you want to make a new release, I'll try to get the package published into Debian...

jlblancoc commented 2 years ago

Oh, I saw you already made it. Good!