What is the << (double left arrow) syntax in YAML, and where is it indicated?

<<: operator <<: in YAML, you can import the contents of one mapping into another, similar to the double-splat ** operator in the Python object destruction operator or ... in JavaScript. For instance,

 foo: a: b <<: c: d e: f 

equivalently

 foo: a: b c: d e: f 

This is useful when used with node anchors to include some common default properties in many objects, as shown, for example, Learn YAML in Y minutes :

 # Anchors can be used to duplicate/inherit properties base: &base name: Everyone has same name foo: &foo <<: *base age: 10 bar: &bar <<: *base age: 20 

However, I am confused about where this syntax comes from, or why it works. CTRL + F in the YAML specification for << indicates that it does not appear anywhere in the specification. However, it is supported by at least PyYAML and http://yaml-online-parser.appspot.com/ .

What is this syntax, and why does it not appear in the specification?

+6
source share
1 answer

It is called type-independent key type for YAML version 1.1. and speced here

This is something that parsers can optionally support, it is, in essence, an interpretation of a key-value pair with a special key << , where this value is either a mapping (possibly indicated by an alias) or a list of mappings, and is interpreted in a special way.

+6
source

Source: https://habr.com/ru/post/1013037/


All Articles