YAML::PP Grant Report March 2018

Hello readers,

I hope you had a nice easter weekend.

I had another busy month and worked about 25 hours on YAML.

YAML::PP

I released YAML::PP version 0.006.

I fixed various small bugs in the emitter.

It is now able to emit empty mappings and sequences as {} and [].

Like the YAML::PP::Constructor, I added YAML::PP::Representer.

Both take the chosen Schema into account, so that you should be able now to correctly dump booleans, numbers and strings. There's still something todo. Numbers can't be reliable differentiated from strings in perl, so there might be cases when numbers will be output as strings, or the other way round.

I'd like to mimic the behaviour of JSON::PP and Cpanel::JSON::XS, as this seems to be the most intuitive way. There is no single correct way, though.

As the schema is extendable, it should also be possible to alter the behaviour by the user.

Single quotes for strings will be added if a plain scalar would be invalid or would be loaded as a number, undef or boolean.

Double quotes are added if the string contains control characters, including \n.

Please play with it and report bugs if you find that the output doesn't look like you would expect. I'm sure there are still things todo.

The emitter will only emit block scalars if requested, and the output will not yet be correct for many cases.

The emitter cannot yet output flow style collections, except empty ones, as they are the only way to express empty collections.

I added another command line utility to show the output of the emitter when using the exact parsing events it got from the input:

% echo "---
foo: &anchor bar" | yamlpp5-parse-emit
---
foo: &anchor bar

So there are five utilities right now:

  • yamlpp5-events - Show parsing events in YAML Test Suite format
  • yamlpp5-highlight - Highlight input with ANSI Colors
  • yamlpp5-load - Load input and dump with Data::Dumper
  • yamlpp5-load-dump - Load and dump with YAML::PP
  • yamlpp5-parse-emit - Parse and pass events directly to the emitter

You can see all results from the test suite on this page: YAML-PP-p5/test-suite.html

I'll add the output of YAML::PP::Parser | YAML::PP::Emitter to that page soon.

Maybe you know Ingy's YAML::Shell utility. You can also use it with YAML::PP:

% ysh -MYAML::PP
Welcome to the YAML Test Shell (YAML::PP)

Type ':help' for more information.

ysh > ---
yaml> sequence:
yaml> - a
yaml> - b
yaml> ...
$VAR1 = {
  'sequence' => [
    'a',
    'b'
  ]
};
ysh > ;
perl> { foo => 23 }
perl> ;
---
foo: 23
ysh >

Other YAML related stuff

I added four test cases to the test suite. I took part in discussions about the test suite. Another author of a Javascript YAML 1.2 processor started to use the test suite and made some suggestions.

Adding test output for the emitter is still a big todo. This highly depends on how the processor decides which layout and style to use for the output.

I also did my first Python pull request, for PyYAML. As of Python 3.7, the order of dictionaries (hashes) is guaranteed to be preserved, so in that case it can be useful to not sort keys when dumping, so the output YAML will have the same order. I added an option for that to PyYAML (not yet merged).

Leave a comment

About tinita

user-pic just another perl punk,