在映射内缩进 YAML 序列
以下内容应该有效吗?
parent:
- child
- child
所以我们拥有的是映射内的一系列值。
具体问题是第2行和第3行的缩进是否有效。 Ruby YAML.dump 生成了此代码,但 Yaml 解析器此处拒绝了它,因为子行没有缩进。
即它想要这样的东西:
parent:
- child
- child
谁是对的?
看看 YAML 规范,它肯定不明显,并且该行
“-”、“?”和“:”用于表示块集合条目的字符被人们认为是缩进的一部分
并没有多大帮助。
Should the following be valid?
parent:
- child
- child
So what we have is a sequence of values inside a mapping.
The specific question is about whether the indentation for the 2nd and 3rd lines is valid. The Ruby YAML.dump generated this code, but the Yaml parser here rejects it, because the child lines are not indented.
i.e. it wants something like:
parent:
- child
- child
Who is right?
Looking at the YAML spec, it's certainly not obvious, and the line
The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation
doesn't help much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是合法的 YAML。规范中的相关文本位于此处:
以及随后的示例 8.22:
Yes, that is legal YAML. The relevant text from the spec is here:
and the subsequent example 8.22: