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

multiline character literal constants #306

Open
shahmoradi opened this issue Jul 6, 2023 · 3 comments
Open

multiline character literal constants #306

shahmoradi opened this issue Jul 6, 2023 · 3 comments

Comments

@shahmoradi
Copy link

shahmoradi commented Jul 6, 2023

This feature request has resurfaced frequently, but I cannot readily find any related proposals/issues. So, I am requesting again to add specific syntax for multiline character literal constants in the language, much similar to the functionality of Python docstrings.
Currently, writing a multiline text is a cumbersome process. For example,

character(:), allocatable :: str
str = &
"This "//new_line("a")//  &
"is "//new_line("a")//  &
"a "//new_line("a")//  &
"multiline "//new_line("a")//  &
"string."

could be written much more cleanly with a new syntax like,

str = `
This 
is 
a 
multiline 
string.`

where the backtick serves as a multiline delimiter that includes the new line characters in the literal constant.
This new syntax (or similar) would also allow hassle-free repeated usage of single and double quotation marks ' and " in a string.
My primary use case for this facility is the seamless incorporation and migration of hard-coded text and paragraphs in various source codes in multiple different programming languages. Currently, this is practically impossible without some preprocessing of the text.
Given the extensive discussions of this feature among users, I hope this request makes it into future committee meetings for discussion and inclusion.

@certik
Copy link
Member

certik commented Jul 7, 2023

Indeed, here is another such example from one of my recent codes: https://github.com/certik/fastGPT/blob/4e70c6a0e9f60a1b3c94f18b32c34a6012de1e7b/driver.f90#L225.

I wonder if we could use """ as in Python. It would not be strictly backwards compatible though.

@klausler
Copy link

klausler commented Jul 7, 2023

I wonder if we could use """ as in Python. It would not be strictly backwards compatible though.

It wouldn't be backwards compatible at all -- it's the start of an unterminated character literal constant.

''" ... "'' and ""' ... '"" would work, and their terminators are unlikely to appear in the text. But I suspect that you need something that would allow anything to appear, no matter how unlikely.

@wyphan
Copy link

wyphan commented Jul 7, 2023

I'd suggest triple backticks ``` like the one used in Markdown for block code.

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

No branches or pull requests

4 participants