Skip to content

Double quoted strings and escapes #9

@schveiguy

Description

@schveiguy

Since a primary use of interpolation strings is mixins, requiring escapes in interpolation strings becomes very cumbersome. For example, to include a \n in the mixin, you need to escape the backslash. Ditto with double quotes.

It also isn't clear whether escapes are needed. The grammar does not support it. All the grammar has is the same for double quoted strings, and then (I'm assuming) once parsed, you have to parse any interpolation sequences according to the secondary grammar. What if there are characters that need escapes inside the interpolation? e.g. are these backslashes needed?

i"Hello $(capitalize(lastname ~ \", \" ~ firstname))"

If not needed, the grammar doesn't reflect this. If needed, this is going to be a lot less attractive for mixins.

For reference, DIP1036 encodes the grammar of the expressions directly in the string type. It's not much more grammar, although it is repetitive. But the benefit is that it's clear that escapes are not needed for the interpolation sequences.

And finally, it seems odd that all other escapes in double quoted strings use backslashes, yet interpolation tokens use double $. Would it make sense to simply add \$ to the list (this is what I did in DIP1036)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions