-
Notifications
You must be signed in to change notification settings - Fork 23
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
Unquoted indentation-based string literals #248
Comments
Aside from the indentation, what does this improve over triple quoted strings? |
github highlighter breaks all the time with current syntax and this for sure wont make it better. also, i have no clue how would i add syntax highlighting with regex for this. |
I don't think it is necessary to explicitly add highlighting code this specific new type of code literals. On the contrary - I say there is absolutely no need to highlight this as string literals, or as any kind of specific construct. I repeat what I already said in RFC - a lot of languages share keywords and syntax. Here is an example how vscode currently handles it right now. I think it looks pretty good. The only thing that needs to be highlighted separately is a 1 Better syntax highlighting in cases where it is necessary to have foreign code literalsScreenshot taken from VScode with zero additional configurations. 2 No indentation or
|
There's also another import strutils
echo """
try {
auto tmp = (itr != itrEnd);
} catch (const boost::wave::preprocess_exception& ex) {
cerr << "ERROR in " << ex.file_name() << " : " << ex.line_no()
""".unindent(2) # <----------- notice `2` here ------------------ produces:
|
Which requires you to specify indentation in every single string literal that you write in the code. It is perfectly doable and quite easy, but now string literals look like |
and how would that look? herestring:
#[
othercode() |
Remark: the only language that I know of which treats Yes, of course it is possible to find innumerable edge cases to break every syntax highlighter possible, but the only two things that break everything down the road are not closed string and |
Since majority voted against and there is no real feature benefit, but only new syntax sugar I think it is appropriate to close the RFC. |
Thank you very much for your sportsmanship! |
Proposal
Add unquoted indentation-based string literals with following syntax:
lexer.nim
, contained in ~60 lines of code.Note: I'm of course open to suggestions and comments about implementation - this is by no means final impllementation, I just added it to have something to show (since this RFC is purely syntax sugar).
Adresses some points from different RFCs such as asm/emit syntax: explicit capture of symbols; heredoc string litterals; syntax highlight hints #210, Multi-line string literals (blocks of lines) #161
Multi-line string literals (blocks of lines) #161 - fully covers this RFC albeit with different syntax. Instead of introducing special handling for relatively cryptic char combination
":
string is introduced asherestring:
- more verbose but easier to recognize.asm/emit syntax: explicit capture of symbols; heredoc string litterals; syntax highlight hints #210 - allows to write unquoted code for
{.emit.}
statement. It might not look as good as solution that specifically addresses particular backend, but syntax highlighting is will work.Comment about possible implementation - instead of
'''
identifierherestring
is used. Github syntax highligher works relatively fine on the new syntax. Given that sole reason for unquoted herestring is to have some basic syntax highlighting/editor support (even though nim is different from say C, it shares some keywords so highlighting works (C++ code literal in example)) it is still better than having no highlighting at all.Implementation
When identifier
herestring
is found during lexing replace it with triple string literal token. All text with current line indentation + 2 will be cut out as a string.Example of use
I implemented some tests for initial implementation
String format
Just as string literal
Nim compiler test suite uses triple quoted string literals to
configure test suite. This:
can be turned into this
which is not too much of a difference from feature standpoint, but a lot of people will find
herestring
version easier to work with + it looks better (this is of course subjective).Emit statement
The text was updated successfully, but these errors were encountered: