varmod-range.mk revision 1.9 1 1.9 rillig # $NetBSD: varmod-range.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the :range variable modifier, which generates sequences
4 1.2 rillig # of integers from the given range.
5 1.6 rillig #
6 1.6 rillig # See also:
7 1.6 rillig # modword.mk
8 1.1 rillig
9 1.4 rillig # The :range modifier generates a sequence of integers, one number per
10 1.9 rillig # word of the expression's value.
11 1.4 rillig .if ${a b c:L:range} != "1 2 3"
12 1.4 rillig . error
13 1.4 rillig .endif
14 1.4 rillig
15 1.4 rillig # To preserve spaces in a word, they can be enclosed in quotes, just like
16 1.4 rillig # everywhere else.
17 1.4 rillig .if ${:U first "the second word" third 4 :range} != "1 2 3 4"
18 1.4 rillig . error
19 1.4 rillig .endif
20 1.4 rillig
21 1.4 rillig # The :range modifier takes the number of words from the value of the
22 1.9 rillig # expression. If that expression is undefined, the range is
23 1.4 rillig # undefined as well. This should not come as a surprise.
24 1.4 rillig .if "${:range}" != ""
25 1.4 rillig . error
26 1.4 rillig .endif
27 1.4 rillig
28 1.4 rillig # The :range modifier can be given a parameter, which makes the generated
29 1.9 rillig # range independent from the value or the name of the expression.
30 1.4 rillig #
31 1.4 rillig # XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
32 1.4 rillig # expression into a defined one. This looks like an oversight.
33 1.4 rillig .if "${:range=5}" != ""
34 1.4 rillig . error
35 1.4 rillig .endif
36 1.4 rillig
37 1.5 rillig # Negative ranges don't make sense.
38 1.5 rillig # As of 2020-11-01, they are accepted though, using up all available memory.
39 1.5 rillig #.if "${:range=-1}"
40 1.5 rillig #. error
41 1.5 rillig #.else
42 1.5 rillig #. error
43 1.5 rillig #.endif
44 1.5 rillig
45 1.5 rillig # The :range modifier requires a number as parameter.
46 1.7 rillig #
47 1.7 rillig # Until 2020-11-01, the parser tried to read the 'x' as a number, failed and
48 1.7 rillig # stopped there. It then tried to parse the next modifier at that point,
49 1.7 rillig # which failed with the message "Unknown modifier".
50 1.7 rillig #
51 1.7 rillig # Since 2020-11-01, the parser issues a more precise "Invalid number" error
52 1.7 rillig # instead.
53 1.8 rillig # expect+2: Invalid number "x}Rest" != "Rest"" for ':range' modifier
54 1.8 rillig # expect+1: Malformed conditional ("${:U:range=x}Rest" != "Rest")
55 1.5 rillig .if "${:U:range=x}Rest" != "Rest"
56 1.5 rillig . error
57 1.5 rillig .else
58 1.5 rillig . error
59 1.5 rillig .endif
60 1.5 rillig
61 1.5 rillig # The upper limit of the range must always be given in decimal.
62 1.5 rillig # This parse error stops at the 'x', trying to parse it as a variable
63 1.5 rillig # modifier.
64 1.8 rillig # expect+2: Unknown modifier "x0"
65 1.8 rillig # expect+1: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
66 1.5 rillig .if "${:U:range=0x0}Rest" != "Rest"
67 1.5 rillig . error
68 1.5 rillig .else
69 1.5 rillig . error
70 1.5 rillig .endif
71 1.5 rillig
72 1.5 rillig # As of 2020-11-01, numeric overflow is not detected.
73 1.5 rillig # Since strtoul returns ULONG_MAX in such a case, it is interpreted as a
74 1.5 rillig # very large number, consuming all available memory.
75 1.5 rillig #.if "${:U:range=18446744073709551619}Rest" != "Rest"
76 1.5 rillig #. error
77 1.5 rillig #.else
78 1.5 rillig #. error
79 1.5 rillig #.endif
80 1.5 rillig
81 1.5 rillig # modifier name too short
82 1.8 rillig # expect+2: Unknown modifier "rang"
83 1.8 rillig # expect+1: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
84 1.5 rillig .if "${a b c:L:rang}Rest" != "Rest"
85 1.5 rillig . error
86 1.5 rillig .else
87 1.5 rillig . error
88 1.5 rillig .endif
89 1.5 rillig
90 1.5 rillig # misspelled modifier name
91 1.8 rillig # expect+2: Unknown modifier "rango"
92 1.8 rillig # expect+1: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
93 1.5 rillig .if "${a b c:L:rango}Rest" != "Rest"
94 1.5 rillig . error
95 1.5 rillig .else
96 1.5 rillig . error
97 1.5 rillig .endif
98 1.5 rillig
99 1.5 rillig # modifier name too long
100 1.8 rillig # expect+2: Unknown modifier "ranger"
101 1.8 rillig # expect+1: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
102 1.5 rillig .if "${a b c:L:ranger}Rest" != "Rest"
103 1.5 rillig . error
104 1.5 rillig .else
105 1.5 rillig . error
106 1.5 rillig .endif
107 1.5 rillig
108 1.1 rillig all:
109