]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(make): Move target greedy match after $() to avoid region matching overflow
authorYiyang Wu <xgreenlandforwyy@gmail.com>
Tue, 23 Dec 2025 21:25:04 +0000 (21:25 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 23 Dec 2025 21:25:04 +0000 (21:25 +0000)
Partially revert 2a33b499a3d7f46dc307234847a6562cef6cf1d8, where all
syn match makeIdent are moved before syn region makeIdent to match $()
(reason: see https://github.com/vim/vim/pull/18403#issuecomment-3341161566)

However this results in https://github.com/vim/vim/issues/18890 ,
because lines like
`$(a) =`
will first start a region search beginning with `$(`
but then the whole target including `)` will be matched by
`syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1`
which leaves the region search for the never-found `)` and let the
region matching overflow.

Same for

`$(a) ::`
`$(a) +=`

The solution is to move those greedy target match back, so they take
priority and prevents region match from happening.

fixes:  #18890
closes: #18938

Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/syntax/make.vim
runtime/syntax/testdir/dumps/make_01_00.dump [new file with mode: 0644]
runtime/syntax/testdir/input/make_01.mak [new file with mode: 0644]

index 338150fa94800324eb67cd02d8c1fcf5ffd27e23..dc649b1258937d189608a753d8db8f3b3cdbba37 100644 (file)
@@ -7,6 +7,7 @@
 " 2025 Apr 15 by Vim project: rework Make flavor detection (#17089)
 " 2025 Oct 12 by Vim project: update makeDefine highlighting (#18403)
 " 2025 Oct 25 by Vim project: update makeTargetinDefine highlighting (#18570)
+" 2025 Dec 23 by Vim project: fix too greedy match (#18938)
 
 " quit when a syntax file was already loaded
 if exists("b:current_syntax")
@@ -40,10 +41,6 @@ syn match makeIdent  "\$\$\w*"
 syn match makeIdent    "\$\$\$\$\w*" containedin=makeDefine
 syn match makeIdent    "\$[^({]"
 syn match makeIdent    "\$\$[^({]" containedin=makeDefine
-syn match makeIdent    "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
-syn match makeIdent    "^ *[^:#= \t]*\s*::="me=e-3
-syn match makeIdent    "^ *[^:#= \t]*\s*="me=e-1
-syn match makeIdent    "%"
 if get(b:, 'make_flavor', s:make_flavor) == 'microsoft'
   syn region makeIdent start="\$(" end=")" contains=makeStatement,makeIdent
   syn region makeIdent start="\${" end="}" contains=makeStatement,makeIdent
@@ -55,6 +52,10 @@ else
   syn region makeIdent start="\$\$(" skip="\\)\|\\\\" end=")" containedin=makeDefine contains=makeStatement,makeIdent
   syn region makeIdent start="\$\${" skip="\\}\|\\\\" end="}" containedin=makeDefine contains=makeStatement,makeIdent
 endif
+syn match makeIdent    "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
+syn match makeIdent    "^ *[^:#= \t]*\s*::="me=e-3
+syn match makeIdent    "^ *[^:#= \t]*\s*="me=e-1
+syn match makeIdent    "%"
 
 " Makefile.in variables
 syn match makeConfig "@[A-Za-z0-9_]\+@"
diff --git a/runtime/syntax/testdir/dumps/make_01_00.dump b/runtime/syntax/testdir/dumps/make_01_00.dump
new file mode 100644 (file)
index 0000000..3ac6700
--- /dev/null
@@ -0,0 +1,20 @@
+>#+0#0000e05#ffffff0| |c|o|m@1|e|n|t| +0#0000000&@65
+@75
+|a+0#00e0e07&| |=+0#0000000&| |b| @69
+|$+0#00e0e07&|(|a|)| |=+0#0000000&| |1| @66
+@75
+|$+0#00e0e07&|(|a|)|:@1| +0#0000000&@68
+| +0#e000e06&@7|@|e+0#e000002&|c|h|o| |d|o|u|b|l|e|-|c|o|l|o|n| |r|u|l|e| +0#0000000&@43
+@75
+|$+0#00e0e07&|(|a|)| |++0#0000000&|=| |o|u|t|p|u|t| @60
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1| 
diff --git a/runtime/syntax/testdir/input/make_01.mak b/runtime/syntax/testdir/input/make_01.mak
new file mode 100644 (file)
index 0000000..28c6147
--- /dev/null
@@ -0,0 +1,9 @@
+# comment
+
+a = b
+$(a) = 1
+
+$(a)::
+       @echo double-colon rule
+
+$(a) += output