def _convert_rhs(rule, nt_idx, tokens_to_input_ids):
  """Convert rule to `rhs` argument for CFGRule."""
  rhs = []
  for token in rule.source:
    if token == qcfg_rule.NT_1:
      rhs.append(cfg_rule.CFGSymbol(idx=nt_idx, type=cfg_rule.NON_TERMINAL))
    elif token == qcfg_rule.NT_2:
      rhs.append(cfg_rule.CFGSymbol(idx=nt_idx, type=cfg_rule.NON_TERMINAL))
    else:
      if token not in tokens_to_input_ids:
        # Rule contains tokens not in the input so can be ignored for parsing.
        return None
      else:
        token_id = tokens_to_input_ids[token]
        rhs.append(cfg_rule.CFGSymbol(idx=token_id, type=cfg_rule.TERMINAL))
  return tuple(rhs)
Convert rule to `rhs` argument for CFGRule.
language/compgen/nqg/model/qcfg/qcfg_parser.py