在映射中缩进 YAML 序列 [英] Indenting a YAML sequence inside a mapping

查看:37
本文介绍了在映射中缩进 YAML 序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容是否有效?

parent:
- child
- child

所以我们拥有的是映射中的一系列值.

So what we have is a sequence of values inside a mapping.

具体问题是关于第 2 行和第 3 行的缩进是否有效.Ruby YAML.dump 生成了此代码,但 Yaml 解析器 here 拒绝它,因为子行没​​有缩进.

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.

即它想要类似的东西:

parent:
  - child
  - child

谁是对的?

看YAML规范,肯定不是很明显,而且行

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

帮助不大.

推荐答案

是的,这是合法的 YAML.规范中的相关文本是此处:

Yes, that is legal YAML. The relevant text from the spec is here:

由于人们将-"指示符视为缩进,因此嵌套块序列可能会缩进一个空格以进行补偿,当然,如果嵌套在另一个块序列中(块出上下文与块入上下文).

Since people perceive the "-" indicator as indentation, nested block sequences may be indented by one less space to compensate, except, of course, if nested inside another block sequence (block-out context vs. block-in context).

以及随后的示例 8.22:

sequence: !!seq
- entry
- !!seq
 - nested
mapping: !!map
 foo: bar

这篇关于在映射中缩进 YAML 序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆