def _convert_to_rhs(rule, terminals_to_ids, nonterminals_to_ids):
  """Convert rule to `rhs` argument for CFGRule."""
  rhs = []
  for token in rule.rhs.split(" "):
    if token.startswith(NON_TERMINAL_PREFIX):
      symbol_idx = nonterminals_to_ids[token[len(NON_TERMINAL_PREFIX):]]
      rhs.append(cfg_rule.CFGSymbol(idx=symbol_idx, type=cfg_rule.NON_TERMINAL))
    else:
      if token not in terminals_to_ids:
        return None
      symbol_idx = terminals_to_ids[token]
      rhs.append(cfg_rule.CFGSymbol(idx=symbol_idx, type=cfg_rule.TERMINAL))
  rhs = tuple(rhs)
  return rhs
Convert rule to `rhs` argument for CFGRule.
language/compgen/nqg/tasks/spider/sql_parser.py