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