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:
parent
d330b760dc
commit
5ca7345671
@ -49,7 +49,7 @@
|
||||
</rule>
|
||||
</state>
|
||||
<state name="value">
|
||||
<rule pattern="([>|](?:[+-])?)(\n(^ {1,})(?:.*\n*(?:^\3 *).*)*)">
|
||||
<rule pattern="([>|](?:[+-])?)(\n(^ {1,})(?:(?:.*\n*(?:^\3 *).*)+|.*))">
|
||||
<bygroups>
|
||||
<token type="Punctuation"/>
|
||||
<token type="LiteralStringDoc"/>
|
||||
|
8
lexers/testdata/yaml.actual
vendored
8
lexers/testdata/yaml.actual
vendored
@ -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 #
|
||||
|
12
lexers/testdata/yaml.expected
vendored
12
lexers/testdata/yaml.expected
vendored
@ -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":"####################"},
|
||||
|
Loading…
x
Reference in New Issue
Block a user