Exemple #1
0
        public override void Write(IndentAwareTextWriter writer)
        {
            writer.Write("for ");
            for (var i = 0; i < VariableNames.Count; i++)
            {
                writer.Write(VariableNames[i]);
                if (i < VariableNames.Count - 1)
                {
                    writer.Write(", ");
                }
            }
            writer.Write(" in ");

            for (int i = 0; i < Iterator.Count; i++)
            {
                Iterator[i].Write(writer);
                if (i != Iterator.Count - 1)
                {
                    writer.Write(", ");
                }
            }

            writer.Write(" do");
            writer.IncreaseIndent();
            writer.WriteLine();
            Block.Write(writer, false);
            writer.DecreaseIndent();
            writer.WriteLine();
            writer.Write("end");
        }
Exemple #2
0
        public void Write(IndentAwareTextWriter writer, bool alone)
        {
            if (TopLevel && alone)
            {
                alone = false;
            }

            if (alone)
            {
                writer.Write("do");
                writer.IncreaseIndent();
                writer.WriteLine();
            }
            for (var i = 0; i < Statements.Count; i++)
            {
                var stat = Statements[i];

                stat.Write(writer);
                //if (writer.ForceOneLine && stat.AmbiguousTermination && i != Statements.Count - 1) {
                //    writer.Write(";");
                //}
                if (i < Statements.Count - 1)
                {
                    writer.WriteLine();
                }
            }
            if (alone)
            {
                writer.DecreaseIndent();
                writer.WriteLine();
                writer.Write("end");
            }
        }
Exemple #3
0
 public override void Write(IndentAwareTextWriter writer)
 {
     writer.Write("repeat");
     writer.IncreaseIndent();
     writer.WriteLine();
     Block.Write(writer, false);
     writer.DecreaseIndent();
     writer.WriteLine();
     writer.Write("until ");
     Condition.Write(writer);
 }
Exemple #4
0
 public override void Write(IndentAwareTextWriter writer)
 {
     writer.Write("while ");
     Condition.Write(writer);
     writer.Write(" do");
     writer.IncreaseIndent();
     writer.WriteLine();
     Block.Write(writer, false);
     writer.DecreaseIndent();
     writer.WriteLine();
     writer.Write("end");
 }
Exemple #5
0
        public void Write(IndentAwareTextWriter writer, bool from_named)
        {
            if (!from_named)
            {
                writer.Write("function");
            }
            writer.Write("(");

            var arg_start_idx = 0;

            if (ImplicitSelf && from_named)
            {
                arg_start_idx += 1;
            }
            // Skips the self for method defs

            for (var i = arg_start_idx; i < ArgumentNames.Count; i++)
            {
                var arg = ArgumentNames[i];
                writer.Write(arg);
                if (i < ArgumentNames.Count - 1)
                {
                    writer.Write(", ");
                }
            }
            if (AcceptsVarargs)
            {
                if (ArgumentNames.Count > 0)
                {
                    writer.Write(", ");
                }
                writer.Write("...");
            }
            writer.Write(")");
            if (Block.IsEmpty)
            {
                writer.Write(" ");
            }
            else
            {
                writer.IncreaseIndent();
                writer.WriteLine();
                Block.Write(writer, false);
                writer.DecreaseIndent();
                writer.WriteLine();
            }
            writer.Write("end");
        }
Exemple #6
0
 public override void Write(IndentAwareTextWriter writer)
 {
     writer.Write("::");
     writer.Write(Name);
     writer.Write("::");
     writer.WriteLine();
 }
Exemple #7
0
        public override void Write(IndentAwareTextWriter writer)
        {
            if (Entries.Count == 0)
            {
                writer.Write("{}");
                return;
            }

            if (Entries.Count == 1)
            {
                writer.Write("{ ");
                var ent = Entries[0];
                ent.Write(writer, skip_key: ent.Key is NumberLiteral && ((NumberLiteral)ent.Key).Value == 1 && !ent.ExplicitKey);
                writer.Write(" }");
                return;
            }

            var seq_idx = 1;

            writer.Write("{");
            writer.IncreaseIndent();
            for (var i = 0; i < Entries.Count; i++)
            {
                writer.WriteLine();

                var ent = Entries[i];

                var is_sequential = false;
                if (ent.Key is NumberLiteral && ((NumberLiteral)ent.Key).Value == seq_idx && !ent.ExplicitKey)
                {
                    is_sequential = true;
                    seq_idx      += 1;
                }

                Entries[i].Write(writer, skip_key: is_sequential);
                if (i < Entries.Count - 1)
                {
                    writer.Write(",");
                }
            }
            writer.DecreaseIndent();
            writer.WriteLine();
            writer.Write("}");
        }
Exemple #8
0
 public override void Write(IndentAwareTextWriter writer)
 {
     MainIf.Write(writer);
     for (var i = 0; i < ElseIfs.Count; i++)
     {
         writer.Write("else");
         ElseIfs[i].Write(writer);
     }
     if (Else != null)
     {
         writer.Write("else");
         writer.IncreaseIndent();
         writer.WriteLine();
         Else.Write(writer, false);
         writer.DecreaseIndent();
         writer.WriteLine();
     }
     writer.Write("end");
 }
Exemple #9
0
 public override void Write(IndentAwareTextWriter writer)
 {
     writer.Write("for ");
     writer.Write(VariableName);
     writer.Write(" = ");
     StartPoint.Write(writer);
     writer.Write(", ");
     EndPoint.Write(writer);
     if (Step != null && !(Step is NumberLiteral && ((NumberLiteral)Step).Value == 1))
     {
         writer.Write(", ");
         Step.Write(writer);
     }
     writer.Write(" do");
     writer.IncreaseIndent();
     writer.WriteLine();
     Block.Write(writer, false);
     writer.DecreaseIndent();
     writer.WriteLine();
     writer.Write("end");
 }