27 lines
709 B
C#
27 lines
709 B
C#
|
using System.Text;
|
||
|
using Upsilon.Parser;
|
||
|
|
||
|
namespace Upsilon.Utilities
|
||
|
{
|
||
|
public static class NodeStringFormatter
|
||
|
{
|
||
|
public static string Print(this SyntaxNode token, int depth = 0)
|
||
|
{
|
||
|
var sb = new StringBuilder();
|
||
|
var tabs = depth - 1;
|
||
|
for (var i = 0; i < tabs; i++)
|
||
|
sb.Append("\t");
|
||
|
if (depth > 0)
|
||
|
{
|
||
|
sb.Append("|-- ");
|
||
|
}
|
||
|
sb.Append(token.Kind);
|
||
|
foreach (var syntaxNode in token.ChildNodes())
|
||
|
{
|
||
|
sb.Append("\n");
|
||
|
sb.Append(syntaxNode.Print(depth + 1));
|
||
|
}
|
||
|
return sb.ToString();
|
||
|
}
|
||
|
}
|
||
|
}
|