开发者

Yaml ambiguity; indentation spaces and empty node

I wrote:

a:
-b
-c

Parser understood it as:

!!map {
  ? !!str "a"
开发者_如何学编程  : !!seq [
      !!str "b",
      !!str "c"
    ]
}

But I meant:

!!map {
  ? !!str "a"
  : !!null ""
}
!!seq [
  !!str "b",
  !!str "c"
]

The specification says:

The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation. This is handled on a case-by-case basis by the relevant productions.

So both interpretations are permissible? If not, can you point out section in specification which prevents it?

Depending on "case-by-case basis by the relevant productions" ? What are "relevant productions"?


Your example isn't parsable by PyYAML 3.11.

http://yaml-online-parser.appspot.com/?yaml=a%3A%0A-b%0A-c&type=json

Try this:

a:
- b
- c

http://yaml-online-parser.appspot.com/?yaml=a%3A%0A-+b%0A-+c&type=json


Try this:

- a: 
- b
- c
%YAML 1.1
---
!!seq [
    !!map {
        ? !!str "a"
        : !!null "null",
    },
    !!str "b",
    !!str "c",
]
...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜