generateAst function

void generateAst(
  1. Root root,
  2. StringSink sink
)

Writes the AST representation of root to sink.

Implementation

void generateAst(Root root, StringSink sink) {
  final Indent indent = Indent(sink);
  final String output = root.toString();
  bool isFirst = true;
  for (final int ch in output.runes) {
    final String chStr = String.fromCharCode(ch);
    if (chStr == '(') {
      if (isFirst) {
        isFirst = false;
      } else {
        indent.inc();
        indent.addln('');
        indent.write('');
      }
    } else if (chStr == ')') {
      indent.dec();
    }
    indent.add(chStr);
  }
  indent.addln('');
}