Skip to content

Commit f2e6828

Browse files
committed
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.
1 parent eabd645 commit f2e6828

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/languages/vim.js

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<span class="hljs-comment">" comment</span>
2+
<span class="hljs-keyword">let</span> one = <span class="hljs-string">"string"</span> <span class="hljs-comment">" comment</span>
3+
<span class="hljs-keyword">let</span> two = <span class="hljs-string">"crazy
4+
\ string with a \" quote"</span>

test/markup/vim/strings-comments.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
" comment
2+
let one = "string" " comment
3+
let two = "crazy
4+
\ string with a \" quote"

0 commit comments

Comments
 (0)