Beispiel #1
0
 public virtual void print(Output @out)
 {
     switch(type)
     {
       case 0:
     @out.print("nil");
     break;
       case 1:
     @out.print(@bool ? "true" : "false");
     break;
       case 2:
     @out.print(number.ToString());
     break;
       case 3:
     int newlines = 0;
     int carriageReturns = 0;
     for(int i = 0; i < @string.Length; i++)
     {
       newlines += @string[i] == '\n' ? 1 : 0;
       carriageReturns += @string[i] == '\r' ? 1 : 0;
     }
     if(carriageReturns == 0 && (newlines > 1 || (newlines == 1 && @string.IndexOf('\n') != @string.Length - 1)))
     {
       int pipe = 0;
       string pipeString = "]]";
       while(@string.IndexOf(pipeString) >= 0)
       {
         pipe++;
         pipeString = "]";
         int i = pipe;
         while(i-- > 0)
             pipeString += "=";
         pipeString += "]";
       }
       @out.print("[");
       while(pipe-- > 0)
           @out.print("=");
       @out.print("[");
       int indent = @out.getIndentationLevel();
       @out.setIndentationLevel(0);
       @out.println();
       @out.print(@string);
       @out.print(pipeString);
       @out.setIndentationLevel(indent);
       }
     else
     {
       @out.print("\"");
       for(int i = 0; i < @string.Length; i++)
       {
         char c = @string[i];
         if(c <= 31 || c >= 127)
         {
           if(c == 7)
           {
             @out.print("\\a");
           }
           else if(c == 8)
           {
             @out.print("\\b");
           }
           else if(c == 12)
           {
             @out.print("\\f");
           }
           else if(c == 10)
           {
             @out.print("\\n");
           }
           else if(c == 13)
           {
             @out.print("\\r");
           }
           else if(c == 9)
           {
             @out.print("\\t");
           }
           else if(c == 11)
           {
             @out.print("\\v");
           }
           else
           {
             string dec = Convert.ToString(c);
             int len = dec.Length;
             @out.print("\\");
             while(len++ < 3)
             {
               @out.print("0");
             }
             @out.print(dec);
           }
             }
         else if(c == 34)
         {
           @out.print("\\\"");
         }
         else if(c == 92)
         {
           @out.print("\\\\");
         }
         else
         {
           @out.print(char.ToString(c));
         }
       }
       @out.print("\"");
     }
     break;
       default:
     throw new Exception();
     }
 }
Beispiel #2
0
 private void handleInitialDeclares(Output @out)
 {
     List<Declaration> initdecls = new List<Declaration>(declList.Length);
     for(int i = @params + (vararg & 1); i < declList.Length; i++)
     {
       if(declList[i].begin == 0)
       {
     initdecls.Add(declList[i]);
       }
     }
     if(initdecls.Count > 0)
     {
       @out.print("local ");
       @out.print(initdecls[0].name);
       for(int i = 1; i < initdecls.Count; i++)
       {
     @out.print(", ");
     @out.print(initdecls[i].name);
       }
       @out.println();
     }
 }
Beispiel #3
0
 public virtual void print(Output @out)
 {
     handleInitialDeclares(@out);
     outer.print(@out);
 }
Beispiel #4
0
 public override void print(Output @out)
 {
     @out.print("-- unhandled compare assign");
 }