lyaml icon indicating copy to clipboard operation
lyaml copied to clipboard

Empty mapping and empty sequence cannot be distinguished after load

Open geert56 opened this issue 1 year ago • 2 comments

Using lyaml.load() any empty (flow) mappings and sequences cannot be distinguished in the returned Lua table. Both will show up as an empty table. With minimum disruption this can be easily fixed by optionally (opts.distinct_sequence) allowing load_sequence to return {{}} in case of #sequence == 0.

geert56 avatar Mar 12 '23 01:03 geert56

I have to shoot down my own proposal. Using {{}} for an empty sequence now clashes with a singleton sequence with the empty mapping as sole element. So maybe attaching a dummy metatable to an empty table makes the distinction.

geert56 avatar Mar 12 '23 14:03 geert56

Care to propose a PR?

gvvaughan avatar Mar 12 '23 21:03 gvvaughan