"foo\\" produces incorrect parse error #1049

kballard opened this Issue Dec 20, 2016 · 3 comments


None yet

2 participants


If I terminate any double-quoted string with \\, Kakoune throws a parse error regarding an unterminated string, as if I had ended it with just \ (which would then escape the double quote).


echo "foo\\x" # works
echo "foo\\" # parse error
echo "\\" # parse error

Similarly, putting \\ before a " escapes it just as putting merely \ does:

echo "foo\\"bar" # this works, but shouldn't

As near as I can tell, it's parsing for the end of the string separately from how it parses escapes, and when it finds a " it simply looks one character back to see if it's a \ and if so, treats the quote as escaped, even if that \ had itself been escaped.


It occurs to me that with this fixed, there's one subtlety, which is how is "%"foo"" parsed? The two options are:

  1. Terminate the string literal at the 2nd ", leaving you with a string that just contains %, which would then presumably throw an error just as it does today if you use "%"
  2. Parse the 2nd " as the start delimiter of the %{-expansion, which makes the whole thing parse as one string with an embedded expansion.

I'd lean towards the first simply because, with either approach, "%" produces an error, but the error produced from approach 1 makes more sense than complaining about an unterminated string (because it tells the user that the % is trying to introduce a string expansion, rather than confusing them by saying there's no string terminator when it looks like there is one).

mawww commented Dec 21, 2016

Regarding "%"foo"", it should do the first option, we parse the content on the "..." later on, so the existence of expands in the string content has no impact on how we parse it, we just look for the first non escaped closer.

The other behaviour seems to be an error, I'll take a stab at fixing that when I get a bit of time.

mawww commented Jan 5, 2017

Argh, I took a look, its pretty easy to fix, but it brings us into escaping hell, as \\ now needs to be written \\\\ in "..." and '...' strings. Thankfully we have % strings that do not support escaping at all.

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