除非我使用流式,否则为什么YAML别名不起作用?

时间:2013-01-26 01:27:28

标签: yaml

如果您运行此YAML 1.1

- &first {'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]}
- *first
- &second 'second':
    - 'description'
    - ['aliases']
    -
        - "Explanatory sentences "
        - "go here."
- *second

YAMLlint,你得到了这个:

--- 
- 
  first: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- 
  first: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- 
  second: 
    - description
    - 
      - aliases
    - 
      - "Explanatory sentences "
      - "go here."
- second

请注意,first组重复两次,而second组仅显示一次,只显示重复块的名称。 first组和second组具有完全相同的数据 - 唯一的区别是布局。为什么别名不适用于second组?

1 个答案:

答案 0 :(得分:1)

我最好的猜测是&锚具有非常高的优先级。我试过这个

- &first 'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]
- *first

而不是:

- &first {'first': ['description', ['aliases'], ["Explanatory sentences ", "go here."]]}
- *first

突然它的行为与second组的行为方式相同。因此,除非您在更大的节点中明确包含'first',否则&first锚点只会附加到'first'字符串,而不是其他内容。