parse-var.mk revision 1.2 1 1.2 rillig # $NetBSD: parse-var.mk,v 1.2 2022/08/06 21:26:05 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.2 rillig # As of var.c 1.1027 from 2022-08-05, the exact way of parsing an expression
18 1.2 rillig # depends on whether the expression is actually evaluated or merely parsed.
19 1.2 rillig #
20 1.2 rillig # If it is evaluated, nested expressions are parsed correctly, parsing each
21 1.2 rillig # modifier according to its exact definition. If the expression is merely
22 1.2 rillig # parsed but not evaluated (because its value would not influence the outcome
23 1.2 rillig # of the condition), and the expression contains a modifier, and that modifier
24 1.2 rillig # contains a nested expression, the nested expression is not parsed
25 1.2 rillig # correctly. Instead, make only counts the opening and closing delimiters,
26 1.2 rillig # which fails for nested modifiers with unbalanced braces.
27 1.2 rillig #
28 1.2 rillig # See ParseModifierPartDollar.
29 1.2 rillig
30 1.2 rillig #.MAKEFLAGS: -dcpv
31 1.2 rillig # Keep these braces outside the conditions below, to keep them simple to
32 1.2 rillig # understand. If the BRACE_PAIR had been replaced with ':U{}', the '}' would
33 1.2 rillig # have to be escaped, but not the '{'. This asymmetry would have made the
34 1.2 rillig # example even more complicated to understand.
35 1.2 rillig BRACE_PAIR= {}
36 1.2 rillig # In this test word, the '{{}' in the middle will be replaced.
37 1.2 rillig BRACE_GROUP= {{{{}}}}
38 1.2 rillig
39 1.2 rillig # The inner ':S' modifier turns the word '{}' into '{{}'.
40 1.2 rillig # The outer ':S' modifier then replaces '{{}' with '<lbraces>'.
41 1.2 rillig # In the first case, the outer expression is relevant and is parsed correctly.
42 1.2 rillig .if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
43 1.2 rillig .endif
44 1.2 rillig # In the second case, the outer expression is irrelevant. In this case, in
45 1.2 rillig # the parts of the outer ':S' modifier, make only counts the braces, and since
46 1.2 rillig # the inner expression '${:U...}' contains more '{' than '}', parsing fails.
47 1.2 rillig .if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
48 1.2 rillig .endif
49 1.2 rillig #.MAKEFLAGS: -d0
50 1.2 rillig
51 1.2 rillig
52 1.2 rillig all: .PHONY
53