Open hishamhm opened 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
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:
getmetatable(result.foo[2].line)
result, lines = lyaml.dump(input, { lines = true } )
I could do either:assert(lines[foo[2]] == 4)
assert(lines.foo[2] == 4)
-- this option would allow us to even doassert(lines.foo[2].bla)
to get the position of non-table items tooWould 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?)