Re: : in the flow context for PyYAML and SnakeYAML

Kirill Simonov <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
On 08/25/2010 04:11 PM, William Spitzak wrote:
> Kirill Simonov wrote:
>> Hi William,
>>
>> If you take a look at the function yaml_parser_scan_plain_scalar, lines
>> 3424-3433, you'll see:
>>
>> /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */
>>
>> if (parser->flow_level
>>          &&  CHECK(parser->buffer, ':')
>>          &&  !IS_BLANKZ_AT(parser->buffer, 1)) {
>>      yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
>>              start_mark, "found unexpected ':'");
>>      goto error;
>> }
>>
>> This condition is only checked in the flow context and it produces an
>> error if there is a colon followed by a non-whitespace character.
>
> You are right, my compiled version has that line commented out, as I had
> to fix it to read some JSON text. My personal opinion is that this MUST
> be changed. I had to fix it to read JSON output and I can't be the only
> one. There are VAST amounts of "unquoted" JSON out there, probably the
> majority! If YAML has any intention of being JSON-compatible it must fix
> this.

By unquoted JSON, do you mean something like:
     {foo:"bar"}

This is definitely not a valid JSON and I'm certain most of the JSON 
parsers will fail to parse it.  I'd say that an ability to parse this 
expression has nothing to do with JSON-compatibility, though you could 
claim it is Javascript-compatibility.

I believe both YAML 1.1 and 1.2 interpret this document as
     {'foo:"bar"': null}
PyYAML and libyaml producing an error is a stub; I intended to replace 
it with one interpretation or the other once I make up my mind. 
Producing an error allows me to choose the interpretation without 
breaking existing valid YAML documents.

> I have unfortunatly drifted away from YAML. I am using my patched
> version of the parser, but am not using any code for emitting it.
> Instead I wrote a much faster one which outputs YAML with "flow" turned
> on all the time, and with the ability to put newlines between the "flow"
> items. I quote everything containing any characters other than
> alphanumeric, period, underscore, +, or -.
>
> I am increasingly of the belief that a correct format would be more like
> JSON with optional quoting, with the addition of "type" and the addition
> of cross-references. Currently I am persuing this, though I am following
> the YAML discussion in case something interesting comes up.

Well, YAML is JSON with optional quoting, types, cross-references, and 
also block styles.


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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.