YAML spec inconsistencies + Question on marshalling

Eemeli Aro <[email protected]> Wed, 31 Jan 2018 21:53:36 +0200
Newsgroups gmane.text.yaml.general
Message-ID <CAFuwTa77AcY7a6qOxTu38JJD=KLWUS=U_O6ZEXoQ85JQbQwq2w@mail.gmail.com>
Hi all,

I'm working on a new JavaScript YAML 1.2 library, and while testing my
code against the examples given in the spec, I've come across a couple
of inconsistencies. I trust this might be a good place to ask about
them?

When a non-strip block scalar appears as the last entry in a file that
is not terminated by a newline, should the value of that scalar still
include a terminating newline? In the spec, example 6.4 appears to do
so, while example 8.21 does not. My own preference here would be to
always include a newline, as otherwise it's very easy to alter the
value while processing, especially when reordering documents in a
stream.

Is there a mistake in the parsing of the "keep" value of example 8.5?
Specifically, should its value be "# text\n\n" rather than "# text\n"?
It's followed by dedented comment lines, and the second newline is
highlighted in the source as being a part of the l-keep-empty(n)
production. The following example 8.6 similarly highlights the (only)
line of its "keep" value with the same production, but shows that
newline to be a part of the resulting value.

On a different note, would anyone have good pointers for
implementations of marshalling YAML scalars? For instance, when a map
includes multiple different numerical values, and some of them are (or
should be) stored as hexadecimal while others as decimal, how do other
implementations control this and/or guarantee that a load/modify/dump
cycle won't normalise all of these numbers to a single style of
representation?

My code so far is at https://github.com/eemeli/yaml and
https://github.com/eemeli/raw-yaml; only the latter lower-level
interface is published so far on npm.

eemeli

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot