Skip to content

Bug: Indentation indicator after chomping indicator is not recognized, appearing as illegal #41

@geekley

Description

@geekley

The YAML spec says that in block scalars, both indicators can appear in any order.
This is the case since YAML 1.0: https://yaml.org/spec/1.0/index.html#id2566934

# Modifiers may be combined in any order.
indented and chomped: |2-
    This has no newline.

also written as: |-2
    This has no newline.

both are equal to: "  This has no newline."

Also on latest YAML 1.2.2: https://yaml.org/spec/1.2.2/#rule-c-b-block-header

[162] c-b-block-header(t) ::=
  (
      (
        c-indentation-indicator
        c-chomping-indicator(t)
      )
    | (
        c-chomping-indicator(t)
        c-indentation-indicator
      )
  )
  s-b-comment

But the grammar only allows the number before the chomping indicator:
https://github.com/textmate/yaml.tmbundle/blob/master/Syntaxes/YAML.tmLanguage#L217
(?:(\|)|(>))([1-9])?([-+])?(.*\n?)

Example:

should-work1: |+2
  string
should-work2: >+2
  string
should-work3: |-2
  string
should-work4: >-2
  string
works1: |2+
  string
works2: >2+
  string
works3: |2-
  string
works4: >2-
  string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions