parse-var.mk revision 1.3 1 1.3 rillig # $NetBSD: parse-var.mk,v 1.3 2022/08/08 18:23:30 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.2 rillig
17 1.3 rillig # Before var.c 1.1028 from 2022-08-08, the exact way of parsing an expression
18 1.3 rillig # depended on whether the expression was actually evaluated or merely parsed.
19 1.2 rillig #
20 1.3 rillig # If it was evaluated, nested expressions were parsed correctly, parsing each
21 1.3 rillig # modifier according to its exact definition (see varmod.mk).
22 1.2 rillig #
23 1.3 rillig # If the expression was merely parsed but not evaluated (for example, because
24 1.3 rillig # its value would not influence the outcome of the condition, or during the
25 1.3 rillig # first pass of the ':@var@body@' modifier), and the expression contained a
26 1.3 rillig # modifier, and that modifier contained a nested expression, the nested
27 1.3 rillig # expression was not parsed correctly. Instead, make only counted the opening
28 1.3 rillig # and closing delimiters, which failed for nested modifiers with unbalanced
29 1.3 rillig # braces.
30 1.3 rillig #
31 1.3 rillig # This naive brace counting was implemented in ParseModifierPartDollar. As of
32 1.3 rillig # var.c 1., there are still several other places that merely count braces
33 1.3 rillig # instead of properly parsing subexpressions.
34 1.2 rillig
35 1.2 rillig #.MAKEFLAGS: -dcpv
36 1.2 rillig # Keep these braces outside the conditions below, to keep them simple to
37 1.2 rillig # understand. If the BRACE_PAIR had been replaced with ':U{}', the '}' would
38 1.2 rillig # have to be escaped, but not the '{'. This asymmetry would have made the
39 1.2 rillig # example even more complicated to understand.
40 1.2 rillig BRACE_PAIR= {}
41 1.2 rillig # In this test word, the '{{}' in the middle will be replaced.
42 1.2 rillig BRACE_GROUP= {{{{}}}}
43 1.2 rillig
44 1.2 rillig # The inner ':S' modifier turns the word '{}' into '{{}'.
45 1.2 rillig # The outer ':S' modifier then replaces '{{}' with '<lbraces>'.
46 1.2 rillig # In the first case, the outer expression is relevant and is parsed correctly.
47 1.2 rillig .if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
48 1.2 rillig .endif
49 1.3 rillig # In the second case, the outer expression was irrelevant. In this case, in
50 1.3 rillig # the parts of the outer ':S' modifier, make only counted the braces, and since
51 1.3 rillig # the inner expression '${BRACE_PAIR:...}' contains more '{' than '}', parsing
52 1.3 rillig # failed with the error message 'Unfinished modifier for "BRACE_GROUP"'. Fixed
53 1.3 rillig # in var.c 1.1028 from 2022-08-08.
54 1.2 rillig .if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
55 1.2 rillig .endif
56 1.2 rillig #.MAKEFLAGS: -d0
57 1.2 rillig
58 1.2 rillig
59 1.2 rillig all: .PHONY
60