formatOutputText static method

String formatOutputText(
  1. Map<String, String> rules
)

Prints the results from GrammarPrinter in a readable format.

The space between the rule names and their definition is set to a standard width based on the longest rule name.

Implementation

static String formatOutputText(Map<String, String> rules) {
  final maxWidth = rules.keys
      .reduce((a, b) => a.length > b.length ? a : b)
      .length;

  return rules.entries
      .map((entry) => '${entry.key.padRight(maxWidth)} := ${entry.value}')
      .toList()
      .join('\n');
}