Module Name:    src
Committed By:   rillig
Date:           Sat Mar 29 11:51:54 UTC 2025

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: moderrs.exp moderrs.mk varmod-assign.exp
            varmod-assign.mk varmod-edge.exp varmod-edge.mk varmod-sysv.exp
            varmod-sysv.mk

Log Message:
make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.


To generate a diff of this commit:
cvs rdiff -u -r1.1147 -r1.1148 src/usr.bin/make/var.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/make/unit-tests/moderrs.mk
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/make/unit-tests/varmod-assign.exp
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/varmod-assign.mk
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/make/unit-tests/varmod-edge.exp
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/make/unit-tests/varmod-edge.mk
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-sysv.exp
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/make/unit-tests/varmod-sysv.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1147 src/usr.bin/make/var.c:1.1148
--- src/usr.bin/make/var.c:1.1147	Sat Mar 29 11:24:34 2025
+++ src/usr.bin/make/var.c	Sat Mar 29 11:51:53 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1147 2025/03/29 11:24:34 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1148 2025/03/29 11:51:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -128,7 +128,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1147 2025/03/29 11:24:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1148 2025/03/29 11:51:53 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2232,13 +2232,15 @@ ParseModifierPart(
 			ParseModifierPartExpr(&p, part, ch, emode);
 	}
 
-	*pp = p;
 	if (*p != end1 && *p != end2) {
 		Parse_Error(PARSE_FATAL,
-		    "Unfinished modifier ('%c' missing)", end2);
+		    "Unfinished modifier after \"%.*s\", expecting \"%c\"",
+		    (int)(p - *pp), *pp, end2);
 		LazyBuf_Done(part);
+		*pp = p;
 		return false;
 	}
+	*pp = p;
 	if (end1 == end2)
 		(*pp)++;
 

Index: src/usr.bin/make/unit-tests/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.47 src/usr.bin/make/unit-tests/moderrs.exp:1.48
--- src/usr.bin/make/unit-tests/moderrs.exp:1.47	Sat Mar 29 11:24:34 2025
+++ src/usr.bin/make/unit-tests/moderrs.exp	Sat Mar 29 11:51:54 2025
@@ -15,16 +15,16 @@ make: Unclosed expression after indirect
 	while evaluating variable "VAR" with value "Thevariable"
 	in command "@echo VAR:${MOD_TERM},=${VAR:${MOD_S}"
 	in target "unclosed-indirect"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "v", expecting ","
 	while evaluating indirect modifiers "S,V,v"
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "-@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}""
 	in target "unfinished-indirect"
-make: Unfinished modifier ('@' missing)
+make: Unfinished modifier after "var}", expecting "@"
 	while evaluating variable "UNDEF" with value "1 2 3"
 	in command "@echo ${UNDEF:U1 2 3:@var}"
 	in target "unfinished-loop-1"
-make: Unfinished modifier ('@' missing)
+make: Unfinished modifier after "...}", expecting "@"
 	while evaluating variable "UNDEF" with value "1 2 3"
 	in command "@echo ${UNDEF:U1 2 3:@var@...}"
 	in target "unfinished-loop-2"
@@ -34,11 +34,11 @@ make: Unclosed expression, expecting '}'
 	in command "@echo ${UNDEF:U1 2 3:@var@${var}}...@"
 	in target "loop-close-1"
 1}... 2}... 3}...
-make: Unfinished modifier (']' missing)
+make: Unfinished modifier after "}", expecting "]"
 	while evaluating variable "UNDEF" with value "1 2 3"
 	in command "@echo ${UNDEF:U1 2 3:[}"
 	in target "words-1"
-make: Unfinished modifier (']' missing)
+make: Unfinished modifier after "#}", expecting "]"
 	while evaluating variable "UNDEF" with value "1 2 3"
 	in command "@echo ${UNDEF:U1 2 3:[#}"
 	in target "words-2"
@@ -47,11 +47,11 @@ make: Bad modifier ":[123451234512345123
 	while evaluating variable "UNDEF" with value "1 2 3"
 	in command "@echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}"
 	in target "words-3"
-make: Unfinished modifier ('!' missing)
+make: Unfinished modifier after "echo}", expecting "!"
 	while evaluating variable "VARNAME" with value ""
 	in command "@echo ${VARNAME:!echo}"
 	in target "exclam-1"
-make: Unfinished modifier ('!' missing)
+make: Unfinished modifier after "=exclam}", expecting "!"
 	while evaluating variable "!" with value "!"
 	in command "@echo ${!:L:!=exclam}"
 	in target "exclam-2"
@@ -59,19 +59,19 @@ make: Missing delimiter for modifier ':S
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 1: ${VAR:S"
 	in target "mod-subst-delimiter-1"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 2: ${VAR:S,"
 	in target "mod-subst-delimiter-2"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "from", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 3: ${VAR:S,from"
 	in target "mod-subst-delimiter-3"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 4: ${VAR:S,from,"
 	in target "mod-subst-delimiter-4"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "to", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 5: ${VAR:S,from,to"
 	in target "mod-subst-delimiter-5"
@@ -84,19 +84,19 @@ make: Missing delimiter for modifier ':C
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 1: ${VAR:C"
 	in target "mod-regex-delimiter-1"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 2: ${VAR:C,"
 	in target "mod-regex-delimiter-2"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "from", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 3: ${VAR:C,from"
 	in target "mod-regex-delimiter-3"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 4: ${VAR:C,from,"
 	in target "mod-regex-delimiter-4"
-make: Unfinished modifier (',' missing)
+make: Unfinished modifier after "to", expecting ","
 	while evaluating variable "VAR" with value "TheVariable"
 	in command "@echo 5: ${VAR:C,from,to"
 	in target "mod-regex-delimiter-5"
@@ -135,19 +135,19 @@ make: Bad modifier ":t"
 	while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34"
 	in command "@echo ${FIB:t:M*}"
 	in target "mod-t-parse-4"
-make: Unfinished modifier (':' missing)
+make: Unfinished modifier after "", expecting ":"
 	while evaluating then-branch of condition "FIB"
 	in command "@echo ${FIB:?"
 	in target "mod-ifelse-parse-1"
-make: Unfinished modifier (':' missing)
+make: Unfinished modifier after "then", expecting ":"
 	while evaluating then-branch of condition "FIB"
 	in command "@echo ${FIB:?then"
 	in target "mod-ifelse-parse-2"
-make: Unfinished modifier ('}' missing)
+make: Unfinished modifier after "", expecting "}"
 	while evaluating else-branch of condition "FIB"
 	in command "@echo ${FIB:?then:"
 	in target "mod-ifelse-parse-3"
-make: Unfinished modifier ('}' missing)
+make: Unfinished modifier after "else", expecting "}"
 	while evaluating else-branch of condition "FIB"
 	in command "@echo ${FIB:?then:else"
 	in target "mod-ifelse-parse-4"

Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.41 src/usr.bin/make/unit-tests/moderrs.mk:1.42
--- src/usr.bin/make/unit-tests/moderrs.mk:1.41	Thu Aug 29 20:20:36 2024
+++ src/usr.bin/make/unit-tests/moderrs.mk	Sat Mar 29 11:51:54 2025
@@ -1,4 +1,4 @@
-# $NetBSD: moderrs.mk,v 1.41 2024/08/29 20:20:36 rillig Exp $
+# $NetBSD: moderrs.mk,v 1.42 2025/03/29 11:51:54 rillig Exp $
 #
 # various modifier error tests
 
@@ -41,14 +41,14 @@ unclosed-indirect:
 	@echo VAR:${MOD_TERM},=${VAR:${MOD_S}
 
 unfinished-indirect:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "v", expecting ","
 	-@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
 
 unfinished-loop-1:
-# expect: make: Unfinished modifier ('@' missing)
+# expect: make: Unfinished modifier after "var}", expecting "@"
 	@echo ${UNDEF:U1 2 3:@var}
 unfinished-loop-2:
-# expect: make: Unfinished modifier ('@' missing)
+# expect: make: Unfinished modifier after "...}", expecting "@"
 	@echo ${UNDEF:U1 2 3:@var@...}
 unfinished-loop-3:
 	@echo ${UNDEF:U1 2 3:@var@${var}@}
@@ -66,10 +66,10 @@ loop-close-2:
 	@echo ${UNDEF:U1 2 3:@var@${var}}...@}
 
 words-1:
-# expect: make: Unfinished modifier (']' missing)
+# expect: make: Unfinished modifier after "}", expecting "]"
 	@echo ${UNDEF:U1 2 3:[}
 words-2:
-# expect: make: Unfinished modifier (']' missing)
+# expect: make: Unfinished modifier after "#}", expecting "]"
 	@echo ${UNDEF:U1 2 3:[#}
 
 words-3:
@@ -96,30 +96,30 @@ words-3:
 	@echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
 
 exclam-1:
-# expect: make: Unfinished modifier ('!' missing)
+# expect: make: Unfinished modifier after "echo}", expecting "!"
 	@echo ${VARNAME:!echo}
 	# When the final exclamation mark is missing, there is no
 	# fallback to the SysV substitution modifier.
 	# If there were a fallback, the output would be "exclam",
 	# and the above would have produced an "Unknown modifier '!'".
 exclam-2:
-# expect: make: Unfinished modifier ('!' missing)
+# expect: make: Unfinished modifier after "=exclam}", expecting "!"
 	@echo ${!:L:!=exclam}
 
 mod-subst-delimiter-1:
 # expect: make: Missing delimiter for modifier ':S'
 	@echo 1: ${VAR:S
 mod-subst-delimiter-2:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "", expecting ","
 	@echo 2: ${VAR:S,
 mod-subst-delimiter-3:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "from", expecting ","
 	@echo 3: ${VAR:S,from
 mod-subst-delimiter-4:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "", expecting ","
 	@echo 4: ${VAR:S,from,
 mod-subst-delimiter-5:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "to", expecting ","
 	@echo 5: ${VAR:S,from,to
 mod-subst-delimiter-6:
 # expect: make: Unclosed expression, expecting '}' for modifier "S,from,to,"
@@ -131,16 +131,16 @@ mod-regex-delimiter-1:
 # expect: make: Missing delimiter for modifier ':C'
 	@echo 1: ${VAR:C
 mod-regex-delimiter-2:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "", expecting ","
 	@echo 2: ${VAR:C,
 mod-regex-delimiter-3:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "from", expecting ","
 	@echo 3: ${VAR:C,from
 mod-regex-delimiter-4:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "", expecting ","
 	@echo 4: ${VAR:C,from,
 mod-regex-delimiter-5:
-# expect: make: Unfinished modifier (',' missing)
+# expect: make: Unfinished modifier after "to", expecting ","
 	@echo 5: ${VAR:C,from,to
 mod-regex-delimiter-6:
 # expect: make: Unclosed expression, expecting '}' for modifier "C,from,to,"
@@ -176,16 +176,16 @@ mod-t-parse-4:
 	@echo ${FIB:t:M*}
 
 mod-ifelse-parse-1:
-# expect: make: Unfinished modifier (':' missing)
+# expect: make: Unfinished modifier after "", expecting ":"
 	@echo ${FIB:?
 mod-ifelse-parse-2:
-# expect: make: Unfinished modifier (':' missing)
+# expect: make: Unfinished modifier after "then", expecting ":"
 	@echo ${FIB:?then
 mod-ifelse-parse-3:
-# expect: make: Unfinished modifier ('}' missing)
+# expect: make: Unfinished modifier after "", expecting "}"
 	@echo ${FIB:?then:
 mod-ifelse-parse-4:
-# expect: make: Unfinished modifier ('}' missing)
+# expect: make: Unfinished modifier after "else", expecting "}"
 	@echo ${FIB:?then:else
 mod-ifelse-parse-5:
 	@echo ${FIB:?then:else}

Index: src/usr.bin/make/unit-tests/varmod-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.31 src/usr.bin/make/unit-tests/varmod-assign.exp:1.32
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.31	Sat Mar 29 10:39:48 2025
+++ src/usr.bin/make/unit-tests/varmod-assign.exp	Sat Mar 29 11:51:54 2025
@@ -51,7 +51,7 @@ make: Unknown modifier ":x"
 	in command "@echo ${ASSIGN::x}"
 	in target "mod-assign-parse-1"
 sysv:y
-make: Unfinished modifier ('}' missing)
+make: Unfinished modifier after "value	# missing closing brace", expecting "}"
 	while evaluating variable "ASSIGN" with value ""
 	in command "@echo ${ASSIGN::=value	# missing closing brace"
 	in target "mod-assign-parse-3"

Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.25 src/usr.bin/make/unit-tests/varmod-assign.mk:1.26
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.25	Thu Aug 29 20:20:36 2024
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Sat Mar 29 11:51:54 2025
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign.mk,v 1.25 2024/08/29 20:20:36 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.26 2025/03/29 11:51:54 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
@@ -102,7 +102,7 @@ mod-assign-parse-2:
 	@echo ${SYSV::=sysv\:x}${SYSV::x=:y}
 
 mod-assign-parse-3:
-# expect: make: Unfinished modifier ('}' missing)
+# expect: make: Unfinished modifier after "value	# missing closing brace", expecting "}"
 	@echo ${ASSIGN::=value	# missing closing brace
 
 mod-assign-shell-error:

Index: src/usr.bin/make/unit-tests/varmod-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.29 src/usr.bin/make/unit-tests/varmod-edge.exp:1.30
--- src/usr.bin/make/unit-tests/varmod-edge.exp:1.29	Sat Jan 11 20:54:45 2025
+++ src/usr.bin/make/unit-tests/varmod-edge.exp	Sat Mar 29 11:51:54 2025
@@ -5,7 +5,7 @@ make: "varmod-edge.mk" line 60: Unclosed
 make: "varmod-edge.mk" line 88: Unfinished character list in pattern '[[' of modifier ':M'
 	while evaluating variable "INP" with value "[ [[ [[["
 	while evaluating variable "MOD" with value "${INP:M${:U[[}}"
-make: "varmod-edge.mk" line 178: Unfinished modifier ('=' missing)
+make: "varmod-edge.mk" line 178: Unfinished modifier after "a\=b}", expecting "="
 	while evaluating variable "INP" with value "file.c file..."
 	while evaluating variable "MOD" with value "${INP:a\=b}"
 make: "varmod-edge.mk" line 194: Unknown modifier ":"
@@ -16,7 +16,7 @@ make: "varmod-edge.mk" line 194: Unknown
 	while evaluating variable "MOD" with value "${INP::::}"
 make: "varmod-edge.mk" line 200: Unknown modifier "Z"
 	while evaluating "${:Z}" with value ""
-make: "varmod-edge.mk" line 213: Unfinished modifier (',' missing)
+make: "varmod-edge.mk" line 213: Unfinished modifier after "}", expecting ","
 	while evaluating "${:S,}" with value ""
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/varmod-edge.mk
diff -u src/usr.bin/make/unit-tests/varmod-edge.mk:1.33 src/usr.bin/make/unit-tests/varmod-edge.mk:1.34
--- src/usr.bin/make/unit-tests/varmod-edge.mk:1.33	Sat Jan 11 20:54:45 2025
+++ src/usr.bin/make/unit-tests/varmod-edge.mk	Sat Mar 29 11:51:54 2025
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.33 2025/01/11 20:54:45 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.34 2025/03/29 11:51:54 rillig Exp $
 #
 # Tests for edge cases in variable modifiers.
 #
@@ -174,7 +174,7 @@ EXP=	file.c file.ext
 INP=	file.c file...
 MOD=	${INP:a\=b}
 EXP=	# empty
-# expect+1: Unfinished modifier ('=' missing)
+# expect+1: Unfinished modifier after "a\=b}", expecting "="
 .if ${MOD} != ${EXP}
 .  warning expected "${EXP}", got "${MOD}"
 .endif
@@ -209,7 +209,7 @@ EXP=	# empty
 # variable name with quotes, leading to the rather confusing "Unfinished
 # modifier for  (',' missing)", having two spaces in a row.
 #
-# expect+1: Unfinished modifier (',' missing)
+# expect+1: Unfinished modifier after "}", expecting ","
 .if ${:S,}
 .  error
 .else

Index: src/usr.bin/make/unit-tests/varmod-sysv.exp
diff -u src/usr.bin/make/unit-tests/varmod-sysv.exp:1.17 src/usr.bin/make/unit-tests/varmod-sysv.exp:1.18
--- src/usr.bin/make/unit-tests/varmod-sysv.exp:1.17	Sat Jan 11 20:54:46 2025
+++ src/usr.bin/make/unit-tests/varmod-sysv.exp	Sat Mar 29 11:51:54 2025
@@ -1,4 +1,4 @@
-make: "varmod-sysv.mk" line 215: Unfinished modifier ('=' missing)
+make: "varmod-sysv.mk" line 215: Unfinished modifier after "from${:D=}to}", expecting "="
 	while evaluating variable "word216" with value "word216"
 word                     modifier                 result                  
 ''                       =                        ""
@@ -145,7 +145,7 @@ pre-middle-suffix        pre%ffix=NPre% 
 suffix                   pre%ffix=NPre%NS         "suffix"
 prefix                   pre%ffix=NPre%NS         "prefix"
 pre-middle-suffix        pre%ffix=NPre%NS         "NPre-middle-suNS"
-make: "varmod-sysv.mk" line 259: Unfinished modifier ('}' missing)
+make: "varmod-sysv.mk" line 259: Unfinished modifier after "$(})", expecting "}"
 	while evaluating variable "error" with value "error"
 make: Fatal errors encountered -- cannot continue
 make: stopped making "all" in unit-tests

Index: src/usr.bin/make/unit-tests/varmod-sysv.mk
diff -u src/usr.bin/make/unit-tests/varmod-sysv.mk:1.22 src/usr.bin/make/unit-tests/varmod-sysv.mk:1.23
--- src/usr.bin/make/unit-tests/varmod-sysv.mk:1.22	Sat Jan 11 20:54:46 2025
+++ src/usr.bin/make/unit-tests/varmod-sysv.mk	Sat Mar 29 11:51:54 2025
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sysv.mk,v 1.22 2025/01/11 20:54:46 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.23 2025/03/29 11:51:54 rillig Exp $
 #
 # Tests for the variable modifier ':from=to', which replaces the suffix
 # "from" with "to".  It can also use '%' as a wildcard.
@@ -211,7 +211,7 @@
 # XXX: As of 2024-06-30, this expression generates an "Unfinished modifier"
 # error, while the correct error message would be "Unknown modifier" since
 # there is no modifier named "fromto".
-# expect+1: Unfinished modifier ('=' missing)
+# expect+1: Unfinished modifier after "from${:D=}to}", expecting "="
 .if ${word216:L:from${:D=}to}
 .  error
 .endif
@@ -255,7 +255,7 @@ INDIRECT=	1:${VALUE} 2:$${VALUE} 4:$$$${
 
 # The error case of an unfinished ':from=to' modifier after the '=' requires
 # an expression that is missing the closing '}'.
-# expect+1: Unfinished modifier ('}' missing)
+# expect+1: Unfinished modifier after "$(})", expecting "}"
 .if ${error:L:from=$(})
 .endif
 

Reply via email to