Upgrade to Pro — share decks privately, control downloads, hide ads and more …

YAML - An unfortunate series of indents

YAML - An unfortunate series of indents

Get a full briefing on the history of YAML and hot tips for the best tools for linting and editing the markup language in your favorite editors.

Keith Resar

April 18, 2019
Tweet

More Decks by Keith Resar

Other Decks in Technology

Transcript

  1. @KeithResar CALENZEN YAML --- name: Zoom US Level 1 (2018-09-05)

    level: 1 priority: 102 driver: RegexV1 key_type: ... detect_regex: … output: ...
  2. @KeithResar RFC 822 From: [email protected] To: [email protected], ∙ ∙ ∙

    "[email protected]" Unstructured Text Key/Value pairs Multi-line folding CRLF followed by LWSP character Delimiting and Quoting Optional, not part of string, c-style escape sequences
  3. @KeithResar OTHER PRIOR ART • Indentation-based scoping from Python •

    End of line normalization from HTML • Collections & scalar data types from Perl, Python, Ruby • Incremental interfaces and streaming one-pass interfaces supports large documents
  4. @KeithResar COMPARING YAML WITH JSON • Simplicity & universality •

    Lowest common denominator • Trivial to generate and parse JSON • Human readability • Arbitrary native data structures • Complex processing across environments YAML
  5. @KeithResar YAML ⊇ JSON JSON's RFC4627 requires that mappings keys

    merely “SHOULD” be unique, while YAML insists they “MUST” be. Technically, YAML therefore complies with the JSON spec, choosing to treat duplicates as an error. In practice, since JSON is silent on the semantics of such duplicates, the only portable JSON files are those with unique keys, which are therefore valid YAML files.
  6. @KeithResar QUOTING --- plain: look ma no quotes, but the

    most limited single_quotes: - 'keith''s single quotes' - 'bare \ is ok' double_quotes: - "only flow that can express arbitrary strings" - "\\ escape sequences, but must quote \" and \\"
  7. @KeithResar BLOCKS --- # literal style - a: | multi-line

    ∙ ∙ ∙ text block # folded style - b: > multi-line ∙ ∙ ∙ text block Becomes: multi-line Text block Becomes: Multi-line text block
  8. @KeithResar BLOCK CHOMPING --- # clip (default) - includes final

    line break - a: | text # strip - excludes final line break & trailing empty lines - a: |- text # keep - includes all trailing line breaks - a: |+ text
  9. @KeithResar DIRECTIVES --- <document content> --- <document content> ... Start

    of Stream Separate directives from content End of Document Used for streaming comm channels
  10. @KeithResar TAGS IN _FAILSAFE_ SCHEMA --- - !!str just a

    string - !!str true - !!map a: 1 b: 2 - !!seq - a - b
  11. @KeithResar TAGS IN _CUSTOM_ SCHEMA %TAG !foo! tag:example.com,2002: --- invoice1:

    !foo!invoice ... invoice2: !<tag:example.com,2002:invoice> ...
  12. @KeithResar LINTING • YMMV re: quality - check web and

    python • yamllint • ansible-lint
  13. @KeithResar GO FARTHER WITH THESE _RESOURCES_ YAML Ain’t Markup Language

    (YAML™) Version 1.2 Spec https://yaml.org/spec/1.2/spec.html Ansible Lint Documentation https://docs.ansible.com/ansible-lint/