Browse files

More correct handling of strings/comments in Vim

Both of those start with a double quote (").

- if it's at BOL, it's a line comment,
- if it's in the middle of a line it's:
  - a string, if it's terminated by a double quote
  - a comment, if it's terminated by EOL

Strings can also contain escaped double quotes and line breaks
*followed* by a back slash (\).

Currently we don't respect the BOL condition, we only look if the
lexeme is ended by a quote. It means that a comment started at BOL
that contains a double quote will be mis-highlighted. Handling it
properly is a fragile pain in the ass with the current parser. We
lose BOL context when test for individual lexems in testRe(), so it
requires splitting the whole body of the language by lines and
treating them either as comments or as everything else.
  • Loading branch information...
isagalaev committed Jan 13, 2016
1 parent eabd645 commit f2e6828b08e5989267494cdc59a880b6c4051d3b
Showing with 22 additions and 2 deletions.
  1. +14 −2 src/languages/vim.js
  2. +4 −0 test/markup/vim/strings-comments.expect.txt
  3. +4 −0 test/markup/vim/strings-comments.txt

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,4 @@
<span class="hljs-comment">" comment</span>
<span class="hljs-keyword">let</span> one = <span class="hljs-string">"string"</span> <span class="hljs-comment">" comment</span>
<span class="hljs-keyword">let</span> two = <span class="hljs-string">"crazy
\ string with a \" quote"</span>
@@ -0,0 +1,4 @@
" comment
let one = "string" " comment
let two = "crazy
\ string with a \" quote"

0 comments on commit f2e6828

Please sign in to comment.