package commons.script;

import java.util.List;
import basics.testing.Test;
import basics.utl.FormatterUtl;
import basics.utl.SUtl;
import basics.utl.SysUtl;

public class Util
{
public static void printTokenizedLines(TokenizedLines lines)
{
   for(int i = 0; i < lines.size(); i++)
   {
      int lineNo = lines.indexToLineInFile(i);
      List<String> tokens = lines.tokens(i);
      for(int n = 0; n < tokens.size(); n += 2)
         Test.printout(SUtl.sprint("(%) %[%] ", FormatterUtl.padl(String.valueOf(lineNo), "0", 2),
            tokens.get(n), tokens.get(n + 1)));
   }
}

public static void printTree(XNode node)
{
   int depth = 0;
   printT(node, depth);
}

private static void printT(XNode node, int depth)
{
   StringBuilder buffer = new StringBuilder();
   buffer.append(FormatterUtl.padl("", "  ", depth));
   buffer.append(node.toString());
   SysUtl.trace(buffer.toString());
   if(node.straightNodes != null)
      for(XNode p : node.straightNodes)
         printT(p, depth+1);
   if(node.altNodes != null)
      for(XNode p : node.altNodes)
         printT(p, depth+1);
}
}
