Module Name:    src
Committed By:   rillig
Date:           Tue Aug 25 16:20:32 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: var-op-assign.exp var-op-assign.mk

Log Message:
make(1): demonstrate how the parser handles spaces in variable names

Not that anyone would need this feature, or that it was ever intended to
be used at all.  But it is there, and if someone ever wants to fix this
part of the parser, they should at least know about this behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/var-op-assign.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/var-op-assign.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/var-op-assign.exp
diff -u src/usr.bin/make/unit-tests/var-op-assign.exp:1.2 src/usr.bin/make/unit-tests/var-op-assign.exp:1.3
--- src/usr.bin/make/unit-tests/var-op-assign.exp:1.2	Tue Aug 25 16:07:39 2020
+++ src/usr.bin/make/unit-tests/var-op-assign.exp	Tue Aug 25 16:20:32 2020
@@ -1,2 +1,6 @@
 this will be evaluated later
-exit status 0
+make: "var-op-assign.mk" line 52: Need an operator
+make: "var-op-assign.mk" line 86: Parsing still continues until here.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/var-op-assign.mk
diff -u src/usr.bin/make/unit-tests/var-op-assign.mk:1.3 src/usr.bin/make/unit-tests/var-op-assign.mk:1.4
--- src/usr.bin/make/unit-tests/var-op-assign.mk:1.3	Tue Aug 25 16:07:39 2020
+++ src/usr.bin/make/unit-tests/var-op-assign.mk	Tue Aug 25 16:20:32 2020
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-assign.mk,v 1.3 2020/08/25 16:07:39 rillig Exp $
+# $NetBSD: var-op-assign.mk,v 1.4 2020/08/25 16:20:32 rillig Exp $
 #
 # Tests for the = variable assignment operator, which overwrites an existing
 # variable or creates it.
@@ -47,5 +47,43 @@ VAR=	${:! echo 'this will be evaluated l
 .if ${VAR}
 .endif
 
+# In a variable assignment, the variable name must consist of a single word.
+#
+VARIABLE NAME=	variable value
+
+# But if the whitespace appears inside parentheses or braces, everything is
+# fine.
+#
+# XXX: This was not an intentional decision, as variable names typically
+# neither contain parentheses nor braces.  This is only a side-effect from
+# the implementation of the parser, which cheats when parsing a variable
+# name.  It only counts parentheses and braces instead of properly parsing
+# nested variable expressions such as VAR.${param}.
+#
+VAR(spaces in parentheses)=	()
+VAR{spaces in braces}=		{}
+
+# Be careful and use indirect variable names here, to prevent accidentally
+# accepting the test in case the parser just uses "VAR" as the variable name,
+# ignoring all the rest.
+#
+VARNAME_PAREN=	VAR(spaces in parentheses)
+VARNAME_BRACES=	VAR{spaces in braces}
+
+.if ${${VARNAME_PAREN}} != "()"
+.error
+.endif
+
+.if ${${VARNAME_BRACES}} != "{}"
+.error
+.endif
+
+# In safe mode, parsing would stop immediately after the "VARIABLE NAME="
+# line, since any commands run after that are probably working with
+# unexpected variable values.
+#
+# Therefore, just output an info message.
+.info Parsing still continues until here.
+
 all:
 	@:;

Reply via email to