Allow quotes in multi-line strings (#419)

Fixes: https://github.com/kdl-org/kdl/issues/415
This commit is contained in:
Thomas Jollans 2024-12-08 10:07:31 +01:00 committed by GitHub
parent 29ae90e9f5
commit 831ecc1d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 7 deletions

15
SPEC.md
View File

@ -430,7 +430,9 @@ before the closing `"""`.
All in-between lines that contain non-newline characters All in-between lines that contain non-newline characters
_MUST_ start with _at least_ the exact same whitespace as the final line _MUST_ start with _at least_ the exact same whitespace as the final line
(precisely matching codepoints, not merely counting characters or "size"); (precisely matching codepoints, not merely counting characters or "size");
they may contain additional whitesapce following this prefix. they may contain additional whitesapce following this prefix. The lines in
between may contain unescaped `"` (but no unescaped `"""` as this would close
the string).
The value of the Multi-Line String omits the first and last Newline, the The value of the Multi-Line String omits the first and last Newline, the
Whitespace of the last line, and the matching Whitespace prefix on all Whitespace of the last line, and the matching Whitespace prefix on all
@ -611,10 +613,9 @@ The Raw String variants are indicated by preceding the strings's opening quotes
with one or more `#` characters. with one or more `#` characters.
The string is then closed by its normal closing quotes, The string is then closed by its normal closing quotes,
followed by a _matching_ number of `#` characters. followed by a _matching_ number of `#` characters.
This means that the string may contain a lone `"` or `"""`, This means that the string may contain any combination of `"` and `#` characters
or `"#`/etc with a _different_ number of `#` characters other than its closing delimiter (e.g., if a raw string starts with `##"`, it can
than what is used to open the string; contain `"` or `"#`, but not `"##` or `"###`).
only an exact match actually closes the string.
Like other Strings, Raw Strings _MUST NOT_ include any of the [disallowed Like other Strings, Raw Strings _MUST NOT_ include any of the [disallowed
literal code-points](#disallowed-literal-code-points) as code points in their literal code-points](#disallowed-literal-code-points) as code points in their
@ -653,7 +654,7 @@ You can show examples of """
without worrying about escapes. without worrying about escapes.
``` ```
or equivalently, `#"You can show examples of """\n multi-line strings\n """\nwithout worrying about escapes."#` as a Quoted String. or equivalently, `"You can show examples of \"\"\"\n multi-line strings\n \"\"\"\nwithout worrying about escapes."` as a Quoted String.
### Number ### Number
@ -856,7 +857,7 @@ disallowed-keyword-identifiers := 'true' - 'false' - 'null' - 'inf' - '-inf' - '
quoted-string := '"' single-line-string-body '"' | '"""' newline multi-line-string-body newline unicode-space*) '"""' quoted-string := '"' single-line-string-body '"' | '"""' newline multi-line-string-body newline unicode-space*) '"""'
single-line-string-body := (string-character - newline)* single-line-string-body := (string-character - newline)*
multi-line-string-body := string-character* multi-line-string-body := (('"' | '""')? string-character)*
string-character := '\' escape | [^\\"] - disallowed-literal-code-points string-character := '\' escape | [^\\"] - disallowed-literal-code-points
escape := ["\\bfnrts] | 'u{' hex-digit{1, 6} '}' | (unicode-space | newline)+ escape := ["\\bfnrts] | 'u{' hex-digit{1, 6} '}' | (unicode-space | newline)+
hex-digit := [0-9a-fA-F] hex-digit := [0-9a-fA-F]

View File

@ -0,0 +1 @@
node "\"\"\"triple-quote\"\"\"\n##\"too few quotes\"##\n#\"\"\"too few #\"\"\"#"

View File

@ -0,0 +1 @@
node "this string contains \"quotes\", twice\"\""

View File

@ -0,0 +1,5 @@
node ##"""
"""triple-quote"""
##"too few quotes"##
#"""too few #"""#
"""##

View File

@ -0,0 +1,3 @@
node """
this string contains "quotes", twice""
"""