예제 #1
0
        public override void Print(Output output)
        {
            m_entries.Sort();
            m_listLength = 1;

            if (m_entries.Count == 0)
            {
                output.Print("{}");
            }
            else
            {
                var lineBreak = (m_isList && m_entries.Count > 5) ||
                                (m_isObject && m_entries.Count > 2) ||
                                (!m_isObject);

                if (!lineBreak)
                {
                    foreach (var entry in m_entries)
                    {
                        var value = entry.Value;

                        if (!value.IsBrief)
                        {
                            lineBreak = true;
                            break;
                        }
                    }
                }

                output.Print("{");

                if (lineBreak)
                {
                    output.PrintLine();
                    output.IncreaseIndent();
                }

                PrintEntry(0, output);

                if (!m_entries[0].Value.IsMultiple)
                {
                    for (var i = 1; i < m_entries.Count; i++)
                    {
                        output.Print(",");

                        if (lineBreak)
                        {
                            output.PrintLine();
                        }
                        else
                        {
                            output.Print(" ");
                        }

                        PrintEntry(i, output);

                        if (m_entries[i].Value.IsMultiple)
                        {
                            break;
                        }
                    }
                }

                if (lineBreak)
                {
                    output.PrintLine();
                    output.DecreaseIndent();
                }

                output.Print("}");
            }
        }
예제 #2
0
 public override void Print(Output output)
 {
     output.Print(m_decl.Name);
 }
예제 #3
0
 protected static void PrintUnary(Output output, string op, Expression expression)
 {
     output.Print(op);
     expression.Print(output);
 }
예제 #4
0
 public override void Print(Output output)
 {
     output.Print("-- unhandled compare assign");
 }
예제 #5
0
 public override void PrintTail(Output output)
 {
     output.Print("break");
 }
예제 #6
0
 public override void Print(Output output)
 {
     output.Print("do return end");
 }
예제 #7
0
        public void Print(Output output)
        {
            switch (m_type)
            {
            case CONST_NIL:
                output.Print("nil");
                break;

            case CONST_BOOL:
                output.Print(m_bool ? "true" : "false");
                break;

            case CONST_NUMBER:
                output.Print(m_number.ToString());
                break;

            case CONST_STRING:
            {
                var newLines     = 0;
                var unprinttable = 0;

                foreach (char c in m_string)
                {
                    if (c == '\n')
                    {
                        newLines++;
                    }
                    else if ((c <= 31 && c != '\t' || c >= 127))
                    {
                        unprinttable++;
                    }
                }

                if (unprinttable == 0 && !m_string.Contains("[[") &&
                    (newLines > 1 || newLines == 1 && m_string.IndexOf('\n') != m_string.Length - 1))
                {
                    var pipe       = 0;
                    var pipeString = "]]";

                    while (m_string.IndexOf(pipeString) >= 0)
                    {
                        pipe++;
                        pipeString = "]";

                        var i = pipe;

                        while (i-- > 0)
                        {
                            pipeString += "=";
                        }

                        pipeString += "]";
                    }

                    output.Print("[");

                    while (pipe-- > 0)
                    {
                        output.Print("=");
                    }

                    output.Print("[");

                    var indent = output.IndentationLevel;

                    output.IndentationLevel = 0;

                    output.PrintLine();
                    output.Print(m_string);
                    output.Print(pipeString);

                    output.IndentationLevel = indent;
                }
                else
                {
                    output.Print("\"");

                    var chars = new[] {
                        "\\a",
                        "\\b",
                        "\\t",
                        "\\n",
                        "\\v",
                        "\\f",
                        "\\r",
                    };

                    foreach (char c in m_string)
                    {
                        if (c <= 31 || c >= 127)
                        {
                            //if (c == 7)
                            //    output.Print("\\a");
                            //else if (c == 8)
                            //    output.Print("\\b");
                            //else if (c == 12)
                            //    output.Print("\\f");
                            //else if (c == 10)
                            //    output.Print("\\n");
                            //else if (c == 13)
                            //    output.Print("\\r");
                            //else if (c == 9)
                            //    output.Print("\\t");
                            //else if (c == 11)
                            //    output.Print("\\v");

                            var cx = ((int)c);

                            if (cx >= 7 && cx <= 13)
                            {
                                output.Print(chars[cx - 7]);
                            }
                            else
                            {
                                /*
                                 * var dec = cx.ToString();
                                 * var len = dec.Length;
                                 * output.Print("\\");
                                 * while (len++ < 3)
                                 *  output.Print("0");
                                 * output.Print(dec);
                                 */
                                var Tempchar = (char)cx;
                                output.Print(Tempchar.ToString());
                            }
                        }
                        else if (c == 34)
                        {
                            output.Print("\\\"");
                        }
                        else if (c == 92)
                        {
                            output.Print("\\\\");
                        }
                        else
                        {
                            string s = Convert.ToString(c);
                            output.Print(s);
                        }
                    }

                    output.Print("\"");
                }
            } break;

            default:
                throw new InvalidOperationException();
            }
        }