gren-lang / compiler

Compiler for the Gren programming language
https://gren-lang.org
Other
342 stars 21 forks source link

Improve multi-line string syntax #213

Open robinheghan opened 1 year ago

robinheghan commented 1 year ago
  1. Only the line containing the closing """ should determine the indentation level to be removed.
  2. If the first character is anything but \n it should be a syntax error (The empty string, """""", is not valid)
  3. The opening and closing """ should have the same indentation level.
robinheghan commented 1 year ago

Worked on by @Gauteab

lue-bird commented 6 months ago

The syntax would still be unambiguous if we use only a single " instead of three, so

text =
    "
    First
    Second
    "

instead of

text =
    """
    First
    Second
    """

Would this be more confusing than nice? I feel like it would be easier to learn/remember. Changing from single-line to multi-line string would also be more seamless.

blaix commented 2 months ago

Discovered this current behavior when trying to test terminal output in gren-tui:

> """
|    indented
| not indented
| """
|   
"indented\nnot indented" : String

I guess that would be fixed by this?

Only the line containing the closing """ should determine the indentation level to be removed.

Until this is done should this be labelled as a bug? Kind of makes multi-line strings unusable in places with Very Significant whitespace.

robinheghan commented 2 months ago

Yes, this is a bug.