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