Adds Tables

This commit is contained in:
2018-11-17 19:13:05 +01:00
parent 4414534866
commit 6a396d6368
10 changed files with 210 additions and 22 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Upsilon;
using Upsilon.Evaluator;
@@ -46,7 +48,8 @@ namespace Ycicle
if (evaluate == null)
continue;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(evaluate);
Console.WriteLine(ParseEvaluated(evaluate));
Console.ResetColor();
}
}
@@ -68,5 +71,34 @@ namespace Ycicle
Console.Write(message.LineAfterError());
Console.WriteLine();
}
private static string ParseEvaluated(object o, int jumps = 0)
{
var sb = new StringBuilder();
if (o is Dictionary<string, object> dic)
{
for (var i = 0; i < jumps; i++) sb.Append(" ");
sb.Append("{\n");
foreach (var (key, value) in dic)
{
for (var i = 0; i < jumps; i++) sb.Append(" ");
sb.Append(" {");
sb.Append("\"");
sb.Append(key);
sb.Append("\": ");
sb.Append(ParseEvaluated(value, jumps + 1));
sb.Append(" }");
sb.Append(",\n");
}
for (var i = 0; i < jumps; i++) sb.Append(" ");
sb.Append("}\n");
}
else
{
sb.Append(o.ToString());
}
return sb.ToString();
}
}
}