docs: def compile_when_to_only_if(expression):
      '''
      when is a shorthand for writing only_if conditionals.  It requires less quoting
      magic.  only_if is retained for backwards compatibility.
      '''
  
      # when: set $variable
      # when: unset $variable
      # when: failed $json_result
      # when: changed $json_result
      # when: int $x >= $z and $y < 3
      # when: int $x in $alist
      # when: float $x > 2 and $y <= $z
      # when: str $x != $y
  
      if type(expression) not in [ str, unicode ]:
          raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
      tokens = expression.split()
      if len(tokens) < 2:
          raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
  
      # when_set / when_unset
      if tokens[0] in [ 'set', 'unset' ]:
          tcopy = tokens[1:]
          for (i,t) in enumerate(tokens[1:]):
              if t.find("$") != -1:
                  tcopy[i] = "is_%s('''%s''')" % (tokens[0], t)
              else:
                  tcopy[i] = t
          return " ".join(tcopy)
  
  
  
      # when_failed / when_changed
      elif tokens[0] in [ 'failed', 'changed' ]:
          tcopy = tokens[1:]
          for (i,t) in enumerate(tokens[1:]):
              if t.find("$") != -1:
                  tcopy[i] = "is_%s(%s)" % (tokens[0], t)
              else:
                  tcopy[i] = t
          return " ".join(tcopy)
  
  
  
      # when_integer / when_float / when_string
      elif tokens[0] in [ 'integer', 'float', 'string' ]:
          cast = None
          if tokens[0] == 'integer':
              cast = 'int'
          elif tokens[0] == 'string':
              cast = 'str'
          elif tokens[0] == 'float':
              cast = 'float'
          tcopy = tokens[1:]
          for (i,t) in enumerate(tokens[1:]):
              if t.find("$") != -1:
                  # final variable substitution will happen in Runner code
                  tcopy[i] = "%s('''%s''')" % (cast, t)
              else:
                  tcopy[i] = t
          return " ".join(tcopy)
  
      # when_boolean
      elif tokens[0] in [ 'bool', 'boolean' ]:
          tcopy = tokens[1:]
          for (i, t) in enumerate(tcopy):
              if t.find("$") != -1:
                  tcopy[i] = "(is_set('''%s''') and '''%s'''.lower() not in ('false', 'no', 'n', 'none', '0', ''))" % (t, t)
          return " ".join(tcopy)
  
      else:
          raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)