def apply_target(rule, substitutions):
  """Return target string with non-terminals replaced with substitutions."""
  if rule.arity != len(substitutions):
    raise ValueError("Rule (%s) arity does not match substitutions: %s" %
                     (rule, substitutions))
  output = []
  for token in rule.target:
    if is_nt(token):
      index = get_nt_index(token)
      output.append(substitutions[index - 1])
    else:
      output.append(token)
  return " ".join(output)
Return target string with non-terminals replaced with substitutions.
language/compgen/csl/qcfg/qcfg_rule.py