Closed bocchino closed 3 years ago
Also think about reverting the notation for an escaped quotation mark to \"
. We switched to \q
because it is less awkward at the end of a string. However, in either case we can't avoid \\
, and \"
is more standard.
I've decided to keep \q
for quotation marks and add \b
for backslashes.
Keeping \q
lets us parse multiline strings in a straightforward way, using the first occurrence of """
as the end delimiter. If we allow \"
, then with this straightforward approach """Hello\""""
is an illegal character sequence ("""Hello\"""
followed by "
). To allow this string, we'd have to pass over the """
after the \
. To do this, we would need parsing rules with lookahead.
Keeping \b
lets us use simple substitution: (1) apply \q
-> "
then (2) apply \b
-> \
. If we use \\
instead, then substitution yields either \\q
-> \q
-> "
or \\q
-> \"
, when in fact the answer should be \q
. To make this work, again we would need parsing rules with lookahead.
After all that, I switched to a state-based parser for strings, instead of a regex-based parser. So I can now support \"
and \\
. I think it's better because it's more standard.
The new rule is that \
c is interpreted as the literal character c in all cases. Nice and simple. In particular, to get a backslash in the interpreted string, you have to write \\
in all cases. This fosters consistency.
Done in commit 5b60cf7a65d0bf23f8cf31fa2e8a4cf037057174.
Otherwise we can't write the character sequence
\q
, because it's interpreted as a double-quote character.