Hi there,
I’ve been digging around in Psych’s lowlevel interface the last few
hours, but I couldn’t find what I was looking for. Given this YAML file:
foo:
bar:
baz: 3
blubb:
baz: 4
How can I find the line number the key(chain) foo-bar-baz is in (that
is, 3 in this case)? I’ve found Psych supports a nice visitor pattern
for parsing, but it seems to not provide the line numbers of the
elements it encounters. So, is there any way (monkey-patching if
necessary) to get the line numbers out of Psych?
Background: I want to programmatically insert comments into an existing
YAML file and as I’ve already found out, inserting comments with Psych
is impossible. That is, I want to say “insert this comment before the
key foo-bar-baz”.
Thanks in advance.
Marvin