Skip to content

Multiline string can not end with double quote #3283

Description

@kika

in psci:

> :paste
… x = """
… "some text"
… """
…
> x
"\n\"some text\"\n"

> :paste
… y = """
… "some text""""
…
(line 2, column 15):
unexpected "\n"
expecting string character or end of string
> :paste
… y = """
… "some text" """
…
> y
"\n\"some text\" "

Activity

  1. michaelficarra commented on Mar 21, 2018

    @michaelficarra
    Contributor

    This is expected. """" is a valid token. And even if it wasn't, the tokeniser would be greedy and consume the """.

  2. kika commented on Mar 21, 2018

    @kika
    ContributorAuthor

    Should I submit a PR to the documentation then?

  3. natefaubion commented on Mar 21, 2018

    @natefaubion
    Contributor

    Is it expected that escape sequences don't work in triple-quotes blocks?

  4. maddie927 commented on Mar 21, 2018

    @maddie927

    I've had issues with this before. There should be some escape sequence even if it's different.

  5. kika commented on Mar 21, 2018

    @kika
    ContributorAuthor

    @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.

  6. paf31 commented on Mar 21, 2018

    @paf31
    Contributor

    Fixing the lexer in the way you describe isn't going to be simple.

  7. kika commented on Mar 22, 2018

    @kika
    ContributorAuthor

    What about implementing escapes? It's cool to have them anyway.

  8. garyb commented on Mar 22, 2018

    @garyb
    Member

    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 😄

  9. parsonsmatt commented on Mar 25, 2018

    @parsonsmatt
    Contributor

    @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?

  10. kika commented on Mar 25, 2018

    @kika
    ContributorAuthor

    @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.

  11. kika commented on Mar 25, 2018

    @kika
    ContributorAuthor

    @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.

  12. gabejohnson commented on Apr 11, 2018

    @gabejohnson

    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\"".

  13. natefaubion commented on May 8, 2019

    @natefaubion
    Contributor

    This is fixed in master with the new lexer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions