initial commit
This commit is contained in:
27
Upsilon/Utilities/NodeStringFormatter.cs
Normal file
27
Upsilon/Utilities/NodeStringFormatter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user