package com.mikesamuel.cil.ast;

import java.io.PrintStream;

import com.google.common.annotations.VisibleForTesting;

@SuppressWarnings("javadoc")
@VisibleForTesting
public class Debug {

  public static void dumpEvents(Iterable<? extends MatchEvent> events) {
    dumpEvents(events, System.err);
  }

  public static void dumpEvents(
      Iterable<? extends MatchEvent> events, PrintStream err) {
    StringBuilder sb = new StringBuilder(". ");
    for (MatchEvent e : events) {
      if (e instanceof MatchEvent.Pop) {
        if (sb.length() != 0) {
          sb.setLength(sb.length() - 2);
        }
      }
      int len = sb.length();
      err.println(sb.append(e));
      sb.setLength(len);
      if (e instanceof MatchEvent.Push) {
        sb.append(". ");
      }
    }
  }
}

@@ -270,16 +270,20 @@
 pEvents(
+%22%22, 
 events, 
@@ -295,16 +295,16 @@
 m.err);%0A
-
   %7D%0A%0A  p
@@ -338,16 +338,31 @@
 s(%0A     
+ String indent,
  Iterabl
@@ -453,21 +453,76 @@
 Builder(
-%22. %22)
+);%0A    sb.append(indent).append(%22. %22);%0A    int pushDepth = 0
 ;%0A    fo
@@ -606,27 +606,48 @@
 if (
-sb.length() != 0) %7B
+pushDepth != 0) %7B%0A          --pushDepth;
 %0A   
@@ -789,16 +789,16 @@
 h(len);%0A
-
       if
@@ -827,24 +827,45 @@
 ent.Push) %7B%0A
+        ++pushDepth;%0A
         sb.a

allow indenting debug output