parse-var.mk revision 1.5 1 # $NetBSD: parse-var.mk,v 1.5 2022/08/23 19:22:01 rillig Exp $
2 #
3 # Tests for parsing variable expressions.
4
5 .MAKEFLAGS: -dL
6
7 # In variable assignments, there may be spaces in the middle of the left-hand
8 # side of the assignment, but only if they occur inside variable expressions.
9 # Leading spaces (but not tabs) are possible but unusual.
10 # Trailing spaces are common in some coding styles, others omit them.
11 VAR.${:U param }= value
12 .if ${VAR.${:U param }} != "value"
13 . error
14 .endif
15
16 # XXX: The following paragraph already uses past tense, in the hope that the
17 # parsing behavior can be cleaned up soon.
18
19 # Since var.c 1.323 from 2020-07-26 18:11 and except for var.c 1.1028 from
20 # 2022-08-08, the exact way of parsing an expression depended on whether the
21 # expression was actually evaluated or merely parsed.
22 #
23 # If it was evaluated, nested expressions were parsed correctly, parsing each
24 # modifier according to its exact definition (see varmod.mk).
25 #
26 # If the expression was merely parsed but not evaluated (for example, because
27 # its value would not influence the outcome of the condition, or during the
28 # first pass of the ':@var@body@' modifier), and the expression contained a
29 # modifier, and that modifier contained a nested expression, the nested
30 # expression was not parsed correctly. Instead, make only counted the opening
31 # and closing delimiters, which failed for nested modifiers with unbalanced
32 # braces.
33 #
34 # This naive brace counting was implemented in ParseModifierPartDollar. As of
35 # var.c 1.1029, there are still several other places that merely count braces
36 # instead of properly parsing subexpressions.
37
38 #.MAKEFLAGS: -dcpv
39 # Keep these braces outside the conditions below, to keep them simple to
40 # understand. If the BRACE_PAIR had been replaced with ':U{}', the '}' would
41 # have to be escaped, but not the '{'. This asymmetry would have made the
42 # example even more complicated to understand.
43 BRACE_PAIR= {}
44 # In this test word, the '{{}' in the middle will be replaced.
45 BRACE_GROUP= {{{{}}}}
46
47 # The inner ':S' modifier turns the word '{}' into '{{}'.
48 # The outer ':S' modifier then replaces '{{}' with '<lbraces>'.
49 # In the first case, the outer expression is relevant and is parsed correctly.
50 .if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
51 .endif
52 # In the second case, the outer expression was irrelevant. In this case, in
53 # the parts of the outer ':S' modifier, make only counted the braces, and since
54 # the inner expression '${BRACE_PAIR:...}' contains more '{' than '}', parsing
55 # failed with the error message 'Unfinished modifier for "BRACE_GROUP"'. Fixed
56 # in var.c 1.1028 from 2022-08-08, reverted in var.c 1.1029 from 2022-08-23.
57 .if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
58 .endif
59 #.MAKEFLAGS: -d0
60
61
62 all: .PHONY
63