Re: : in the flow context for PyYAML and SnakeYAML
Kirill Simonov <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Andrey,
On 08/18/2010 03:13 AM, Andrey Somov wrote:
> Hi all,
> according to http://pyyaml.org/wiki/YAMLColonInFlowContext colon in
> the flow context does not work according to the 1.1 specification in
> PyYAML.
> PyYAML follows "pythonic" way instead of implementing language-neutral
> solution. It causes compatibility issues with other languages.
> There is an issue reported for SnakeYAML to address the problem -
> http://code.google.com/p/snakeyaml/issues/detail?id=78
>
> The ticket for PyYAML is created but there is no progress -
> http://pyyaml.org/ticket/158
>
> I am not really in favor to fix the problem only in SnakeYAML as we
> find it important that any valid document for SnakeYAML is always
> valid for PyYAML and vice versa.
As far as I remember, the YAML 1.1 spec claims that ':' is a valid
character for a plain literal if it is not followed by a whitespace, and
the mapping separator is ': ' (colon followed by a whitespace). I
strongly disagreed with it because it does not follow Python or
Javascript conventions, but I didn't want to decide one way or another
until some consensus is reached. So I made ':' (colon followed by a
non-whitespace character) an error when it is a part of a plain literal
in the flow context.
I haven't checked the YAML 1.2 specs, but I believe the rules were
relaxed to facilitate JSON compatibility. AFAIK, the mapping separator
is now ':' (colon), but colon is still a valid character in a plain
literal and if it is not followed by a whitespace, it is interpreted as
a part of the literal rather than a mapping separator. Thus a JSON
expression like {"foo":1} is now a valid YAML. The solution is still
not that great since a valid Python or Javascript expression like {1:1}
has a different meaning in YAML (in this case, {'1:1': null}). I'm not
sure how much this is a problem in practice though.
I believe there was another proposal (which I like even less): forbid
':' in mapping keys, but allow them in mapping values. Unfortunately it
creates ambiguities in expressions like [foo:bar], which could be
interpreted both ways.
Note that my understanding of the YAML specs could be incorrect: it was
a long time ago since I last read them.
Thanks,
Kirill
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d