Repository navigation
Multiline string can not end with double quote #3283
Description
Activity
This is expected.
""""is a valid token. And even if it wasn't, the tokeniser would be greedy and consume the""".Should I submit a PR to the documentation then?
Is it expected that escape sequences don't work in triple-quotes blocks?
I've had issues with this before. There should be some escape sequence even if it's different.
@paf31 thinks that we need to fix the docs. I'm ready to try and fix the tokenizer so that the quotes are indeed allowed everywhere in the triple quoted string. Or allow escapes, which is even better.
My reasoning is just that Purescript is a very elegant language. And having "you can have a single quote everywhere in the triple quoted string, oh, just not as the last character" in the documentation is not elegant.
Fixing the lexer in the way you describe isn't going to be simple.
Reacted by Michael FicarraWhat about implementing escapes? It's cool to have them anyway.
How would that work? I see
"""existing as "dump unescaped things here" heredoc kinda thing more than it being for multiline specifically - it not already having escape sequences is a feature 😄@kika What languages with multi-line strings work like you want? While Python lets you write:
z = """i can end with double quotes."""""
the evaluated value is:
λ ~/ python -i foo.py >>> z 'i can end with double quotes.'As far as I can tell, this is because Python parses that as
"""foo""" ""and then apparently Python does string concatenation for adjacent string literals?@parsonsmatt I can't think of one that allows 4 quotes in a row, but at least python and coffeescript allow escapes, so it's a non-issue for them.
z = """i can end with double quotes.\""""
works in both of them.@garyb Allowing escapes is not mutually exclusive with 'dump unescaped things'. You can dump unescaped things while allowing escapes. But the unescaped backslash will fall victim of such change.
FWIW, Idris supports this https://www.idris-lang.org/idris-1-2-0-released/
Verbatim strings now support trailing quote characters. All quote characters until the final three are considered part of the string. Now a string such as """"hello"""" will parse, and is equivalent to "\"hello\"".
This is fixed in master with the new lexer.
in
psci: