Module Name:    src
Committed By:   rillig
Date:           Sun Aug  9 07:41:14 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: modmisc.exp modmisc.mk

Log Message:
make(1): explain the mod-subst-dollar test


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/make/unit-tests/modmisc.exp
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/make/unit-tests/modmisc.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/unit-tests/modmisc.exp
diff -u src/usr.bin/make/unit-tests/modmisc.exp:1.39 src/usr.bin/make/unit-tests/modmisc.exp:1.40
--- src/usr.bin/make/unit-tests/modmisc.exp:1.39	Sun Aug  9 07:18:03 2020
+++ src/usr.bin/make/unit-tests/modmisc.exp	Sun Aug  9 07:41:14 2020
@@ -57,6 +57,7 @@ mod-subst-dollar:$8:
 mod-subst-dollar:$40:
 mod-subst-dollar:U8:
 mod-subst-dollar:$$$$:
+mod-subst-dollar:$$$good3
 mod-loop-dollar:1:
 mod-loop-dollar:${word}$:
 mod-loop-dollar:$3$:

Index: src/usr.bin/make/unit-tests/modmisc.mk
diff -u src/usr.bin/make/unit-tests/modmisc.mk:1.37 src/usr.bin/make/unit-tests/modmisc.mk:1.38
--- src/usr.bin/make/unit-tests/modmisc.mk:1.37	Sun Aug  9 07:18:03 2020
+++ src/usr.bin/make/unit-tests/modmisc.mk	Sun Aug  9 07:41:14 2020
@@ -1,4 +1,4 @@
-# $Id: modmisc.mk,v 1.37 2020/08/09 07:18:03 rillig Exp $
+# $Id: modmisc.mk,v 1.38 2020/08/09 07:41:14 rillig Exp $
 #
 # miscellaneous modifier tests
 
@@ -207,6 +207,16 @@ mod-loop-varname-dollar:
 
 # No matter how many dollar characters there are, they all get merged
 # into a single dollar by the :S modifier.
+#
+# As of 2020-08-09, this is because ParseModifierPart sees a '$' and
+# calls Var_Parse to expand the variable.  In all other places, the "$$"
+# is handled outside of Var_Parse.  Var_Parse therefore considers "$$"
+# one of the "really stupid names", skips the first dollar, and parsing
+# continues with the next character.  This repeats for the other dollar
+# signs, except the one before the delimiter.  That one is handled by
+# the code that optionally interprets the '$' as the end-anchor in the
+# first part of the :S modifier.  That code doesn't call Var_Parse but
+# simply copies the dollar to the result.
 mod-subst-dollar:
 	@echo $@:${:U1:S,^,$,:Q}:
 	@echo $@:${:U2:S,^,$$,:Q}:
@@ -222,6 +232,9 @@ mod-subst-dollar:
 # Here is an alternative way to generate dollar characters.
 # It's unexpectedly complicated though.
 	@echo $@:${:U:range=5:ts\x24:C,[0-9],,g:Q}:
+# In modifiers, dollars are escaped using the backslash, not using another
+# dollar sign.  Therefore, creating a dollar sign is pretty simple:
+	@echo $@:${:Ugood3:S,^,\$\$\$,:Q}
 
 # Demonstrate that it is possible to generate dollar characters using the
 # :@ modifier.

Reply via email to