// ** This class was generated with DemFGen (vers:12/06/2009)

package edu.neu.ccs.demeterf.lexer.classes;

import edu.neu.ccs.demeterf.Fields;
import edu.neu.ccs.demeterf.lib.ident;
import edu.neu.ccs.demeterf.lib.verbatim;
import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.*;
import edu.neu.ccs.demeterf.demfgen.classes.*;
import edu.neu.ccs.demeterf.demfgen.classes.Package;



/** Computes a String representation in CD Syntax, named as a ToString method */
public class PrintToString extends edu.neu.ccs.demeterf.FC{
   /** Static stub method for calling toString */
   public static String PrintToStringM(Object o){
      return new edu.neu.ccs.demeterf.Traversal(new PrintToString(),edu.neu.ccs.demeterf.Control.builtins()).<PrintToString._LT>traverse(o).toString();
   }

   public _LT combine(byte _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(short _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(int _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(long _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(float _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(double _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(char _h_){ return empty.append(new _S("\'"+escape(""+_h_)+"\'")); }
   public _LT combine(boolean _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(String _h_){ return empty.append(new _S("\""+escape(""+_h_)+"\"")); }
   public _LT combine(ident _h_){ return empty.append(new _S(""+_h_)); }
   public _LT combine(verbatim _h_){ return empty.append(new _S(""+_h_)); }

   static _LT empty = new _LT();
   public  static class _LT{
     edu.neu.ccs.demeterf.lib.List<_T> l;
     public _LT(){ l = new edu.neu.ccs.demeterf.lib.Empty<_T>(); }
     public _LT(edu.neu.ccs.demeterf.lib.List<_T> ll){ l = ll; }
     public _LT push(_T t){ return new _LT(l.push(t)); }
     public _LT append(_T t){ return new _LT(l.append(t)); }
     public _LT append(_LT t){ return new _LT(l.append(t.l)); }
     public String toString(){ return l.fold(new _F(),""); }
     public _LT compress(){ return l.isEmpty()?this:compress(new _E(), l); }
     public static _LT compress(_S s, edu.neu.ccs.demeterf.lib.List<_T> r){
        if(r.isEmpty())return (s.isE())?empty:empty.push(s);
          _T top = r.top();
          if(top.isS())return compress(s.append((_S)top), r.pop());
          if(s.isE())return compress(s, r.pop()).push(top);
          return compress(new _E(), r.pop()).push(top).push(s);
     }
   }
   public static class _T{
     public boolean isS(){ return false; }
     public boolean isE(){ return false; }
   }
   public static class _P extends _T{ public static _P p = new _P(); }
   public static class _M extends _T{ public static _M m = new _M(); }
   public static class _N extends _T{ public static _N n = new _N(); }
   public static class _R extends _T{ public static _R r = new _R(); }
   public static class _S extends _T{
     public StringBuffer s;
     public _S(String ss){ s = new StringBuffer(ss); }
     public _S append(_S ss){ s.append(ss.s); return this; }
     public  boolean isS(){ return true; }
   }
   public static class _E extends _S{
     public _E(){ super("");}
     public  boolean isS(){ return true; }
   }
   public static class _F extends edu.neu.ccs.demeterf.lib.List.Fold<_T,String>{
     int idt = 0;
     public  String fold(_T t, String s){
        if(t == _P.p)plus();
        else if(t == _M.m)minus();
        else if(t == _R.r)s += "\r";
        else if(t == _N.n)s += "\n"+indent();
        else s += ((_S)t).s;
        return s;
     }
     void plus(){ idt++; }
     void minus(){ idt--; }
     String indent(){ return indent(idt); }
     static String indent(int i){ return (i <= 0)?"":"   "+indent(i-1); }
   }
   public static String escape(String s){
      char str[] = s.toCharArray();
      StringBuffer ret = new StringBuffer("");
      for(char c:str)ret.append(escape(c));
      return ret.toString();
   }
   public static String escape(char c){
      switch(c){
      case '\n':return "\\n";  case '\t':return "\\t";
      case '\b':return "\\b";  case '\r':return "\\r";
      case '\f':return "\\f";  case '\\':return "\\\\";
      case '\'':return "\\'"; case '\"':return "\\\"";
      default: return ""+c;
      }
   }
   public _LT combine(Package _h_, _LT pkg){
      return empty.append(new _S("package")).append(new _S(" ")).append(pkg).append(new _S(";")).append(_N.n).compress();
   }
   public _LT combine(NoPackage _h_){
      return empty;
   }
   public _LT combine(NEPkgList _h_, _LT id, _LT rest){
      return empty.append(id).append(rest).compress();
   }
   public _LT combine(PkgCons _h_, _LT id, _LT rest){
      return empty.append(new _S(".")).append(id).append(rest).compress();
   }
   public _LT combine(PkgEmpty _h_){
      return empty;
   }
   public _LT combine(LexMain _h_, _LT pkg, _LT lits, _LT ds){
      return empty.append(pkg).append(_N.n).append(new _S("literals")).append(new _S("{")).append(lits).append(new _S("}")).append(_N.n).append(ds).compress();
   }
   public _LT combine(LocDef _h_, _LT id, _LT re){
      return empty.append(new _S("local")).append(new _S(" ")).append(id).append(new _S(" ")).append(new _S("=")).append(new _S(" ")).append(re).append(new _S(";")).compress();
   }
   public _LT combine(TokDef _h_, _LT id, _LT re){
      return empty.append(id).append(new _S(" ")).append(new _S("=")).append(new _S(" ")).append(re).append(new _S(";")).compress();
   }
   public _LT combine(LocRef _h_, _LT id){
      return empty.append(id).compress();
   }
   public _LT combine(StrRE _h_, _LT val){
      return empty.append(val).compress();
   }
   public _LT combine(ChRE _h_, _LT val){
      return empty.append(val).compress();
   }
   public _LT combine(NChRE _h_, _LT v){
      return empty.append(new _S("~")).append(v).compress();
   }
   public _LT combine(GrpRE _h_, _LT gs){
      return empty.append(new _S("[")).append(gs).append(new _S("]")).compress();
   }
   public _LT combine(NGrpRE _h_, _LT gs){
      return empty.append(new _S("~[")).append(gs).append(new _S("]")).compress();
   }
   public _LT combine(GrpRang _h_, _LT s, _LT e){
      return empty.append(s).append(new _S("-")).append(e).compress();
   }
   public _LT combine(GrpChar _h_, _LT ch){
      return empty.append(ch).compress();
   }
   public _LT combine(ConcatRE _h_, _LT res){
      return empty.append(new _S("(concat")).append(new _S(" ")).append(res).append(new _S(")")).compress();
   }
   public _LT combine(OrRE _h_, _LT res){
      return empty.append(new _S("(or")).append(new _S(" ")).append(res).append(new _S(")")).compress();
   }
   public _LT combine(PlusRE _h_, _LT re){
      return empty.append(new _S("(+")).append(new _S(" ")).append(re).append(new _S(")")).compress();
   }
   public _LT combine(StarRE _h_, _LT re){
      return empty.append(new _S("(*")).append(new _S(" ")).append(re).append(new _S(")")).compress();
   }
   public _LT combine(HuhRE _h_, _LT re){
      return empty.append(new _S("(?")).append(new _S(" ")).append(re).append(new _S(")")).compress();
   }
   public _LT combine(NFA _h_, _LT start, _LT fin, _LT trans){
      return empty.append(new _S("nfa:")).append(start).append(fin).append(_P.p).append(_N.n).append(new _S(" ")).append(trans).append(_M.m).append(_N.n).append(new _S("}")).compress();
   }
   public _LT combine(Trans _h_, _LT l, _LT frm, _LT to){
      return empty.append(new _S("{")).append(l).append(new _S(", ")).append(frm).append(new _S(" -> ")).append(to).append(new _S("}")).append(_N.n).compress();
   }
   public _LT combine(State _h_, _LT id){
      return empty.append(new _S("(")).append(id).append(new _S(")")).compress();
   }
   public _LT combine(FinalState _h_, _LT s, _LT tok){
      return empty.append(new _S("final")).append(new _S(" ")).append(s).append(new _S(" => ")).append(tok).compress();
   }
   public _LT combine(Epsilon _h_){
      return empty.append(new _S("epsilon")).compress();
   }
   public _LT combine(ChLbl _h_, _LT v){
      return empty.append(v).compress();
   }
   public _LT combine(NChLbl _h_, _LT v){
      return empty.append(new _S("~")).append(v).compress();
   }
   public _LT combine(GrpLbl _h_, _LT gs){
      return empty.append(new _S("[")).append(gs).append(new _S("]")).compress();
   }
   public _LT combine(NGrpLbl _h_, _LT gs){
      return empty.append(new _S("~[")).append(gs).append(new _S("]")).compress();
   }
   public _LT combine(Mach _h_, _LT sts, _LT rsts, _LT trans){
      return empty.append(new _S("mach:")).append(sts).append(rsts).append(trans).compress();
   }
   public _LT combine(MTrans _h_, _LT state, _LT c){
      return empty.append(state).append(c).compress();
   }
   public _LT combine(RED _h_){
      return empty.append(new _S("red")).compress();
   }
   public _LT combine(BLACK _h_){
      return empty.append(new _S("black")).compress();
   }

   public _LT combine(Map _h_, _LT tree){
      return empty.append(new _S("[")).append(new _S(" ")).append(tree).append(new _S(" ")).append(new _S("]")).compress();
   }
   public _LT combine(RBLeaf _h_){
      return empty;
   }
   public _LT combine(RBNode _h_, _LT color, _LT data, _LT left, _LT right){
      return empty.append(new _S("(node")).append(new _S(" ")).append(color).append(new _S(" ")).append(data).append(new _S(" ")).append(left).append(new _S(" ")).append(right).append(new _S(")")).compress();
   }
   public _LT combine(Entry _h_, _LT key, _LT val){
      return empty.append(new _S("(")).append(key).append(new _S(" ")).append(new _S("->")).append(new _S(" ")).append(val).append(new _S(")")).compress();
   }
   public _LT combine(Set _h_, _LT tree){
      return empty.append(new _S("{")).append(new _S(" ")).append(tree).append(new _S(" ")).append(new _S("}")).compress();
   }
   public _LT combine(Wrap _h_, _LT x){
      return empty.append(x).compress();
   }
   public _LT combine(Empty _h_){
      return empty;
   }
   public _LT combine(Cons _h_, _LT first, _LT rest){
      return empty.append(first).append(new _S(" ")).append(rest).compress();
   }


}


