public void TestIndentation()
 {
     var Output = new IndentedStringBuilder();
     Output.Write("{\n");
     Output.Indent(() =>
     {
         Output.Write("Hello World!\n");
         Output.Write("Goodbye World!\n");
     });
     Output.Write("}\n");
     Assert.AreEqual(
         @"{\n" +
         @"    Hello World!\n" +
         @"    Goodbye World!\n" +
         @"}\n",
         AstStringUtils.ToLiteralRaw(Output.ToString())
     );
 }
Example #2
0
 private static void SerializeAsXml(AstNode Node, IndentedStringBuilder Out, bool Spaces)
 {
     var NodeName = Node.GetType().Name;
     Out.Write("<" + NodeName);
     var Parameters = Node.Info;
     if (Parameters != null)
     {
         foreach (var Pair in Parameters)
         {
             Out.Write(String.Format(" {0}=\"{1}\"", Pair.Key, Pair.Value));
         }
     }
     if (Node.Childs.Count() > 0)
     {
         Out.Write(">");
         if (Spaces) Out.WriteNewLine();
         if (Spaces)
         {
             Out.Indent(() =>
             {
                 foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
             });
         }
         else
         {
             foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
         }
         Out.Write("</" + NodeName + ">");
         if (Spaces) Out.WriteNewLine();
     }
     else
     {
         Out.Write(" />");
         if (Spaces) Out.WriteNewLine();
     }
 }
Example #3
0
 public static string SerializeAsXml(AstNode Node, bool Spaces = true)
 {
     var Out = new IndentedStringBuilder();
     SerializeAsXml(Node, Out, Spaces);
     return Out.ToString();
 }