1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-09 13:23:51 +02:00

fix: inconsistent YAML multiline parsing (#475)

When the YAML block scalar (multiline string) syntax is used with only one line of text, the single line is not matched by the current regexp. It currently only works with at least two lines.

This fixes the regexp by adding a special case for a single line after the first indentation in the block.
This commit is contained in:
Guillaume Galy 2023-01-11 11:14:42 +01:00 committed by Alec Thomas
parent d330b760dc
commit 5ca7345671
3 changed files with 19 additions and 3 deletions

View File

@ -49,7 +49,7 @@
</rule>
</state>
<state name="value">
<rule pattern="([&gt;|](?:[+-])?)(\n(^ {1,})(?:.*\n*(?:^\3 *).*)*)">
<rule pattern="([&gt;|](?:[+-])?)(\n(^ {1,})(?:(?:.*\n*(?:^\3 *).*)+|.*))">
<bygroups>
<token type="Punctuation"/>
<token type="LiteralStringDoc"/>

View File

@ -105,7 +105,9 @@ e: |+
f: >+
multiline folded keep one space
line 2
g: test
g: |
multiline literal with only one line
h: test
block_scalars_with_indent:
a: |
@ -129,7 +131,9 @@ block_scalars_with_indent:
f: >+
multiline folded keep
line 2
g: test
g: |
multiline literal with only one line
h: test
####################
# COLLECTION TYPES #

View File

@ -251,6 +251,12 @@
{"type":"NameTag","value":"g"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"LiteralStringDoc","value":"\n multiline literal with only one line"},
{"type":"TextWhitespace","value":" \n"},
{"type":"NameTag","value":"h"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Literal","value":"test"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"NameTag","value":"block_scalars_with_indent"},
@ -297,6 +303,12 @@
{"type":"NameTag","value":"g"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"LiteralStringDoc","value":"\n multiline literal with only one line"},
{"type":"TextWhitespace","value":" \n "},
{"type":"NameTag","value":"h"},
{"type":"Punctuation","value":":"},
{"type":"TextWhitespace","value":" "},
{"type":"Literal","value":"test"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Comment","value":"####################"},