def get_nt_index(nt):
  """Return the index of the NT."""
  if isinstance(nt, NT):
    return nt.index
  elif isinstance(nt, str):
    digits = re.findall(r"\d+", nt)
    assert len(digits) == 1
    return int(digits[0])
  else:
    raise ValueError("Unsupported NT type %s" % type(nt))
Return the index of the NT.
language/compgen/csl/qcfg/qcfg_rule.py