From 79c07fdc26241c1490c079c6526e6560c808c220 Mon Sep 17 00:00:00 2001 From: namniav Date: Tue, 12 Dec 2023 06:00:23 +0800 Subject: [PATCH] Fix syntax highlighting for bracket arguments and comments Fix syntax highlighting for `cmakeBracketArgument`, `cmakeComment` and `cmakeBracketComment`. --- syntax/cmake.vim | 6 +- test/bracket-args-and-comment.cmake.html.ref | 68 ++++++++++---------- test/run-test.sh | 11 +++- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/syntax/cmake.vim b/syntax/cmake.vim index 3533fc2..178e6a7 100644 --- a/syntax/cmake.vim +++ b/syntax/cmake.vim @@ -19,10 +19,10 @@ endif let s:keepcpo= &cpo set cpo&vim -syn region cmakeBracketArgument start="\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell +syn region cmakeBracketArgument start="\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell -syn region cmakeComment start="#" end="$" contains=cmakeTodo,@Spell -syn region cmakeBracketComment start="\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell +syn region cmakeComment start="#\(\[=*\[\)\@!" end="$" contains=cmakeTodo,@Spell +syn region cmakeBracketComment start="#\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell syn match cmakeEscaped /\(\\\\\|\\"\|\\n\|\\t\)/ contained syn region cmakeRegistry start="\[" end="]" contained oneline contains=cmakeTodo,cmakeEscaped diff --git a/test/bracket-args-and-comment.cmake.html.ref b/test/bracket-args-and-comment.cmake.html.ref index 4cfa905..9c826db 100644 --- a/test/bracket-args-and-comment.cmake.html.ref +++ b/test/bracket-args-and-comment.cmake.html.ref @@ -1,39 +1,39 @@
-message(FATAL_ERROR [[
-This is the first line in a bracket argument with bracket length 1.
-No \-escape sequences or ${variable} references are evaluated.
-This is always one argument even though it contains a ; character.
-It does end in a closing bracket of length 1.
-]])
-
-message(FATAL_ERROR [=[
-This is the first line in a bracket argument with bracket length 1.
-No \-escape sequences or ${variable} references are evaluated.
-This is always one argument even though it contains a ; character.
-The text does not end on a closing bracket of length 0 like ]].
-It does end in a closing bracket of length 1.
-]=])
-
-message(FATAL_ERROR [==[
-This is the first line in a bracket argument with bracket length 1.
-No \-escape sequences or ${variable} references are evaluated.
-This is always one argument even though it contains a ; character.
-The text does not end on a closing bracket of length 0 like ]].
-It does end in a closing bracket of length 1.
-]==])
-
-[[ # this will make a cmake-error but defines a bracket-arguemnt
-cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be string-colored
-]]
+message(FATAL_ERROR [[
+This is the first line in a bracket argument with bracket length 1.
+No \-escape sequences or ${variable} references are evaluated.
+This is always one argument even though it contains a ; character.
+It does end in a closing bracket of length 1.
+]])
+
+message(FATAL_ERROR [=[
+This is the first line in a bracket argument with bracket length 1.
+No \-escape sequences or ${variable} references are evaluated.
+This is always one argument even though it contains a ; character.
+The text does not end on a closing bracket of length 0 like ]].
+It does end in a closing bracket of length 1.
+]=])
+
+message(FATAL_ERROR [==[
+This is the first line in a bracket argument with bracket length 1.
+No \-escape sequences or ${variable} references are evaluated.
+This is always one argument even though it contains a ; character.
+The text does not end on a closing bracket of length 0 like ]].
+It does end in a closing bracket of length 1.
+]==])
+
+[[ # this will make a cmake-error but defines a bracket-arguemnt
+cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be string-colored
+]]
 
 #[[
-cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be greyed out
-]] target_link_libraries(t lib)
+cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be greyed out
+]] target_link_libraries(t lib)
 
 #[[
-cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be greyed out
-#]] target_link_libraries(t lib)
+cmake_minimum_required(VERSION 4.0 FATAL_ERROR) # Should be greyed out
+#]] target_link_libraries(t lib)
 
 # commented bracket-comment
 ##[[
@@ -41,13 +41,13 @@
 #]]
 
 #[[This is a bracket comment.
-It runs until the close bracket.]]
+It runs until the close bracket.]]
 
-message("First Argument\n" #[[Bracket Comment]] "Second Argument")
+message("First Argument\n" #[[Bracket Comment]] "Second Argument")
 
 #[=[
-comment
-]=]
+comment
+]=]
 
 
diff --git a/test/run-test.sh b/test/run-test.sh index 35fa48b..0911548 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -6,8 +6,15 @@ TMP=$(mktemp) vim -u .vimrc -n -es -c TOhtml -c "w! $TMP" -c 'qa!' $1.cmake >/dev/null 2>&1 # extract the body of the html-file -sed -i -n -e '//,$p' $TMP -sed -i '/<\/body>/q' $TMP +if [[ "$OSTYPE" =~ ^darwin ]]; then + # macOS's builtin sed expects a suffix to create backup before in-place + # editing. An empty suffix prevents the backup. + sed -i "" -n -e '//,$p' $TMP + sed -i "" '/<\/body>/q' $TMP +else + sed -i -n -e '//,$p' $TMP + sed -i '/<\/body>/q' $TMP +fi # diff with references diff -u $1.cmake.html.ref $TMP