YAML Specification

repository·main·Indexed 19 days ago

https://github.com/yaml/yaml-spec

The official development environment and source for the YAML Data Language Specification, including versions 1.2.0, 1.2.1, and 1.2.2. This repository manages the generation and publishing of the spec.yaml.io website using a Jekyll-based build system and Docker. It contains the primary specification source files in Markdown, YAML, and LaTeX, as well as a glossary covering YAML node types, scalar styles, and the loading and dumping processes.

Tokens
29.9K
Snippets
94
Records
156
Agent score
67%

What's inside yaml-yaml-spec

  1. Overview of the YAML Specification Repository

    main
    This repository serves as the development environment for the YAML Data Language Specification. It contains the source code and build system used to publish the official YAML 1.2 specification (located in the 1.2 directory). The repository is used to define and incrementally add components for future versions of the YAML language.
  2. Overview of YAML 1.2

    main

    YAML (YAML Ain’t Markup Language) is a human-friendly, Unicode-based data serialization language. It is designed to represent native data structures from agile programming languages (like Python, Ruby, and JavaScript) using three basic primitives:

    • Mappings: Key-value pairs (hashes/dictionaries).
    • Sequences: Ordered lists (arrays/lists).
    • Scalars: Individual data values (strings, numbers, etc.).

    YAML is commonly used for configuration files, log files, interprocess messaging, and object persistence.

  3. Compare YAML flow scalar styles

    main

    YAML provides three flow scalar styles, each offering a different trade-off between readability and expressive power:

    1. Double-Quoted (`"..."): Most expressive. Supports arbitrary strings via escape sequences. Best for strings containing special characters or requiring specific control characters (like tabs or newlines).
    2. Single-Quoted ('...'): Moderate expressiveness. Supports printable characters. Escaping is limited to doubling single quotes ('').
    3. Plain (unquoted): Most readable, least expressive. No escaping allowed. Highly sensitive to context and restricted by character combinations (like : or #).
  4. Understand the 1.2.2 YAML Spec source directory layout

    main

    The spec/1.2.2/ directory contains the raw source files (Markdown, YAML, and LaTeX) used to generate the published YAML 1.2.2 specification.

    Key files include:

    • spec.md: The primary YAML specification source file currently under development.
    • links.yaml: A file used to manage internal link references to keep the main specification file clean.
    • src/: Contains LaTeX source files for generating specification diagram images.
    • ext/: Contains supplemental documentation including:
      • changes.md: Specification changes.
      • errata.md: Specification errata.
      • glossary.md: Specification glossary.
      • resources.md: External community and web resources.
      • team.md: Information about the YAML language development team.
  5. What is YAML and its core design goals?

    main

    YAML (YAML Ain't Markup Language) is a human-friendly, Unicode-based data serialization language designed to represent native data structures of dynamic programming languages. It is used for configuration, messaging, object persistence, and data auditing.

    Its primary design goals, in decreasing priority, are:

    1. Human readability.
    2. Portability between programming languages.
    3. Matching native data structures of dynamic languages.
    4. Providing a consistent model for generic tools.
    5. Supporting one-pass processing.
    6. Expressiveness and extensibility.
    7. Ease of implementation and use.
  6. Identify YAML Node Kinds

    main

    Every node in a YAML representation belongs to one of three kinds:

    • Scalar: An opaque datum represented as zero or more Unicode characters.
    • Sequence: An ordered series of zero or more nodes. Sequences can contain duplicate nodes or even contain themselves (cycles).
    • Mapping: An unordered set of key: value node pairs.
      • Constraint: Each key in a mapping must be unique.
      • Flexibility: Keys can be any arbitrary node, and the same node can be used as a value for multiple keys.

    Note: For theoretical and practical purposes, sequences can be viewed as mappings with integer keys starting at zero.

  7. Understand YAML Document structures

    main

    A YAML stream can contain multiple independent documents. There are three primary types of documents:

    1. Bare Documents: Contain only content without any directives or markers. The first non-comment line must not start with a % character. Nodes are indented as if they have a parent at -1 spaces.
    2. Explicit Documents: Begin with a directives end marker (---) but contain no directives. These can be completely empty.
    3. Directives Documents: Begin with directives (e.g., %YAML 1.2) followed by a directives end marker (---).

    Documents can be separated by markers to ensure unambiguous parsing, especially when content lines might otherwise look like directives.

    # Bare Document
    Key: Value
    
    # Explicit Document
    ---
    { matches %: 20 }
    ...
    
    # Directives Document
    %YAML 1.2
    ---
    !!str "Document"
    ...
  8. Use Block Scalar Nodes (Literal and Folded)

    main

    Block scalars allow multi-line text blocks. They use specific indicators:

    • | (Literal style): Preserves newlines.
    • > (Folded style): Replaces newlines with spaces.

    Node properties (like tags) can span multiple lines and must be indented by at least one more space than the parent block collection.

    literal: |
      value
    folded: >
      value
  9. Understand the Core Schema in YAML

    main
    The Core schema is an extension of the JSON schema designed for more human-readable presentation. It is the recommended default schema for YAML processors. Unlike the JSON schema, if a plain scalar in the Core schema does not match any specific type pattern, it is resolved to a string (tag:yaml.org,2002:str) rather than resulting in an error.
  10. Use plain (unquoted) scalar style for maximum readability

    main

    The plain style uses no indicators and no escaping. While highly readable, it is the most context-sensitive and restricted style.

    Constraints and Rules:

    • Whitespace: A plain scalar must not be empty and must not contain leading or trailing whitespace.
    • Forbidden Combinations:
      • Must never contain the : (colon followed by space) and # (hash) character combinations (to avoid ambiguity with mappings and comments).
      • Inside flow collections or when used as implicit keys, they must not contain [, ], {, }, or ,.
    • Starting Characters: Plain scalars must not begin with most indicators. However, :, ?, and - may be used as the first character if they are followed by a non-space "safe" character.
    • Line Breaks: Long lines can only be broken where a space character is surrounded by non-space characters.
    • Implicit Keys: Plain scalars must be restricted to a single line when used as an implicit key.
    # Outside flow collection:
    - ::vector
    - ": - ()"
    - Up, up, and away!
    - -123
    - http://example.com/foo#bar
    
    # Inside flow collection:
    - [ ::vector, 
      ": - ()", 
      "Up, up and away!", 
      -123, 
      http://example.com/foo#bar ]
  11. Use separation lines and comments between tokens

    main

    YAML allows tokens to be separated by multi-line (possibly empty) comments. This is useful for organizing large structures.

    Constraints

    • Implicit Keys: These are restricted to a single line and cannot be separated by multi-line comments.
    • Indentation: Even if separation comments are not restricted by indentation, any structures following these comments must be properly indented to maintain valid YAML syntax.
    {
      first: Sammy,
      last: Sosa
    }:
    # Statistics:
      hr: 65
      avg: 0.278