xref: /freebsd/contrib/bmake/unit-tests/varparse-mod.mk (revision d5e0a182cf153f8993a633b93d9220c99a89e760)
1*d5e0a182SSimon J. Gerraty# $NetBSD: varparse-mod.mk,v 1.2 2023/11/19 21:47:52 rillig Exp $
2956e45f6SSimon J. Gerraty
3*d5e0a182SSimon J. Gerraty# Tests for parsing expressions with modifiers.
4956e45f6SSimon J. Gerraty
5956e45f6SSimon J. Gerraty# As of 2020-10-02, the below condition does not result in a parse error.
6956e45f6SSimon J. Gerraty# The condition contains two separate mistakes.  The first mistake is that
7956e45f6SSimon J. Gerraty# the :!cmd! modifier is missing the closing '!'.  The second mistake is that
8956e45f6SSimon J. Gerraty# there is a stray '}' at the end of the whole condition.
9956e45f6SSimon J. Gerraty#
10956e45f6SSimon J. Gerraty# As of 2020-10-02, the actual parse result of this condition is a single
11*d5e0a182SSimon J. Gerraty# expression with 2 modifiers. The first modifier is
12956e45f6SSimon J. Gerraty# ":!echo "\$VAR"} !".  Afterwards, the parser optionally skips a ':' (at the
13956e45f6SSimon J. Gerraty# bottom of ApplyModifiers) and continues with the next modifier, in this case
14956e45f6SSimon J. Gerraty# "= "value"", which is interpreted as a SysV substitution modifier with an
15956e45f6SSimon J. Gerraty# empty left-hand side, thereby appending the string " "value"" to each word
16956e45f6SSimon J. Gerraty# of the expression.
17956e45f6SSimon J. Gerraty#
18956e45f6SSimon J. Gerraty# As of 2020-10-02, some modifiers ensure that they are followed by either a
19956e45f6SSimon J. Gerraty# ':' or the closing brace or parenthesis of the expression.  The modifiers
20956e45f6SSimon J. Gerraty# that don't ensure this are (in order of appearance in ApplyModifier):
21956e45f6SSimon J. Gerraty#	:@var@replacement@
22956e45f6SSimon J. Gerraty#	:_
23956e45f6SSimon J. Gerraty#	:L
24956e45f6SSimon J. Gerraty#	:P
25956e45f6SSimon J. Gerraty#	:!cmd!
26956e45f6SSimon J. Gerraty#	:gmtime=...
27956e45f6SSimon J. Gerraty#	:localtime=...
28956e45f6SSimon J. Gerraty#	:M (because '}' and ')' are treated the same)
29956e45f6SSimon J. Gerraty#	:N (because '}' and ')' are treated the same)
30956e45f6SSimon J. Gerraty#	:S
31956e45f6SSimon J. Gerraty#	:C
32956e45f6SSimon J. Gerraty#	:range=...
33956e45f6SSimon J. Gerraty# On the other hand, these modifiers ensure that they are followed by a
34956e45f6SSimon J. Gerraty# delimiter:
35956e45f6SSimon J. Gerraty#	:D
36956e45f6SSimon J. Gerraty#	:U
37956e45f6SSimon J. Gerraty#	:[...]
38956e45f6SSimon J. Gerraty#	:gmtime (if not followed by '=')
39956e45f6SSimon J. Gerraty#	:hash (if not followed by '=')
40956e45f6SSimon J. Gerraty#	:localtime (if not followed by '=')
41956e45f6SSimon J. Gerraty#	:t
42956e45f6SSimon J. Gerraty#	:q
43956e45f6SSimon J. Gerraty#	:Q
44956e45f6SSimon J. Gerraty#	:T
45956e45f6SSimon J. Gerraty#	:H
46956e45f6SSimon J. Gerraty#	:E
47956e45f6SSimon J. Gerraty#	:R
48956e45f6SSimon J. Gerraty#	:range (if not followed by '=')
49956e45f6SSimon J. Gerraty#	:O
50956e45f6SSimon J. Gerraty#	:u
51956e45f6SSimon J. Gerraty#	:sh
52956e45f6SSimon J. Gerraty# These modifiers don't care since they reach until the closing character
53956e45f6SSimon J. Gerraty# of the expression, which is either ')' or '}':
54956e45f6SSimon J. Gerraty#	::= (as well as the other assignment modifiers)
55956e45f6SSimon J. Gerraty#	:?
56956e45f6SSimon J. Gerraty#
57956e45f6SSimon J. Gerraty.if ${:!echo "\$VAR"} != "value"}
58956e45f6SSimon J. Gerraty.endif
59956e45f6SSimon J. Gerraty
60956e45f6SSimon J. Gerratyall:
61956e45f6SSimon J. Gerraty	@:
62