def _format_token_rules(token_rules):
  """Formats a list of (pattern, symbol) pairs as a table."""
  pattern_width = max([len(rule[0]) for rule in token_rules])
  pattern_width += 2  # For the `` characters.
  result = ["{pat_header:{width}} | Symbol\n"
            "{empty:-<{width}} | {empty:-<30}\n".format(pat_header="Pattern",
                                                        width=pattern_width,
                                                        empty="")]
  for rule in token_rules:
    if rule[1]:
      symbol_name = "`" + rule[1] + "`"
    else:
      symbol_name = "*no symbol emitted*"
    result.append(
        "{pattern:{width}} | {symbol}\n".format(pattern="`" + rule[0] + "`",
                                                width=pattern_width,
                                                symbol=symbol_name))
  return "".join(result)