Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make(1): demonstrate how the parser ...
details: https://anonhg.NetBSD.org/src/rev/19f6f8765826
branches: trunk
changeset: 1013315:19f6f8765826
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Aug 25 16:20:32 2020 +0000
description:
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.
diffstat:
usr.bin/make/unit-tests/var-op-assign.exp | 6 +++-
usr.bin/make/unit-tests/var-op-assign.mk | 40 ++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 2 deletions(-)
diffs (64 lines):
diff -r 6ec127ffa04e -r 19f6f8765826 usr.bin/make/unit-tests/var-op-assign.exp
--- a/usr.bin/make/unit-tests/var-op-assign.exp Tue Aug 25 16:07:39 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-assign.exp Tue Aug 25 16:20:32 2020 +0000
@@ -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
diff -r 6ec127ffa04e -r 19f6f8765826 usr.bin/make/unit-tests/var-op-assign.mk
--- a/usr.bin/make/unit-tests/var-op-assign.mk Tue Aug 25 16:07:39 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-assign.mk Tue Aug 25 16:20:32 2020 +0000
@@ -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 @@
.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:
@:;
Home |
Main Index |
Thread Index |
Old Index