YAML::PP Grant Report November 2017
See also my previous reports on news.perlfoundation.org (Aug/Sep, Oct) and blogs.perl.org (Aug/Sep, Oct).
In November, I was working over 40 hours on YAML related stuff.
YAML::PP
I released version 0.005.
Flow Style partially implemented
Soooo, I managed to partially implement flow style collections and decided to push what I have so far, so a lot of YAML documents should now be parseable.
---
empty sequence: []
empty mapping: {}
sequence: [a, b, c]
mapping: { a: 1, b: 2 }
mixed: [ { a: 1 }, { b: 2 } ]
multiline: [
{ a: 1 },
{ b: 2 },
]
Anchors and Tags are not fully working; there are some places in the grammar where they need to be added.
What's not yet working is implicit keys, empty nodes and some more rarely used things:
---
[a]: 1
sequence with implicit mappings: [ a: 1, b: 2 ]
empty value: { a: !!str, b: "" }
Escapes in Double Quoted Strings
All valid escapes are now supported, and invalid ones are forbidden.
See "Quoted Strings" below for more details on this.
Small improvements
Allow unicode in alias/anchor names
---
- &😁 unicode anchor
Document header at the end is now recognized
# document one:
---
a: b
...
# document two with an empty node:
---
Multiline quoted strings must be indented
Forbid sequence or mapping as a mapping value on the same line
---
# invalid
a: b: c
d: - e
Forbid sequence after an anchor/tag on the same line
# invalid:
---
&sequence - a
...
# valid:
---
&sequence
- a
Moved plain multiline handling to grammar
As always, you can have a look at the current test suite results.
YAML Test Suite
I added 7 tests and added data / fixed some other tests.
YAML Editor
I added pyyaml-json and ruamel-json to the editor.
YAML Test Matrix
I added pyyaml-json, pyyaml-py, ruamel-json and ruamel-py to the matrix view. Now we can also see how PyYAML and ruamel Loaders are passing the test suite.
YAML::PP is actually looking quite good already: YAML Test Matrix
YAML::XS
I finished implementing Boolean Object support. See my previous report on this.
I added support for !!str
, !!seq
and !!map
. These are standard tags in
YAML 1.1, and YAML::XS previously died when finding these tags.
While these are rarely used, it at least makes it look a bit better on the Test Matrix ;-)
!!seq
and!!map
don't have any effect in most cases!!str
will force the scalar to be a string instead of a number or a boolean, for example
!!int
, !!float
and !!bool
should also be added, but this will be a bit
more work.
I released version 0.67.
London Perl Workshop
I gave two talks at the London Perl Workshop:
- A 20 minute talk about YAML in general and Perl Modules
- A lightning talk about YAML::PP
Quoted Strings
In YAML, you have four ways to "quote" strings.
Single quotes
The content of single quoted strings will be taken literal. To escape a single quote, you double it:
string: 'this contains one '' singlequote'
You can also have a multiline quoted string like that:
string: 'this will
all be
folded to
one line
but this
will be in a seperate line'
Lines are folded, unless there is an empty line.
Double quotes
Double quotes work the same way as single quotes, but you can use escapes here. A double quote itself is escaped with a backslash. Double quoted strings are the only way to use escapes.
This is from example 5.13 from the Spec:
"\\ \" \a \b \e \f
\n \r \t \v \0
\ \_ \N \L \P
\/
\x41 \u0041 \U00000041"
The last line is just A
in three different escape styles.
It is important to note that the backslash is only allowed for those
escapes. A \.
, for example, is invalid.
Folded Block Scalar
I could write a whole blog post on Folded Block Scalars, so here is just a short version:
---
folded: >
this will
all be folded
to one line
but this will be on a seperate line
The folding works the same as in quoted strings, with some extra rules.
By adding a chomp indicator you have more influence on trailing newlines.
>-
will chomp trailing empty/newlines, >+
will keep them. By default,
the last newline will be kept, only trailing empty lines are removed.
Literal Block Scalar
Literal style differs from folded, in that lines are not folded, and any trailing spaces will be kept.
literal: |
line 1
line 2
line 4
Tutorial
No, I haven't written a tutorial, but I would like to do so. This is of course a whole task on its own, and a more language agnostic one. I have some ideas how to make it useful.
I can find many short YAML tutorials out there. Many of them are missing important basics or are slightly incorrect. Some are actually specific for the platform/program they are used in, like this one for Ansible. Note the example of block scalars and the incorrect explanation ;-)
For making YAML better, we don't only need all parsers/loaders behave in the same way, we also need a comprehensive tutorial that is correct.
With the test suite, we already have a lot of examples we can refer to, by the ID or by tag names. And with YAML::PP, it's easy to create syntax highlighted examples.
Leave a comment