Skip to content

bug: dedented flow closing parsing error #43

@DarkaMaul

Description

@DarkaMaul

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

4463985

Describe the bug

When a flow sequence closing ] (or flow mapping closing }) appears on a new line at a column less than the enclosing block mapping key, the scanner emits a premature BL (dedent) token before the ]/} can be recognized. This causes an ERROR node in the parse tree.

This is valid YAML per the spec — flow collection indicators can appear at any indentation level within a flow context.

Found in the wild parsing ArduPilot/ardupilot's test_scripts.yml, where a matrix config uses this pattern.

Disclaimer: The minimization/reproduction was performed by an LLM, but I've manually reviewed and tested the output before opening this issue.

Steps To Reproduce/Bad Parse Tree

outer:
  inner: [
    a,
    b,
 ]

> tree-sitter parse /tmp/output.yml

(stream [0, 0] - [5, 0]
  (document [0, 0] - [5, 0]
    (block_node [0, 0] - [5, 0]
      (block_mapping [0, 0] - [5, 0]
        (block_mapping_pair [0, 0] - [5, 0]
          key: (flow_node [0, 0] - [0, 5]
            (plain_scalar [0, 0] - [0, 5]
              (string_scalar [0, 0] - [0, 5])))
          value: (block_node [1, 2] - [5, 0]
            (block_mapping [1, 2] - [5, 0]
              (block_mapping_pair [1, 2] - [1, 8]
                key: (flow_node [1, 2] - [1, 7]
                  (plain_scalar [1, 2] - [1, 7]
                    (string_scalar [1, 2] - [1, 7]))))
              (ERROR [1, 9] - [4, 2]
                (flow_node [2, 4] - [2, 5]
                  (plain_scalar [2, 4] - [2, 5]
                    (string_scalar [2, 4] - [2, 5])))
                (flow_node [3, 4] - [3, 5]
                  (plain_scalar [3, 4] - [3, 5]
                    (string_scalar [3, 4] - [3, 5])))))))))))
/tmp/output.yml Parse:    0.06 ms          574 bytes/ms (ERROR [1, 9] - [4, 2])

Expected Behavior/Parse Tree

I believe the correct tree should be:

(stream [0, 0] - [5, 0]
  (document [0, 0] - [5, 0]
    (block_node [0, 0] - [5, 0]
      (block_mapping [0, 0] - [5, 0]
        (block_mapping_pair [0, 0] - [5, 0]
          key: (flow_node [0, 0] - [0, 5]
            (plain_scalar [0, 0] - [0, 5]
              (string_scalar [0, 0] - [0, 5])))
          value: (block_node [1, 2] - [5, 0]
            (block_mapping [1, 2] - [5, 0]
              (block_mapping_pair [1, 2] - [4, 2]
                key: (flow_node [1, 2] - [1, 7]
                  (plain_scalar [1, 2] - [1, 7]
                    (string_scalar [1, 2] - [1, 7])))
                value: (flow_node [1, 9] - [4, 2]
                  (flow_mapping [1, 9] - [4, 2]
                    (flow_pair [2, 4] - [2, 8]
                      key: (flow_node [2, 4] - [2, 5]
                        (plain_scalar [2, 4] - [2, 5]
                          (string_scalar [2, 4] - [2, 5])))
                      value: (flow_node [2, 7] - [2, 8]
                        (plain_scalar [2, 7] - [2, 8]
                          (integer_scalar [2, 7] - [2, 8]))))
                    (flow_pair [3, 4] - [3, 8]
                      key: (flow_node [3, 4] - [3, 5]
                        (plain_scalar [3, 4] - [3, 5]
                          (string_scalar [3, 4] - [3, 5])))
                      value: (flow_node [3, 7] - [3, 8]
                        (plain_scalar [3, 7] - [3, 8]

Repro

The same bug affect both mapping and sequence:

outer:
  inner: [
    a,
    b,
 ]
outer:
  inner: {
    a: 1,
    b: 2,
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions