diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9509cc0..53f17c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,5 @@ jobs: run: pip install "setuptools<81" vim-vint - name: Lint Vimscript run: vint ftdetect ftplugin syntax + - name: Test regex highlighting + run: vim -Nu NONE -n -es -S tests/regex_syntax.vim diff --git a/syntax/sema.vim b/syntax/sema.vim index 4298eb9..12abdd6 100644 --- a/syntax/sema.vim +++ b/syntax/sema.vim @@ -18,6 +18,7 @@ syn keyword semaTodo TODO FIXME XXX HACK NOTE contained " ---------- Strings & Characters ---------------------------------------- +syn region semaRegex start=/#"/ skip=/\\./ end=/"/ syn region semaString start=/"/ skip=/\\./ end=/"/ contains=semaStringEscape syn match semaStringEscape /\\./ contained @@ -496,6 +497,7 @@ hi def link semaComment Comment hi def link semaBlockComment Comment hi def link semaTodo Todo hi def link semaString String +hi def link semaRegex String hi def link semaStringEscape SpecialChar hi def link semaNumber Number hi def link semaBoolean Boolean diff --git a/tests/regex_syntax.vim b/tests/regex_syntax.vim new file mode 100644 index 0000000..2a94915 --- /dev/null +++ b/tests/regex_syntax.vim @@ -0,0 +1,27 @@ +set nocompatible +set runtimepath^=. +syntax on + +new +setfiletype sema +call setline(1, '(regex/match? #"\d+" "123")') +call setline(2, '(regex/match? #"\"[^\"]+\"" text)') +call setline(3, '(regex/match? #"\\" text)') + +function! AssertGroup(line, column, expected) abort + let actual = synIDattr(synID(a:line, a:column, 1), 'name') + if actual !=# a:expected + echom printf('%d:%d expected %s, got %s', a:line, a:column, a:expected, actual) + cquit 1 + endif +endfunction + +call AssertGroup(1, 2, 'semaBuiltin') +call AssertGroup(1, 15, 'semaRegex') +call AssertGroup(1, 17, 'semaRegex') +call AssertGroup(2, 15, 'semaRegex') +call AssertGroup(2, 18, 'semaRegex') +call AssertGroup(3, 15, 'semaRegex') +call AssertGroup(3, 17, 'semaRegex') + +quitall!