package org.forge.text.syntax.encoder;

import java.io.OutputStream;

import org.forge.text.syntax.Encoder;
import org.forge.text.syntax.Theme;
import org.forge.text.syntax.TokenType;

public class DebugEncoder extends Encoder.AbstractEncoder implements Encoder {

   public DebugEncoder(OutputStream out, Theme theme) {
      super(out, theme);
   }

   @Override
   public void textToken(String text, TokenType type) {
      if(type == TokenType.space) {
         write(text);
      }
      else {
         String output = text;
         if(output.indexOf("\\") != -1) {
            output = output.replaceAll("\\\\", "\\\\\\\\");
         }
         if(output.indexOf(")") != -1) {
            output = output.replaceAll("\\)", "\\\\)");
         }
         write(type + "(" + output + ")");
      }
   }

   @Override
   public void beginGroup(TokenType type) {
      writeln(type + "<");
   }

   @Override
   public void endGroup(TokenType type) {
      writeln(">");
   }

   @Override
   public void beginLine(TokenType type) {
      writeln(type + "[");
   }

   @Override
   public void endLine(TokenType type) {
      writeln("]");
   }
}

@@ -760,20 +760,33 @@
   write(
+fixTokeName(
 type
+)
  + %22(%22 +
@@ -879,31 +879,42 @@
 %0A      write
-ln
+(fixTokeName
 (type
+)
  + %22%3C%22);%0A   
@@ -982,18 +982,16 @@
    write
-ln
 (%22%3E%22);%0A 
@@ -1066,15 +1066,26 @@
 rite
-ln
+(fixTokeName
 (type
+)
  + %22
@@ -1164,15 +1164,209 @@
 rite
-ln(%22%5D
+(%22%5D%22);%0A   %7D%0A%0A   public String fixTokeName(TokenType type) %7B%0A      String name = type.name();%0A      if(name.endsWith(%22_
 %22)
+) %7B%0A         name = name.substring(0, name.length()-1);%0A      %7D%0A      return name
 ;%0A  

Align Debug output with Coderay to verify test suite