Skip to content

Commit

Permalink
Migrate walkers to scriban.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Feb 1, 2024
1 parent ae470f5 commit 622b09f
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />

#nullable enable

Expand Down Expand Up @@ -182,34 +182,6 @@ internal partial class SampleVisitor<T1, T2, T3, TResult>
protected virtual TResult? DefaultVisit(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode node, T1 arg1, T2 arg2, T3 arg3) => default;
}

internal abstract class SampleWalker : global::Tsu.Trees.RedGreen.Sample.Internal.SampleVisitor
{
private int _recursionDepth;

public override void Visit(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}

public partial class SampleRewriter : Tsu.Trees.RedGreen.Sample.SampleVisitor<global::Tsu.Trees.RedGreen.Sample.SampleNode>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,6 @@ public partial class SampleVisitor<T1, T2, T3, TResult>
protected virtual TResult? DefaultVisit(global::Tsu.Trees.RedGreen.Sample.SampleNode node, T1 arg1, T2 arg2, T3 arg3) => default;
}

public abstract class SampleWalker : global::Tsu.Trees.RedGreen.Sample.SampleVisitor
{
private int _recursionDepth;

public override void Visit(global::Tsu.Trees.RedGreen.Sample.SampleNode? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit(global::Tsu.Trees.RedGreen.Sample.SampleNode node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}


public partial class SampleRewriter : Tsu.Trees.RedGreen.Sample.SampleVisitor<global::Tsu.Trees.RedGreen.Sample.SampleNode>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated />

#nullable enable

namespace Tsu.Trees.RedGreen.Sample.Internal
{
internal abstract class SampleWalker : global::Tsu.Trees.RedGreen.Sample.Internal.SampleVisitor
{
private int _recursionDepth;

public override void Visit(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated />

#nullable enable

namespace Tsu.Trees.RedGreen.Sample
{
public abstract class SampleWalker : global::Tsu.Trees.RedGreen.Sample.SampleVisitor
{
private int _recursionDepth;

public override void Visit(global::Tsu.Trees.RedGreen.Sample.SampleNode? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit(global::Tsu.Trees.RedGreen.Sample.SampleNode node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}
}
35 changes: 35 additions & 0 deletions Tsu.Trees.RedGreen/src/Templates/Internal/GreenWalker.sbn-cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated />

#nullable enable

namespace {{ green_base.namespace_no_global }}
{
{{ green_base.accessibility }} abstract class {{ suffix }}Walker : {{ green_base.namespace }}.{{ suffix }}Visitor
{
private int _recursionDepth;

public override void Visit({{ green_base.csharp_no_nullable }}? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit({{ green_base.csharp_no_nullable }} node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}
}
35 changes: 35 additions & 0 deletions Tsu.Trees.RedGreen/src/Templates/RedWalker.sbn-cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated />

#nullable enable

namespace {{ red_base.namespace_no_global }}
{
{{ red_base.accessibility }} abstract class {{ suffix }}Walker : {{ red_base.namespace }}.{{ suffix }}Visitor
{
private int _recursionDepth;

public override void Visit({{ red_base.csharp_no_nullable }}? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}

node.Accept(this);

_recursionDepth--;
}
}

protected override void DefaultVisit({{ red_base.csharp_no_nullable }} node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}
}
2 changes: 2 additions & 0 deletions Tsu.Trees.RedGreen/src/Tsu.Trees.RedGreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<ItemGroup>
<EmbeddedResource Include="Templates/Internal/GreenRoot.sbn-cs" Visible="true" LogicalName="Internal/GreenRoot.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenNodes.sbn-cs" Visible="true" LogicalName="Internal/GreenNodes.sbn-cs" />
<EmbeddedResource Include="Templates/Internal/GreenWalker.sbn-cs" Visible="true" LogicalName="Internal/GreenWalker.sbn-cs" />
<EmbeddedResource Include="Templates/RedWalker.sbn-cs" Visible="true" LogicalName="RedWalker.sbn-cs" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 0 additions & 32 deletions Tsu.Trees.RedGreen/src/VisitorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,39 +199,7 @@ public static void WriteWalker(this IndentedTextWriter writer, Tree tree, INamed
if (!tree.CreateVisitors)
{
writer.WriteVisitor(tree, baseType, 0);
writer.WriteLineNoTabs("");
}

writer.WriteLines($$"""
{{baseType.DeclaredAccessibility.ToCSharpString()}} abstract class {{tree.Suffix}}Walker : {{baseType.ContainingNamespace.ToCSharpString(false)}}.{{tree.Suffix}}Visitor
{
private int _recursionDepth;
public override void Visit({{baseType.ToCSharpString()}}? node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > 30)
{
global::System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack();
}
node.Accept(this);
_recursionDepth--;
}
}
protected override void DefaultVisit({{baseType.ToCSharpString()}} node)
{
foreach (var child in node.ChildNodes())
{
Visit(child);
}
}
}
""");
}

public static void WriteRewriter(this IndentedTextWriter writer, Tree tree, INamedTypeSymbol baseType)
Expand Down

0 comments on commit 622b09f

Please sign in to comment.