The YAML spec states that the final line break is part of a block scalar unless strip - is used as a chomping mode. The parser however treats the final line break as whitespace and assigns it to a different node.
Here is an example to reproduce the issue:
a: |
hello
world
b: |
hello
world
The parser generates the following output:
ROOT@0..42
DOCUMENT@0..41
BLOCK@0..41
BLOCK_MAP@0..41
BLOCK_MAP_ENTRY@0..20
BLOCK_MAP_KEY@0..1
FLOW@0..1
PLAIN_SCALAR@0..1 "a"
COLON@1..2 ":"
WHITESPACE@2..3 " "
BLOCK_MAP_VALUE@3..20
BLOCK@3..20
BLOCK_SCALAR@3..20
BAR@3..4 "|"
BLOCK_SCALAR_TEXT@4..20 "\n hello\n world"
WHITESPACE@20..21 "\n" <-----
BLOCK_MAP_ENTRY@21..41
BLOCK_MAP_KEY@21..22
FLOW@21..22
PLAIN_SCALAR@21..22 "b"
COLON@22..23 ":"
WHITESPACE@23..24 " "
BLOCK_MAP_VALUE@24..41
BLOCK@24..41
BLOCK_SCALAR@24..41
BAR@24..25 "|"
BLOCK_SCALAR_TEXT@25..41 "\n hello\n world"
WHITESPACE@41..42 "\n" <-----
The incorrectly parsed line breaks are marked with <-----. They should be part of the BLOCK_SCALAR_TEXT instead.
I tried to fix it myself, but it turned out to be quite challenging. Parsing the line break as part of BLOCK_SCALAR_TEXT breaks the parent rules which expect the line break as a separator, e.g. the block_map parsing function.
The YAML spec states that the final line break is part of a block scalar unless strip
-is used as a chomping mode. The parser however treats the final line break as whitespace and assigns it to a different node.Here is an example to reproduce the issue:
The parser generates the following output:
The incorrectly parsed line breaks are marked with
<-----. They should be part of theBLOCK_SCALAR_TEXTinstead.I tried to fix it myself, but it turned out to be quite challenging. Parsing the line break as part of
BLOCK_SCALAR_TEXTbreaks the parent rules which expect the line break as a separator, e.g. theblock_mapparsing function.