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