-
Notifications
You must be signed in to change notification settings - Fork 856
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
One multiline string to rule them all. #225
Conversation
Adds multiline strings to TOML with a way to escape whitespace for writing long single line strings.
Using Can we do some hybrid like That would allow flexibility but maintain readability/familiarity. |
I love Lua's method. Its elegant, simple and robust. If we're going to with smart delimiters, then I would really love to just use Lua's approach. If you had to write Python, you could always use With |
This proposition does not cover #163, which was about splitting long strings without line breaks into smaller ones to be concatenated. |
@pygy Yes it does. See the second example. |
I feel really weird about multiline strings. It just doesn't sit right with my idea of what TOML ought to be. Why do we require >75 characters in a value? Is TOML meant to hold content? I'd like to hear more about the motivations for this, and get @mojombo's take on this proposal. Overall, I'm 👎 on multiline strings, because I don't think TOML is for content. 😕 |
I wouldn't be heartbroken if this didn't make it in, but I understood it to be a popularly requested feature. |
You mean this one? s = [=[ hello [[something]] world ]=] That's not the use case I have in mind. I mean the ability to split a long string without line ends like s = "qwertyuiopoiuytewqwertyuiopoiuytewqwertyuioiuytrertyuioiyrewertyuiweruoureruiodfjkjhfdfghjkkhfdfhjkkhfdfgjkgfdfghjkkjhgfsyrertyuihffghjkkhdfgh" into s = "qwertyuiopoiuytewqwertyuiopoiuytewqwertyuioiuytrertyuioiyr" .. -- or `+`, or even
"ewertyuiweruoureruiodfjkjhfdfghjkkhfdfhjkkhfdfgjkgfdfghjkk" .. -- nothing at all like C
"jhgfsyrertyuihffghjkkhdfgh" Lua long strings preserve the line ends as is. |
|
Sorry, it's time for me to go to sleep I hadn't seen the diff, and though that you were suggesting Lua-style strings (which I like, personally), rather than the current proposal. |
@pygy I like Lua-style strings too. I used |
I agree with you about the consensus, Lua is still a bit obscure, and using its syntax would likely cause a riot :-) |
I like But why do you have to include i.e. why can't you do this:
? |
@jprichardson I believe the intention is to have the ability to both preserve and eliminate whitespace in multiline strings. Sans |
@jprichardson The string you gave: key2 = """
The quick brown
fox jumps over
the lazy dog.""" Would be valid and not equivalent to: key2 = """
The quick brown \
fox jumps over \
the lazy dog.""" The latter string is byte-for-byte equivalent to The idea is that |
Python allows both Python also allows backslash-escaping triple quotes in triple-quoted strings to handle the unlikely case that both |
@ChristianSi I think we can just fallback on escaping quotes. Regular TOML strings already support it. |
@BurntSushi That's true, I agree. |
@mojombo What do you think? |
I propose using ''' instead, and as a raw string. No escaping, no Furthermore, I would support trimming the first and last newline in a multi-line ''' string. These would then be equivalent:
|
@johanfange No. We need two versions. One of them is a regular string, I'd rather not trim the last new line. Why do you want to? The common case is to end your string with a new line, which looks weird and counter-intuitive if we trim the last one. |
Agreed. |
Having read through your arguments in the old threads on this I now agree that last line trimming isn't desirable. However, I'm unconvinced of the need for multi-line strings with escaping though. What is the suggested use-case for this? It's not very pretty and doesn't seem terribly useful at first glance.
|
Writing long strings without line breaks (and obviously, without your editor auto-wrapping the line ewyuck). |
@BurntSushi Okay, just seemed a bit overkill to me, especially considering parsers have to support it too. I think that kind of thing would be more appropriate at the application-level, e.g. by writing in Markdown, HTML or something. Then again, I usually don't write long one-line paragraphs in my config files, so who am I to judge. |
Closed in favor of #228. |
Adds multiline strings to TOML with a way to escape whitespace for
writing long single line strings.
I like this approach because it combines multiline strings and long single line strings into one form. All of these ideas were mentioned in one form or another in #92, #163 and #164.
I chose
"""
because that seems to be what people converged on. The obvious down-side is that"""
cannot be typed into a multiline string. This isn't a very high price to pay, but if we didn't want to, then I'd suggest Lua's multiline string syntax:Basically, the quoting mechanism builds in the ability to change the delimiters.