Odin
Odin copied to clipboard
[request] multi-line string where indentation get's eaten
One thing I dislike about multi-line comments is that they can screw with the look of the file due to the indentation. Here a tiny example (I think it's worse when the multi-line strings covers a lot more lines and contains code (like shader code)):
I would much more prefer something like this:
But that results in:
The problem is knowing how much white space to eat. My idea is to have something like this:
The idea of how it works:
#eat_prefixed_whitespacehas to be present- the second line has to contain a
|character - the position of this character is x tabs in, where x is how many tabs it should eat minus one (cause the second line might contain content as well so we can't put it there
- on the lines after the second line with the
|, if any other character is found then a tab in this prefixed area, then a error should be thrown
- I typed some ideas for when people use spaces instead of tabs as well, but people that use spaces should be shot...
bonus

Easiest solution is to use Python like triple quote strings.
yeah that would be easier. Still there needs to be something to indicate how much to eat.
I've enjoyed using heredocs in languages like Crystal:
sql = <<-SQL
SELECT
a,
b,
c
FROM bar
SQL
# ^ whitespace trimmed from this column
# yields "SELECT\n a,\n b,\n c\nFROM bar\n"
The way it works is leading whitespace is aligned with whatever column the terminating marker is at.
For example, this yields exactly the same string:
sql = <<-SQL
SELECT
a,
b,
c
FROM bar
SQL
So it would be nice if it worked the same way, where leading whitespace is trimmed up to the column of the closing fence:
sql := """
SELECT
a,
b,
c
FROM bar
"""
assert(sql == "SELECT\n a,\n b,\n c\nFROM bar\n")
While I don't expect Odin to adopt heredocs, I will mention another nice feature specifically with heredoc syntax, is they can be recognized by frontends like GitHub and use the heredoc identifier (SQL) to pick different syntax highlighting for that block of text.
IFF I am going to do this as a feature in the language, it will be Python-like triple quotes as I suggested.
Please don't suggest any other lexical/syntax bits please.
@gingerBill To be clear, I was not suggesting Odin implement heredocs like Crystal precisely as illustrated.
I was suggesting that I would really like leading space to be trimmed in the same manner, using the closing fence as a guide - so that the last example that I wrote passes the assert.
(Or some similar behavior)