gvvaughan / lyaml

LibYAML binding for Lua.
gvvaughan.github.io/lyaml
Other
208 stars 34 forks source link

[feature request] line number information #26

Open hishamhm opened 5 years ago

hishamhm commented 5 years ago

Would it be at all possible to retain line number information for entries?

`result = lyaml.dump([[ foo:

I would like to get the information that foo[2] lives in line 4 of the input.

Two approaches come to mind:

Would something among these lines be a desirable feature? Are there any implementation hurdles to this I should be aware of in case I try implementing it? (i.e. does libyaml return position information?)

gvvaughan commented 5 years ago

Hi Hisham,

This feature is already available in the low-level API , and I use it in the spec file loader for specl. See lib/loader.lua in gvvaughan/lyaml for how to make use of it. The only real caveat is that libyaml counts character positions, but Lua uses bytes internally which makes it hard to deal with UTF-8 inputs.

I'd be very happy to take a PR that exposes the position information with a nice backwards compatible API for the high level parser. Most of the code is already written in specl, I just haven't yet needed to move it over myself yet.

Cheers, Gary