Skip to content

Commit

Permalink
Use the ordering customization in the sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Feb 2, 2024
1 parent 4ae5c09 commit 2521208
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// GreenBase = global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// RedBase = global::Tsu.Trees.RedGreen.Sample.SampleNode
// KindEnum = global::Tsu.Trees.RedGreen.Sample.SampleKind
// CreateVisitors = True
// CreateWalker = True
// CreateRewriter = True
// Root = global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// Kinds:
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = False, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
// Kinds:
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.FunctionCallExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.FunctionCallExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 9)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample (IsList = False, Name = _identifier, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = True, Name = _args, IsOptional = False, PassToBase = False, Order = 2)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.BinaryOperationExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.AdditionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 5)
// Tsu.Trees.RedGreen.Sample.SampleKind.DivisionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 8)
// Tsu.Trees.RedGreen.Sample.SampleKind.MultiplicationExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 7)
// Tsu.Trees.RedGreen.Sample.SampleKind.SubtractionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 6)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _left, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _right, IsOptional = False, PassToBase = False, Order = 2)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.NumericalLiteralExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.NumericalLiteralExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 4)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// double (IsList = False, Name = _value, IsOptional = False, PassToBase = False, Order = 1)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.IdentifierExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 3)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// string (IsList = False, Name = _name, IsOptional = False, PassToBase = False, Order = 1)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.StatementSample
// Kinds:
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = False, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.ExpressionStatement (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 11)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _expression, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = True, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.AssignmentStatement (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 10)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample (IsList = False, Name = _identifier, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _value, IsOptional = False, PassToBase = False, Order = 2)
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = True, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.SemicolonToken (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 2)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ partial class ExpressionStatementSample : global::Tsu.Trees.RedGreen.Sample.Inte
{
internal ExpressionStatementSample(
global::Tsu.Trees.RedGreen.Sample.SampleKind kind,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon,
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon
)
: base(kind, semicolon)
{
Expand All @@ -306,8 +306,8 @@ internal ExpressionStatementSample(
public override global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? GetSlot(int index) =>
index switch
{
0 => this._semicolon,
1 => this._expression,
0 => this._expression,
1 => this._semicolon,
_ => null
};

Expand Down Expand Up @@ -335,18 +335,18 @@ public override TResult Accept<T1, T2, T3, TResult>(global::Tsu.Trees.RedGreen.S
visitor.VisitExpressionStatement(this, arg1, arg2, arg3);

public global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample Update(
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon,
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon
)
{
if (
this._semicolon != semicolon
|| this._expression != expression
this._expression != expression
|| this._semicolon != semicolon
)
{
return global::Tsu.Trees.RedGreen.Sample.Internal.SampleFactory.ExpressionStatement(
semicolon,
expression
expression,
semicolon
);
}

Expand All @@ -357,9 +357,9 @@ partial class AssignmentStatement : global::Tsu.Trees.RedGreen.Sample.Internal.S
{
internal AssignmentStatement(
global::Tsu.Trees.RedGreen.Sample.SampleKind kind,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon,
global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample identifier,
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon
)
: base(kind, semicolon)
{
Expand All @@ -374,9 +374,9 @@ internal AssignmentStatement(
public override global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? GetSlot(int index) =>
index switch
{
0 => this._semicolon,
1 => this._identifier,
2 => this._value,
0 => this._identifier,
1 => this._value,
2 => this._semicolon,
_ => null
};

Expand Down Expand Up @@ -404,21 +404,21 @@ public override TResult Accept<T1, T2, T3, TResult>(global::Tsu.Trees.RedGreen.S
visitor.VisitAssignmentStatement(this, arg1, arg2, arg3);

public global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement Update(
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon,
global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample identifier,
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value
global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value,
global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon
)
{
if (
this._semicolon != semicolon
|| this._identifier != identifier
this._identifier != identifier
|| this._value != value
|| this._semicolon != semicolon
)
{
return global::Tsu.Trees.RedGreen.Sample.Internal.SampleFactory.AssignmentStatement(
semicolon,
identifier,
value
value,
semicolon
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ internal static class SampleFactory
global::Tsu.Trees.RedGreen.Sample.SampleKind.SemicolonToken);
}

public static global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement AssignmentStatement(global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon, global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample identifier, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value)
public static global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement AssignmentStatement(global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample identifier, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample value, global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon)
{
#if DEBUG
if (semicolon == null) throw new global::System.ArgumentNullException(nameof(semicolon));
if (identifier == null) throw new global::System.ArgumentNullException(nameof(identifier));
if (value == null) throw new global::System.ArgumentNullException(nameof(value));
if (semicolon == null) throw new global::System.ArgumentNullException(nameof(semicolon));
#endif // DEBUG

return new global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement(
global::Tsu.Trees.RedGreen.Sample.SampleKind.AssignmentStatement, semicolon, identifier, value);
global::Tsu.Trees.RedGreen.Sample.SampleKind.AssignmentStatement, identifier, value, semicolon);
}

public static global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample ExpressionStatement(global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression)
public static global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample ExpressionStatement(global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample expression, global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample semicolon)
{
#if DEBUG
if (semicolon == null) throw new global::System.ArgumentNullException(nameof(semicolon));
if (expression == null) throw new global::System.ArgumentNullException(nameof(expression));
if (semicolon == null) throw new global::System.ArgumentNullException(nameof(semicolon));
#endif // DEBUG

return new global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample(
global::Tsu.Trees.RedGreen.Sample.SampleKind.ExpressionStatement, semicolon, expression);
global::Tsu.Trees.RedGreen.Sample.SampleKind.ExpressionStatement, expression, semicolon);
}

public static global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample IdentifierExpression(string name)
Expand Down Expand Up @@ -203,9 +203,9 @@ public partial class SampleRewriter : Tsu.Trees.RedGreen.Sample.SampleVisitor<gl
public override global::Tsu.Trees.RedGreen.Sample.SampleNode VisitSemicolonToken(global::Tsu.Trees.RedGreen.Sample.SemicolonTokenSample node) =>
node;
public override global::Tsu.Trees.RedGreen.Sample.SampleNode VisitAssignmentStatement(global::Tsu.Trees.RedGreen.Sample.AssignmentStatement node) =>
node.Update((global::Tsu.Trees.RedGreen.Sample.SemicolonTokenSample?)Visit(node.Semicolon) ?? throw new global::System.InvalidOperationException("Semicolon cannot be null."), (global::Tsu.Trees.RedGreen.Sample.IdentifierExpressionSample?)Visit(node.Identifier) ?? throw new global::System.InvalidOperationException("Identifier cannot be null."), (global::Tsu.Trees.RedGreen.Sample.ExpressionSample?)Visit(node.Value) ?? throw new global::System.InvalidOperationException("Value cannot be null."));
node.Update((global::Tsu.Trees.RedGreen.Sample.IdentifierExpressionSample?)Visit(node.Identifier) ?? throw new global::System.InvalidOperationException("Identifier cannot be null."), (global::Tsu.Trees.RedGreen.Sample.ExpressionSample?)Visit(node.Value) ?? throw new global::System.InvalidOperationException("Value cannot be null."), (global::Tsu.Trees.RedGreen.Sample.SemicolonTokenSample?)Visit(node.Semicolon) ?? throw new global::System.InvalidOperationException("Semicolon cannot be null."));
public override global::Tsu.Trees.RedGreen.Sample.SampleNode VisitExpressionStatement(global::Tsu.Trees.RedGreen.Sample.ExpressionStatementSample node) =>
node.Update((global::Tsu.Trees.RedGreen.Sample.SemicolonTokenSample?)Visit(node.Semicolon) ?? throw new global::System.InvalidOperationException("Semicolon cannot be null."), (global::Tsu.Trees.RedGreen.Sample.ExpressionSample?)Visit(node.Expression) ?? throw new global::System.InvalidOperationException("Expression cannot be null."));
node.Update((global::Tsu.Trees.RedGreen.Sample.ExpressionSample?)Visit(node.Expression) ?? throw new global::System.InvalidOperationException("Expression cannot be null."), (global::Tsu.Trees.RedGreen.Sample.SemicolonTokenSample?)Visit(node.Semicolon) ?? throw new global::System.InvalidOperationException("Semicolon cannot be null."));
public override global::Tsu.Trees.RedGreen.Sample.SampleNode VisitIdentifierExpression(global::Tsu.Trees.RedGreen.Sample.IdentifierExpressionSample node) =>
node.Update(node.Name);
public override global::Tsu.Trees.RedGreen.Sample.SampleNode VisitNumericalLiteralExpression(global::Tsu.Trees.RedGreen.Sample.NumericalLiteralExpressionSample node) =>
Expand Down
Loading

0 comments on commit 2521208

Please sign in to comment.