Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow quotes in multi-line strings #419

Merged
merged 2 commits into from
Dec 8, 2024

Conversation

tjol
Copy link
Contributor

@tjol tjol commented Dec 7, 2024

Fixes #415.

This changes the grammar and prose to allow (multi-line) strings to include unescaped quotes as long as they don't contain their own closing delimiter.

I haven't touched the grammar for raw strings since it already allows raw strings to contain " and # in any order and number. The restriction that the body of a raw string can't contain the corresponding closing delimiter was never explicit in the grammar (afaict), and I don't think it's worth making explicit there when it's already explicit in the prose.

Also: added tests, tweaked the wording for raw string.

Copy link
Member

@zkat zkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I think there’s a minor thing to look at but I also don’t mind merging as is.

SPEC.md Outdated
@@ -653,7 +654,7 @@ You can show examples of """
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stuff between backticks is how you would represent the contents as a single line string. I think you’ll want to escape the quotes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -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*) '"""'
single-line-string-body := (string-character - newline)*
multi-line-string-body := string-character*
multi-line-string-body := (('"' | '""')? string-character)*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[chefkiss] I love how clean a change this is

@zkat
Copy link
Member

zkat commented Dec 8, 2024

Thanks a bunch for taking the time to do this!

@zkat zkat merged commit 831ecc1 into kdl-org:main Dec 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] Should triple-quoted strings be allowed to contain unescaped quotes?
2 participants