diff --git a/src/GDShrapt.Reader.Tests/BuildingTests.cs b/src/GDShrapt.Reader.Tests/BuildingTests.cs
index 0042c36..8fb50d3 100644
--- a/src/GDShrapt.Reader.Tests/BuildingTests.cs
+++ b/src/GDShrapt.Reader.Tests/BuildingTests.cs
@@ -73,5 +73,68 @@ public void CustomStyleTest()
AssertHelper.CompareCodeStrings(codeToCompare, code);
}
+
+ [TestMethod]
+ public void CustomStyleTest2()
+ {
+ var declaration = GD.Declaration.Class(
+ GD.List.Atributes(
+ GD.Atribute.Tool(),
+ GD.Syntax.NewLine,
+ GD.Atribute.ClassName("Generated"),
+ GD.Syntax.NewLine,
+ GD.Atribute.Extends("Node2D")),
+
+ GD.Syntax.NewLine,
+ GD.Syntax.NewLine,
+
+ GD.Declaration.Variable(
+ GD.Keyword.Const,
+ GD.Syntax.OneSpace,
+ GD.Syntax.Identifier("my_constant"),
+ GD.Syntax.OneSpace,
+ GD.Syntax.Assign,
+ GD.Syntax.OneSpace,
+ GD.Syntax.String("Hello World")),
+
+ GD.Syntax.NewLine,
+ GD.Syntax.NewLine,
+
+ GD.Declaration.Variable(
+ GD.Keyword.Onready,
+ GD.Syntax.OneSpace,
+ GD.Keyword.Var,
+ GD.Syntax.OneSpace,
+ GD.Syntax.Identifier("parameter"),
+ GD.Syntax.OneSpace,
+ GD.Syntax.Assign,
+ GD.Syntax.OneSpace,
+ GD.Expression.True()),
+
+ GD.Syntax.NewLine,
+ GD.Syntax.NewLine,
+
+ GD.Declaration.Method(
+ GD.Keyword.Func,
+ GD.Syntax.OneSpace,
+ GD.Syntax.Identifier("_start"),
+ GD.Syntax.OpenBracket,
+ GD.Syntax.CloseBracket,
+ GD.Syntax.Colon,
+
+ GD.Syntax.NewLine,
+ GD.Syntax.Intendation(1),
+ GD.Expression.Call(
+ GD.Expression.Identifier("print"),
+ GD.Syntax.OpenBracket,
+ GD.List.Expressions(GD.Expression.String("Hello world")),
+ GD.Syntax.CloseBracket)));
+
+ var code = declaration.ToString();
+
+ var codeToCompare = "tool\nclass_name Generated\nextends Node2D\n\nconst my_constant = \"Hello World\"\n\nonready var parameter = true\n\nfunc _start():\n\tprint(\"Hello world\")";
+
+ AssertHelper.CompareCodeStrings(codeToCompare, code);
+ }
}
}
diff --git a/src/GDShrapt.Reader/Basics/GDNode.cs b/src/GDShrapt.Reader/Basics/GDNode.cs
index 0f4f2e7..be1e60d 100644
--- a/src/GDShrapt.Reader/Basics/GDNode.cs
+++ b/src/GDShrapt.Reader/Basics/GDNode.cs
@@ -14,6 +14,15 @@ public abstract class GDNode : GDSyntaxToken,
{
public abstract GDTokensForm Form { get; }
+ ///
+ /// Sets new tokens for the node's form. Tokens may be null
+ ///
+ public GDSyntaxToken[] FormTokensSetter
+ {
+ set => Form.SetFormUnsafe(value);
+ }
+
+
public IEnumerable Tokens => Form.Direct();
public IEnumerable TokensReversed => Form.Reversed();
public IEnumerable Nodes => Tokens.OfType();
diff --git a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_DECLARATIONS.cs b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_DECLARATIONS.cs
index 8cbcddf..6778020 100644
--- a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_DECLARATIONS.cs
+++ b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_DECLARATIONS.cs
@@ -18,6 +18,13 @@ public static T AddClassNameAtribute(this T receiver, string name)
return receiver;
}
+ public static T AddClassNameAtribute(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Atribute.ClassName(unsafeTokens));
+ return receiver;
+ }
+
public static T AddExtendsAtribute(this T receiver, string baseTypeName)
where T : ITokenReceiver
{
@@ -25,6 +32,13 @@ public static T AddExtendsAtribute(this T receiver, string baseTypeName)
return receiver;
}
+ public static T AddExtendsAtribute(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Atribute.Extends(unsafeTokens));
+ return receiver;
+ }
+
public static T AddExtendsWithPathAtribute(this T receiver, string path)
where T : ITokenReceiver
{
@@ -39,6 +53,13 @@ public static T AddVariable(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Declaration.Variable(unsafeTokens));
+ return receiver;
+ }
+
public static T AddVariable(this T receiver, string name)
where T : ITokenReceiver
{
@@ -142,6 +163,13 @@ public static T AddMethod(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Declaration.Method(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMethod(this T receiver, string name, params GDStatement[] statements)
where T : ITokenReceiver
{
diff --git a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_EXPRESSIONS.cs b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_EXPRESSIONS.cs
index 8cf7071..e5b3d4c 100644
--- a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_EXPRESSIONS.cs
+++ b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_EXPRESSIONS.cs
@@ -53,6 +53,13 @@ public static T AddIfExpression(this T receiver, GDExpression condition, GDEx
return receiver;
}
+ public static T AddIfExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.If(unsafeTokens));
+ return receiver;
+ }
+
public static T AddIfExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -67,6 +74,13 @@ public static T AddArrayExpression(this T receiver, params GDExpression[] exp
return receiver;
}
+ public static T AddArrayExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Array(unsafeTokens));
+ return receiver;
+ }
+
public static T AddArrayExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -81,6 +95,13 @@ public static T AddDictionaryExpression(this T receiver, params GDDictionaryK
return receiver;
}
+ public static T AddDictionaryExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Dictionary(unsafeTokens));
+ return receiver;
+ }
+
public static T AddDictionaryExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -109,6 +130,13 @@ public static T AddCallExpression(this T receiver, GDExpression caller, param
return receiver;
}
+ public static T AddCallExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Call(unsafeTokens));
+ return receiver;
+ }
+
public static T AddCallExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -123,6 +151,13 @@ public static T AddBracketExpression(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Bracket(unsafeTokens));
+ return receiver;
+ }
+
public static T AddBracketExpression(this T receiver, GDExpression inner)
where T : ITokenReceiver
{
@@ -137,6 +172,13 @@ public static T AddMemberOperatorExpression(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Member(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMemberOperatorExpression(this T receiver, GDExpression caller, string identifier)
where T : ITokenReceiver
{
@@ -158,6 +200,13 @@ public static T AddIndexerExpression(this T receiver, GDExpression caller, GD
return receiver;
}
+ public static T AddIndexerExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Indexer(unsafeTokens));
+ return receiver;
+ }
+
public static T AddIndexerExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -200,6 +249,13 @@ public static T AddReturnExpression(this T receiver)
return receiver;
}
+ public static T AddReturnExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Return(unsafeTokens));
+ return receiver;
+ }
+
public static T AddReturnExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -221,6 +277,13 @@ public static T AddDualOperatorExpression(this T receiver, GDExpression left,
return receiver;
}
+ public static T AddDualOperatorExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.DualOperator(unsafeTokens));
+ return receiver;
+ }
+
public static T AddDualOperatorExpression(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -235,7 +298,14 @@ public static T AddSingleOperatorExpression(this T receiver, Func(this T receiver, GDSingleOperator @operator, GDExpression operand)
+ public static T AddSingleOperatorExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.SingleOperator(unsafeTokens));
+ return receiver;
+ }
+
+ public static T AddSingleOperatorExpression(this T receiver, GDSingleOperator @operator, GDExpression operand)
where T : ITokenReceiver
{
receiver.HandleReceivedToken(GD.Expression.SingleOperator(@operator, operand));
@@ -249,6 +319,13 @@ public static T AddGetNodeExpression(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.GetNode(unsafeTokens));
+ return receiver;
+ }
+
public static T AddGetNodeExpression(this T receiver, GDPathList pathList)
where T : ITokenReceiver
{
@@ -269,6 +346,12 @@ public static T AddNodePathExpression(this T receiver, string path)
receiver.HandleReceivedToken(GD.Expression.NodePath(path));
return receiver;
}
+ public static T AddNodePathExpression(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.NodePath(unsafeTokens));
+ return receiver;
+ }
public static T AddNodePathExpression(this T receiver, Func setup)
where T : ITokenReceiver
@@ -284,6 +367,13 @@ public static T AddMatchCaseVariableExpression(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.MatchCaseVariable(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMatchCaseVariableExpression(this T receiver, string identifier)
where T : ITokenReceiver
{
@@ -298,6 +388,13 @@ public static T AddYieldExpression(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Yield(unsafeTokens));
+ return receiver;
+ }
+
public static T AddYieldExpression(this T receiver, params GDExpression[] parameters)
where T : ITokenReceiver
{
diff --git a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_LIST.cs b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_LIST.cs
index 893a976..f7e8624 100644
--- a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_LIST.cs
+++ b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_LIST.cs
@@ -11,6 +11,13 @@ public static T AddStatements(this T receiver, params GDStatement[] statement
return receiver;
}
+ public static T AddStatements(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Statements(unsafeTokens));
+ return receiver;
+ }
+
public static T AddStatements(this T receiver, GDStatementsList statementsList)
where T : ITokenReceiver
{
@@ -46,6 +53,13 @@ public static T AddAtributes(this T receiver, params GDClassAtribute[] atribu
return receiver;
}
+ public static T AddAtributes(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Atributes(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMembers(this T receiver, params GDClassMember[] members)
where T : ITokenReceiver
{
@@ -53,6 +67,13 @@ public static T AddMembers(this T receiver, params GDClassMember[] members)
return receiver;
}
+ public static T AddMembers(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Members(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMembers(this T receiver, GDClassMembersList list)
where T : ITokenReceiver
{
@@ -74,6 +95,13 @@ public static T AddExpressions(this T receiver, params GDExpression[] express
return receiver;
}
+ public static T AddExpressions(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Expressions(unsafeTokens));
+ return receiver;
+ }
+
public static T AddExpressions(this T receiver, GDClassMembersList list)
where T : ITokenReceiver
{
@@ -95,6 +123,13 @@ public static T AddKeyValues(this T receiver, params GDDictionaryKeyValueDecl
return receiver;
}
+ public static T AddKeyValues(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.KeyValues(unsafeTokens));
+ return receiver;
+ }
+
public static T AddKeyValues(this T receiver, GDDictionaryKeyValueDeclarationList list)
where T : ITokenReceiver
{
@@ -116,6 +151,13 @@ public static T AddParameters(this T receiver, params GDParameterDeclaration[
return receiver;
}
+ public static T AddParameters(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Parameters(unsafeTokens));
+ return receiver;
+ }
+
public static T AddParameters(this T receiver, GDParametersList list)
where T : ITokenReceiver
{
@@ -137,6 +179,13 @@ public static T AddElifBranches(this T receiver, params GDElifBranch[] branch
return receiver;
}
+ public static T AddElifBranches(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.ElifBranches(unsafeTokens));
+ return receiver;
+ }
+
public static T AddElifBranches(this T receiver, GDElifBranchesList list)
where T : ITokenReceiver
{
@@ -158,6 +207,13 @@ public static T AddEnumValues(this T receiver, params GDEnumValueDeclaration[
return receiver;
}
+ public static T AddEnumValues(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.EnumValues(unsafeTokens));
+ return receiver;
+ }
+
public static T AddEnumValues(this T receiver, GDEnumValuesList list)
where T : ITokenReceiver
{
@@ -179,6 +235,13 @@ public static T AddPath(this T receiver, params GDIdentifier[] names)
return receiver;
}
+ public static T AddPath(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.Path(unsafeTokens));
+ return receiver;
+ }
+
public static T AddPath(this T receiver, GDPathList list)
where T : ITokenReceiver
{
@@ -200,6 +263,13 @@ public static T AddExportParameters(this T receiver, params GDDataToken[] tok
return receiver;
}
+ public static T AddExportParameters(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.List.ExportParameters(unsafeTokens));
+ return receiver;
+ }
+
public static T AddExportParameters(this T receiver, GDExportParametersList list)
where T : ITokenReceiver
{
diff --git a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_STATEMENTS.cs b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_STATEMENTS.cs
index 296c72e..f3a11bf 100644
--- a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_STATEMENTS.cs
+++ b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_STATEMENTS.cs
@@ -11,6 +11,13 @@ public static T AddFor(this T receiver, Func
return receiver;
}
+ public static T AddFor(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Statement.For(unsafeTokens));
+ return receiver;
+ }
+
public static T AddFor(this T receiver, GDIdentifier variable, GDExpression collection, GDExpression body)
where T : ITokenReceiver
{
@@ -39,6 +46,13 @@ public static T AddIf(this T receiver, Func set
return receiver;
}
+ public static T AddIf(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Statement.If(unsafeTokens));
+ return receiver;
+ }
+
public static T AddIf(this T receiver, GDIfBranch ifBranch)
where T : ITokenReceiver
{
@@ -81,6 +95,13 @@ public static T AddYield(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Yield(unsafeTokens));
+ return receiver;
+ }
+
public static T AddYield(this T receiver, params GDExpression[] parameters)
where T : ITokenReceiver
{
@@ -109,6 +130,13 @@ public static T AddReturn(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Return(unsafeTokens));
+ return receiver;
+ }
+
public static T AddReturn(this T receiver, GDExpression result)
where T : ITokenReceiver
{
@@ -123,6 +151,13 @@ public static T AddDualOperator(this T receiver, GDExpression left, GDDualOpe
return receiver;
}
+ public static T AddDualOperator(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.DualOperator(unsafeTokens));
+ return receiver;
+ }
+
public static T AddDualOperator(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -137,6 +172,13 @@ public static T AddCall(this T receiver, GDExpression caller, params GDExpres
return receiver;
}
+ public static T AddCall(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Expression.Call(unsafeTokens));
+ return receiver;
+ }
+
public static T AddCall(this T receiver, Func setup)
where T : ITokenReceiver
{
@@ -151,6 +193,13 @@ public static T AddMatch(this T receiver, Func(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ {
+ receiver.HandleReceivedToken(GD.Statement.Match(unsafeTokens));
+ return receiver;
+ }
+
public static T AddMatch(this T receiver, GDExpression value, params GDMatchCaseDeclaration[] cases)
where T : ITokenReceiver
{
diff --git a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_SYNTAX.cs b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_SYNTAX.cs
index 7d60fc2..25b3b4d 100644
--- a/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_SYNTAX.cs
+++ b/src/GDShrapt.Reader/Building/GDBuildingExtensionMethods_SYNTAX.cs
@@ -30,6 +30,23 @@ public static T AddIntendation(this T receiver, int count = 0)
return receiver;
}
+ public static T Add(this T receiver, params GDSyntaxToken[] unsafeTokens)
+ where T : ITokenReceiver
+ where B : GDNode, new()
+ {
+ receiver.HandleReceivedToken(new B() { FormTokensSetter = unsafeTokens });
+ return receiver;
+ }
+
+ public static T Add(this T receiver)
+ where T : ITokenReceiver
+ where B : GDSyntaxToken, new()
+ {
+ receiver.HandleReceivedToken(new B());
+ return receiver;
+ }
+
+
public static T Add(this T receiver, B token)
where T : ITokenReceiver
where B : GDSyntaxToken
diff --git a/src/GDShrapt.Reader/Building/GD_ATRIBUTE.cs b/src/GDShrapt.Reader/Building/GD_ATRIBUTE.cs
index 09c589d..674a08e 100644
--- a/src/GDShrapt.Reader/Building/GD_ATRIBUTE.cs
+++ b/src/GDShrapt.Reader/Building/GD_ATRIBUTE.cs
@@ -13,6 +13,7 @@ public static class Atribute
public static GDClassNameAtribute ClassName() => new GDClassNameAtribute();
public static GDClassNameAtribute ClassName(Func setup) => setup(new GDClassNameAtribute());
+ public static GDClassNameAtribute ClassName(params GDSyntaxToken[] unsafeTokens) => new GDClassNameAtribute() { FormTokensSetter = unsafeTokens };
public static GDClassNameAtribute ClassName(string identifier) => new GDClassNameAtribute()
{
ClassNameKeyword = new GDClassNameKeyword(),
@@ -29,6 +30,7 @@ public static class Atribute
public static GDExtendsAtribute Extends() => new GDExtendsAtribute();
public static GDExtendsAtribute Extends(Func setup) => setup(new GDExtendsAtribute());
+ public static GDExtendsAtribute Extends(params GDSyntaxToken[] unsafeTokens) => new GDExtendsAtribute() { FormTokensSetter = unsafeTokens };
public static GDExtendsAtribute Extends(GDType type) => new GDExtendsAtribute()
{
ExtendsKeyword = new GDExtendsKeyword(),
diff --git a/src/GDShrapt.Reader/Building/GD_BRANCH.cs b/src/GDShrapt.Reader/Building/GD_BRANCH.cs
index c9df8e9..6c3e025 100644
--- a/src/GDShrapt.Reader/Building/GD_BRANCH.cs
+++ b/src/GDShrapt.Reader/Building/GD_BRANCH.cs
@@ -8,6 +8,7 @@ public static class Branch
{
public static GDIfBranch If() => new GDIfBranch();
public static GDIfBranch If(Func setup) => setup(new GDIfBranch());
+ public static GDIfBranch If(params GDSyntaxToken[] unsafeTokens) => new GDIfBranch() { FormTokensSetter = unsafeTokens };
public static GDIfBranch If(GDExpression condition, GDExpression expression) => new GDIfBranch()
{
IfKeyword = new GDIfKeyword(),
@@ -38,6 +39,7 @@ public static class Branch
public static GDElifBranch Elif() => new GDElifBranch();
public static GDElifBranch Elif(Func setup) => setup(new GDElifBranch());
+ public static GDElifBranch Elif(params GDSyntaxToken[] unsafeTokens) => new GDElifBranch() { FormTokensSetter = unsafeTokens };
public static GDElifBranch Elif(GDExpression condition, GDExpression expression) => new GDElifBranch()
{
ElifKeyword = new GDElifKeyword(),
@@ -68,6 +70,7 @@ public static class Branch
public static GDElseBranch Else() => new GDElseBranch();
public static GDElseBranch Else(Func setup) => setup(new GDElseBranch());
+ public static GDElseBranch Else(params GDSyntaxToken[] unsafeTokens) => new GDElseBranch() { FormTokensSetter = unsafeTokens };
public static GDElseBranch Else(GDExpression expression) => new GDElseBranch()
{
ElseKeyword = new GDElseKeyword(),
diff --git a/src/GDShrapt.Reader/Building/GD_DECLARATION.cs b/src/GDShrapt.Reader/Building/GD_DECLARATION.cs
index 104432c..a782791 100644
--- a/src/GDShrapt.Reader/Building/GD_DECLARATION.cs
+++ b/src/GDShrapt.Reader/Building/GD_DECLARATION.cs
@@ -2,12 +2,16 @@
namespace GDShrapt.Reader
{
+ ///
+ /// GDScript code generation helper
+ ///
public static partial class GD
{
public static class Declaration
{
public static GDClassDeclaration Class() => new GDClassDeclaration();
public static GDClassDeclaration Class(Func setup) => setup(new GDClassDeclaration());
+ public static GDClassDeclaration Class(params GDSyntaxToken[] unsafeTokens) => new GDClassDeclaration() { FormTokensSetter = unsafeTokens };
public static GDClassDeclaration Class(GDClassAtributesList atributes, GDClassMembersList members) => new GDClassDeclaration()
{
Atributes = atributes,
@@ -17,6 +21,7 @@ public static class Declaration
public static GDInnerClassDeclaration InnerClass() => new GDInnerClassDeclaration();
public static GDInnerClassDeclaration InnerClass(Func setup) => setup(new GDInnerClassDeclaration());
+ public static GDInnerClassDeclaration InnerClass(params GDSyntaxToken[] unsafeTokens) => new GDInnerClassDeclaration() { FormTokensSetter = unsafeTokens };
public static GDInnerClassDeclaration InnerClass(string name) => new GDInnerClassDeclaration()
{
ClassKeyword = new GDClassKeyword(),
@@ -74,6 +79,7 @@ public static class Declaration
public static GDMethodDeclaration Method() => new GDMethodDeclaration();
public static GDMethodDeclaration Method(Func setup) => setup(new GDMethodDeclaration());
+ public static GDMethodDeclaration Method(params GDSyntaxToken[] unsafeTokens) => new GDMethodDeclaration() { FormTokensSetter = unsafeTokens };
public static GDMethodDeclaration Method(GDIdentifier identifier, GDParametersList parameters, params GDStatement[] statements) => new GDMethodDeclaration()
{
FuncKeyword = new GDFuncKeyword(),
@@ -199,6 +205,7 @@ public static class Declaration
public static GDParameterDeclaration Parameter() => new GDParameterDeclaration();
public static GDParameterDeclaration Parameter(Func setup) => setup(new GDParameterDeclaration());
+ public static GDParameterDeclaration Parameter(params GDSyntaxToken[] unsafeTokens) => new GDParameterDeclaration() { FormTokensSetter = unsafeTokens };
public static GDParameterDeclaration Parameter(string identifier) => new GDParameterDeclaration()
{
Identifier = Syntax.Identifier(identifier)
@@ -256,6 +263,7 @@ public static class Declaration
public static GDMatchCaseDeclaration MatchCase() => new GDMatchCaseDeclaration();
public static GDMatchCaseDeclaration MatchCase(Func setup) => setup(new GDMatchCaseDeclaration());
+ public static GDMatchCaseDeclaration MatchCase(params GDSyntaxToken[] unsafeTokens) => new GDMatchCaseDeclaration() { FormTokensSetter = unsafeTokens };
public static GDMatchCaseDeclaration MatchCase(GDExpressionsList conditions, GDStatementsList statements) => new GDMatchCaseDeclaration()
{
Conditions = conditions,
@@ -272,6 +280,7 @@ public static class Declaration
public static GDSignalDeclaration Signal() => new GDSignalDeclaration();
public static GDSignalDeclaration Signal(Func setup) => setup(new GDSignalDeclaration());
+ public static GDSignalDeclaration Signal(params GDSyntaxToken[] unsafeTokens) => new GDSignalDeclaration() { FormTokensSetter = unsafeTokens };
public static GDSignalDeclaration Signal(GDIdentifier identifier, GDParametersList parameters) => new GDSignalDeclaration()
{
SignalKeyword = new GDSignalKeyword(),
@@ -304,6 +313,7 @@ public static class Declaration
public static GDVariableDeclaration Variable() => new GDVariableDeclaration();
public static GDVariableDeclaration Variable(Func setup) => setup(new GDVariableDeclaration());
+ public static GDVariableDeclaration Variable(params GDSyntaxToken[] unsafeTokens) => new GDVariableDeclaration() { FormTokensSetter = unsafeTokens };
public static GDVariableDeclaration Variable(GDIdentifier identifier) => new GDVariableDeclaration()
{
VarKeyword = new GDVarKeyword(),
diff --git a/src/GDShrapt.Reader/Building/GD_EXPRESSION.cs b/src/GDShrapt.Reader/Building/GD_EXPRESSION.cs
index 22574bd..f198556 100644
--- a/src/GDShrapt.Reader/Building/GD_EXPRESSION.cs
+++ b/src/GDShrapt.Reader/Building/GD_EXPRESSION.cs
@@ -19,6 +19,7 @@ public static class Expression
public static GDIfExpression If() => new GDIfExpression();
public static GDIfExpression If(Func setup) => setup(new GDIfExpression());
+ public static GDIfExpression If(params GDSyntaxToken[] unsafeTokens) => new GDIfExpression() { FormTokensSetter = unsafeTokens };
public static GDIfExpression If(GDExpression condition, GDExpression trueExpr, GDExpression falseExpr) => new GDIfExpression()
{
TrueExpression = trueExpr,
@@ -34,6 +35,7 @@ public static class Expression
public static GDArrayInitializerExpression Array() => new GDArrayInitializerExpression();
public static GDArrayInitializerExpression Array(Func setup) => setup(new GDArrayInitializerExpression());
+ public static GDArrayInitializerExpression Array(params GDSyntaxToken[] unsafeTokens) => new GDArrayInitializerExpression() { FormTokensSetter = unsafeTokens };
public static GDArrayInitializerExpression Array(params GDExpression[] expressions) => new GDArrayInitializerExpression()
{
Values = List.Expressions(expressions)
@@ -41,6 +43,7 @@ public static class Expression
public static GDDictionaryInitializerExpression Dictionary() => new GDDictionaryInitializerExpression();
public static GDDictionaryInitializerExpression Dictionary(Func setup) => setup(new GDDictionaryInitializerExpression());
+ public static GDDictionaryInitializerExpression Dictionary(params GDSyntaxToken[] unsafeTokens) => new GDDictionaryInitializerExpression() { FormTokensSetter = unsafeTokens };
public static GDDictionaryInitializerExpression Dictionary(params GDDictionaryKeyValueDeclaration[] keyValues) => new GDDictionaryInitializerExpression()
{
KeyValues = List.KeyValues(keyValues)
@@ -61,6 +64,7 @@ public static class Expression
public static GDCallExpression Call() => new GDCallExpression();
public static GDCallExpression Call(Func setup) => setup(new GDCallExpression());
+ public static GDCallExpression Call(params GDSyntaxToken[] unsafeTokens) => new GDCallExpression() { FormTokensSetter = unsafeTokens };
public static GDCallExpression Call(GDExpression caller, params GDExpression[] parameters) => new GDCallExpression()
{
CallerExpression = caller,
@@ -71,7 +75,7 @@ public static class Expression
public static GDBracketExpression Bracket() => new GDBracketExpression();
public static GDBracketExpression Bracket(Func setup) => setup(new GDBracketExpression());
-
+ public static GDBracketExpression Bracket(params GDSyntaxToken[] unsafeTokens) => new GDBracketExpression() { FormTokensSetter = unsafeTokens };
public static GDBracketExpression Bracket(GDExpression inner) => new GDBracketExpression()
{
OpenBracket = new GDOpenBracket(),
@@ -81,7 +85,7 @@ public static class Expression
public static GDMemberOperatorExpression Member() => new GDMemberOperatorExpression();
public static GDMemberOperatorExpression Member(Func setup) => setup(new GDMemberOperatorExpression());
-
+ public static GDMemberOperatorExpression Member(params GDSyntaxToken[] unsafeTokens) => new GDMemberOperatorExpression() { FormTokensSetter = unsafeTokens };
public static GDMemberOperatorExpression Member(GDExpression caller, string identifier) => new GDMemberOperatorExpression()
{
CallerExpression = caller,
@@ -115,6 +119,7 @@ public static class Expression
public static GDIndexerExpression Indexer() => new GDIndexerExpression();
public static GDIndexerExpression Indexer(Func setup) => setup(new GDIndexerExpression());
+ public static GDIndexerExpression Indexer(params GDSyntaxToken[] unsafeTokens) => new GDIndexerExpression() { FormTokensSetter = unsafeTokens };
public static GDIndexerExpression Indexer(GDExpression caller, GDExpression indexExpression) => new GDIndexerExpression()
{
CallerExpression = caller,
@@ -149,6 +154,7 @@ public static class Expression
};
public static GDReturnExpression Return(Func setup) => setup(new GDReturnExpression());
+ public static GDReturnExpression Return(params GDSyntaxToken[] unsafeTokens) => new GDReturnExpression() { FormTokensSetter = unsafeTokens };
public static GDReturnExpression Return(GDExpression result) => new GDReturnExpression()
{
ReturnKeyword = new GDReturnKeyword(),
@@ -158,6 +164,7 @@ public static class Expression
public static GDSingleOperatorExpression SingleOperator() => new GDSingleOperatorExpression();
public static GDSingleOperatorExpression SingleOperator(Func setup) => setup(new GDSingleOperatorExpression());
+ public static GDSingleOperatorExpression SingleOperator(params GDSyntaxToken[] unsafeTokens) => new GDSingleOperatorExpression() { FormTokensSetter = unsafeTokens };
public static GDSingleOperatorExpression SingleOperator(GDSingleOperator @operator, GDExpression operand) => new GDSingleOperatorExpression()
{
Operator = @operator,
@@ -166,6 +173,7 @@ public static class Expression
public static GDDualOperatorExpression DualOperator() => new GDDualOperatorExpression();
public static GDDualOperatorExpression DualOperator(Func setup) => setup(new GDDualOperatorExpression());
+ public static GDDualOperatorExpression DualOperator(params GDSyntaxToken[] unsafeTokens) => new GDDualOperatorExpression() { FormTokensSetter = unsafeTokens };
public static GDDualOperatorExpression DualOperator(GDExpression left, GDDualOperator @operator, GDExpression right) => new GDDualOperatorExpression()
{
LeftExpression = left,
@@ -175,6 +183,7 @@ public static class Expression
public static GDGetNodeExpression GetNode() => new GDGetNodeExpression();
public static GDGetNodeExpression GetNode(Func setup) => setup(new GDGetNodeExpression());
+ public static GDGetNodeExpression GetNode(params GDSyntaxToken[] unsafeTokens) => new GDGetNodeExpression() { FormTokensSetter = unsafeTokens };
public static GDGetNodeExpression GetNode(GDPathList pathList) => new GDGetNodeExpression()
{
Dollar = new GDDollar(),
@@ -199,6 +208,7 @@ public static class Expression
public static GDNodePathExpression NodePath() => new GDNodePathExpression();
public static GDNodePathExpression NodePath(Func setup) => setup(new GDNodePathExpression());
+ public static GDNodePathExpression NodePath(params GDSyntaxToken[] unsafeTokens) => new GDNodePathExpression() { FormTokensSetter = unsafeTokens };
public static GDNodePathExpression NodePath(GDString path) => new GDNodePathExpression()
{
At = new GDAt(),
@@ -207,6 +217,7 @@ public static class Expression
public static GDMatchCaseVariableExpression MatchCaseVariable() => new GDMatchCaseVariableExpression();
public static GDMatchCaseVariableExpression MatchCaseVariable(Func setup) => setup(new GDMatchCaseVariableExpression());
+ public static GDMatchCaseVariableExpression MatchCaseVariable(params GDSyntaxToken[] unsafeTokens) => new GDMatchCaseVariableExpression() { FormTokensSetter = unsafeTokens };
public static GDMatchCaseVariableExpression MatchCaseVariable(string identifier) => new GDMatchCaseVariableExpression()
{
VarKeyword = new GDVarKeyword(),
@@ -223,6 +234,7 @@ public static class Expression
public static GDYieldExpression Yield() => new GDYieldExpression();
public static GDYieldExpression Yield(Func setup) => setup(new GDYieldExpression());
+ public static GDYieldExpression Yield(params GDSyntaxToken[] unsafeTokens) => new GDYieldExpression() { FormTokensSetter = unsafeTokens };
public static GDYieldExpression Yield(GDExpressionsList parameters) => new GDYieldExpression()
{
YieldKeyword = new GDYieldKeyword(),
diff --git a/src/GDShrapt.Reader/Building/GD_LIST.cs b/src/GDShrapt.Reader/Building/GD_LIST.cs
index 0a2c6d2..579bb4f 100644
--- a/src/GDShrapt.Reader/Building/GD_LIST.cs
+++ b/src/GDShrapt.Reader/Building/GD_LIST.cs
@@ -8,18 +8,7 @@ public static class List
{
public static GDStatementsList Statements() => new GDStatementsList();
public static GDStatementsList Statements(Func setup) => setup(new GDStatementsList());
- public static GDStatementsList Statements(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return new GDStatementsList();
-
- var list = new GDStatementsList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDStatementsList Statements(params GDSyntaxToken[] unsafeTokens) => new GDStatementsList() { FormTokensSetter = unsafeTokens };
public static GDStatementsList Statements(params GDStatement[] statements)
{
if (statements == null || statements.Length == 0)
@@ -29,8 +18,8 @@ public static GDStatementsList Statements(params GDStatement[] statements)
for (int i = 0; i < statements.Length; i++)
{
- list.Form.Add(new GDNewLine());
- list.Form.Add(Syntax.Intendation());
+ list.Form.AddToEnd(new GDNewLine());
+ list.Form.AddToEnd(Syntax.Intendation());
list.Add(statements[i]);
}
@@ -39,18 +28,7 @@ public static GDStatementsList Statements(params GDStatement[] statements)
public static GDExpressionsList Expressions() => new GDExpressionsList();
public static GDExpressionsList Expressions(Func setup) => setup(new GDExpressionsList());
- public static GDExpressionsList Expressions(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return new GDExpressionsList();
-
- var list = new GDExpressionsList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDExpressionsList Expressions(params GDSyntaxToken[] unsafeTokens) => new GDExpressionsList() { FormTokensSetter = unsafeTokens };
public static GDExpressionsList Expressions(params GDExpression[] expressions)
{
if (expressions == null || expressions.Length == 0)
@@ -62,8 +40,8 @@ public static GDExpressionsList Expressions(params GDExpression[] expressions)
{
if (i > 0)
{
- list.Form.Add(new GDComma());
- list.Form.Add(Syntax.Space());
+ list.Form.AddToEnd(new GDComma());
+ list.Form.AddToEnd(Syntax.Space());
}
list.Add(expressions[i]);
@@ -74,18 +52,7 @@ public static GDExpressionsList Expressions(params GDExpression[] expressions)
public static GDDictionaryKeyValueDeclarationList KeyValues() => new GDDictionaryKeyValueDeclarationList();
public static GDDictionaryKeyValueDeclarationList KeyValues(Func setup) => setup(new GDDictionaryKeyValueDeclarationList());
- public static GDDictionaryKeyValueDeclarationList KeyValues(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return new GDDictionaryKeyValueDeclarationList();
-
- var list = new GDDictionaryKeyValueDeclarationList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDDictionaryKeyValueDeclarationList KeyValues(params GDSyntaxToken[] unsafeTokens) => new GDDictionaryKeyValueDeclarationList() { FormTokensSetter = unsafeTokens };
public static GDDictionaryKeyValueDeclarationList KeyValues(params GDDictionaryKeyValueDeclaration[] keyValues)
{
if (keyValues == null || keyValues.Length == 0)
@@ -97,8 +64,8 @@ public static GDDictionaryKeyValueDeclarationList KeyValues(params GDDictionaryK
{
if (i > 0)
{
- list.Form.Add(new GDComma());
- list.Form.Add(Syntax.Space());
+ list.Form.AddToEnd(new GDComma());
+ list.Form.AddToEnd(Syntax.Space());
}
list.Add(keyValues[i]);
@@ -109,18 +76,7 @@ public static GDDictionaryKeyValueDeclarationList KeyValues(params GDDictionaryK
public static GDParametersList Parameters() => new GDParametersList();
public static GDParametersList Parameters(Func setup) => setup(new GDParametersList());
- public static GDParametersList Parameters(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return new GDParametersList();
-
- var list = new GDParametersList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDParametersList Parameters(params GDSyntaxToken[] unsafeTokens) => new GDParametersList() { FormTokensSetter = unsafeTokens };
public static GDParametersList Parameters(params GDParameterDeclaration[] parameters)
{
if (parameters == null || parameters.Length == 0)
@@ -132,8 +88,8 @@ public static GDParametersList Parameters(params GDParameterDeclaration[] parame
{
if (i > 0)
{
- list.Form.Add(new GDComma());
- list.Form.Add(Syntax.Space());
+ list.Form.AddToEnd(new GDComma());
+ list.Form.AddToEnd(Syntax.Space());
}
list.Add(parameters[i]);
@@ -144,18 +100,7 @@ public static GDParametersList Parameters(params GDParameterDeclaration[] parame
public static GDElifBranchesList ElifBranches() => new GDElifBranchesList();
public static GDElifBranchesList ElifBranches(Func setup) => setup(new GDElifBranchesList());
- public static GDElifBranchesList ElifBranches(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return new GDElifBranchesList();
-
- var list = new GDElifBranchesList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDElifBranchesList ElifBranches(params GDSyntaxToken[] unsafeTokens) => new GDElifBranchesList() { FormTokensSetter = unsafeTokens };
public static GDElifBranchesList ElifBranches(params GDElifBranch[] branches)
{
if (branches == null || branches.Length == 0)
@@ -165,8 +110,8 @@ public static GDElifBranchesList ElifBranches(params GDElifBranch[] branches)
for (int i = 0; i < branches.Length; i++)
{
- list.Form.Add(new GDNewLine());
- list.Form.Add(Syntax.Intendation());
+ list.Form.AddToEnd(new GDNewLine());
+ list.Form.AddToEnd(Syntax.Intendation());
list.Add(branches[i]);
}
@@ -175,18 +120,7 @@ public static GDElifBranchesList ElifBranches(params GDElifBranch[] branches)
public static GDClassMembersList Members() => new GDClassMembersList();
public static GDClassMembersList Members(Func setup) => setup(new GDClassMembersList());
- public static GDClassMembersList Members(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDClassMembersList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDClassMembersList Members(params GDSyntaxToken[] unsafeTokens) => new GDClassMembersList() { FormTokensSetter = unsafeTokens };
public static GDClassMembersList Members(params GDClassMember[] members)
{
if (members == null || members.Length == 0)
@@ -198,11 +132,11 @@ public static GDClassMembersList Members(params GDClassMember[] members)
{
if (i > 0)
{
- list.Form.Add(new GDNewLine());
- list.Form.Add(new GDNewLine());
+ list.Form.AddToEnd(new GDNewLine());
+ list.Form.AddToEnd(new GDNewLine());
}
- list.Form.Add(Syntax.Intendation());
+ list.Form.AddToEnd(Syntax.Intendation());
list.Add(members[i]);
}
@@ -211,18 +145,7 @@ public static GDClassMembersList Members(params GDClassMember[] members)
public static GDClassAtributesList Atributes() => new GDClassAtributesList();
public static GDClassAtributesList Atributes(Func setup) => setup(new GDClassAtributesList());
- public static GDClassAtributesList Atributes(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDClassAtributesList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDClassAtributesList Atributes(params GDSyntaxToken[] unsafeTokens) => new GDClassAtributesList() { FormTokensSetter = unsafeTokens };
public static GDClassAtributesList Atributes(params GDClassAtribute[] atributes)
{
if (atributes == null || atributes.Length == 0)
@@ -233,8 +156,8 @@ public static GDClassAtributesList Atributes(params GDClassAtribute[] atributes)
for (int i = 0; i < atributes.Length; i++)
{
if (i > 0)
- list.Form.Add(new GDNewLine());
- list.Form.Add(Syntax.Intendation());
+ list.Form.AddToEnd(new GDNewLine());
+ list.Form.AddToEnd(Syntax.Intendation());
list.Add(atributes[i]);
}
@@ -243,18 +166,7 @@ public static GDClassAtributesList Atributes(params GDClassAtribute[] atributes)
public static GDEnumValuesList EnumValues() => new GDEnumValuesList();
public static GDEnumValuesList EnumValues(Func setup) => setup(new GDEnumValuesList());
- public static GDEnumValuesList EnumValues(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDEnumValuesList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDEnumValuesList EnumValues(params GDSyntaxToken[] unsafeTokens) => new GDEnumValuesList() { FormTokensSetter = unsafeTokens };
public static GDEnumValuesList EnumValues(params GDEnumValueDeclaration[] values)
{
if (values == null || values.Length == 0)
@@ -266,8 +178,8 @@ public static GDEnumValuesList EnumValues(params GDEnumValueDeclaration[] values
{
if (i > 0)
{
- list.Form.Add(new GDComma());
- list.Form.Add(Syntax.Space());
+ list.Form.AddToEnd(new GDComma());
+ list.Form.AddToEnd(Syntax.Space());
}
list.Add(values[i]);
@@ -279,18 +191,7 @@ public static GDEnumValuesList EnumValues(params GDEnumValueDeclaration[] values
public static GDPathList Path() => new GDPathList();
public static GDPathList Path(Func setup) => setup(new GDPathList());
- public static GDPathList Path(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDPathList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDPathList Path(params GDSyntaxToken[] unsafeTokens) => new GDPathList() { FormTokensSetter = unsafeTokens };
public static GDPathList Path(params GDIdentifier[] identifiers)
{
if (identifiers == null || identifiers.Length == 0)
@@ -301,7 +202,7 @@ public static GDPathList Path(params GDIdentifier[] identifiers)
for (int i = 0; i < identifiers.Length; i++)
{
if (i > 0)
- list.Form.Add(new GDRightSlash());
+ list.Form.AddToEnd(new GDRightSlash());
list.Add(identifiers[i]);
}
@@ -311,18 +212,7 @@ public static GDPathList Path(params GDIdentifier[] identifiers)
public static GDExportParametersList ExportParameters() => new GDExportParametersList();
public static GDExportParametersList ExportParameters(Func setup) => setup(new GDExportParametersList());
- public static GDExportParametersList ExportParameters(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDExportParametersList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDExportParametersList ExportParameters(params GDSyntaxToken[] unsafeTokens) => new GDExportParametersList() { FormTokensSetter = unsafeTokens };
public static GDExportParametersList ExportParameters(params GDDataToken[] tokens)
{
if (tokens == null || tokens.Length == 0)
@@ -334,8 +224,8 @@ public static GDExportParametersList ExportParameters(params GDDataToken[] token
{
if (i > 0)
{
- list.Form.Add(new GDComma());
- list.Form.Add(Syntax.Space());
+ list.Form.AddToEnd(new GDComma());
+ list.Form.AddToEnd(Syntax.Space());
}
list.Add(tokens[i]);
@@ -346,18 +236,7 @@ public static GDExportParametersList ExportParameters(params GDDataToken[] token
public static GDMatchCasesList MatchCases() => new GDMatchCasesList();
public static GDMatchCasesList MatchCases(Func setup) => setup(new GDMatchCasesList());
- public static GDMatchCasesList MatchCases(params GDSyntaxToken[] unsafeTokens)
- {
- if (unsafeTokens == null || unsafeTokens.Length == 0)
- return null;
-
- var list = new GDMatchCasesList();
-
- for (int i = 0; i < unsafeTokens.Length; i++)
- list.Form.Add(unsafeTokens[i]);
-
- return list;
- }
+ public static GDMatchCasesList MatchCases(params GDSyntaxToken[] unsafeTokens) => new GDMatchCasesList() { FormTokensSetter = unsafeTokens };
public static GDMatchCasesList MatchCases(params GDMatchCaseDeclaration[] tokens)
{
if (tokens == null || tokens.Length == 0)
@@ -367,8 +246,8 @@ public static GDMatchCasesList MatchCases(params GDMatchCaseDeclaration[] tokens
for (int i = 0; i < tokens.Length; i++)
{
- list.Form.Add(new GDNewLine());
- list.Form.Add(Syntax.Intendation());
+ list.Form.AddToEnd(new GDNewLine());
+ list.Form.AddToEnd(Syntax.Intendation());
list.Add(tokens[i]);
}
diff --git a/src/GDShrapt.Reader/Building/GD_STATEMENT.cs b/src/GDShrapt.Reader/Building/GD_STATEMENT.cs
index 5351581..19be311 100644
--- a/src/GDShrapt.Reader/Building/GD_STATEMENT.cs
+++ b/src/GDShrapt.Reader/Building/GD_STATEMENT.cs
@@ -8,6 +8,7 @@ public static class Statement
{
public static GDForStatement For() => new GDForStatement();
public static GDForStatement For(Func setup) => setup(new GDForStatement());
+ public static GDForStatement For(params GDSyntaxToken[] unsafeTokens) => new GDForStatement() { FormTokensSetter = unsafeTokens };
public static GDForStatement For(GDIdentifier variable, GDExpression collection, GDExpression body) => new GDForStatement()
{
ForKeyword = new GDForKeyword(),
@@ -43,6 +44,7 @@ public static class Statement
public static GDIfStatement If() => new GDIfStatement();
public static GDIfStatement If(Func setup) => setup(new GDIfStatement());
+ public static GDIfStatement If(params GDSyntaxToken[] unsafeTokens) => new GDIfStatement() { FormTokensSetter = unsafeTokens };
public static GDIfStatement If(GDIfBranch ifBranch) => new GDIfStatement()
{
IfBranch = ifBranch
@@ -76,6 +78,7 @@ public static class Statement
public static GDWhileStatement While() => new GDWhileStatement();
public static GDWhileStatement While(Func setup) => setup(new GDWhileStatement());
+ public static GDWhileStatement While(params GDSyntaxToken[] unsafeTokens) => new GDWhileStatement() { FormTokensSetter = unsafeTokens };
public static GDWhileStatement While(GDExpression condition, GDExpression body) => new GDWhileStatement()
{
WhileKeyword = new GDWhileKeyword(),
@@ -106,6 +109,7 @@ public static class Statement
public static GDMatchStatement Match() => new GDMatchStatement();
public static GDMatchStatement Match(Func setup) => setup(new GDMatchStatement());
+ public static GDMatchStatement Match(params GDSyntaxToken[] unsafeTokens) => new GDMatchStatement() { FormTokensSetter = unsafeTokens };
public static GDMatchStatement Match(GDExpression value, params GDMatchCaseDeclaration[] cases) => new GDMatchStatement()
{
MatchKeyword = new GDMatchKeyword(),
@@ -125,6 +129,7 @@ public static class Statement
public static GDVariableDeclarationStatement Variable() => new GDVariableDeclarationStatement();
public static GDVariableDeclarationStatement Variable(Func setup) => setup(new GDVariableDeclarationStatement());
+ public static GDVariableDeclarationStatement Variable(params GDSyntaxToken[] unsafeTokens) => new GDVariableDeclarationStatement() { FormTokensSetter = unsafeTokens };
public static GDVariableDeclarationStatement Variable(string name) => new GDVariableDeclarationStatement()
{
VarKeyword = new GDVarKeyword(),
diff --git a/src/GDShrapt.Reader/Building/GD_SYNTAX.cs b/src/GDShrapt.Reader/Building/GD_SYNTAX.cs
index 99b04a4..11bdbe3 100644
--- a/src/GDShrapt.Reader/Building/GD_SYNTAX.cs
+++ b/src/GDShrapt.Reader/Building/GD_SYNTAX.cs
@@ -18,6 +18,7 @@ public static class Syntax
public static GDNumber Number(long value) => new GDNumber() { ValueInt64 = value };
public static GDNumber Number(double value) => new GDNumber() { ValueDouble = value };
+ public static GDSpace OneSpace => Space();
public static GDSpace Space(int count = 1) => new GDSpace() { Sequence = new string(' ', count) };
public static GDSpace Space(string whiteSpace) => new GDSpace() { Sequence = whiteSpace };
public static GDNewLine NewLine => new GDNewLine();
diff --git a/src/GDShrapt.Reader/Declarations/GDDictionaryKeyValueDeclaration.cs b/src/GDShrapt.Reader/Declarations/GDDictionaryKeyValueDeclaration.cs
index 2b98285..18def75 100644
--- a/src/GDShrapt.Reader/Declarations/GDDictionaryKeyValueDeclaration.cs
+++ b/src/GDShrapt.Reader/Declarations/GDDictionaryKeyValueDeclaration.cs
@@ -36,15 +36,15 @@ public enum State
Completed
}
- readonly GDTokensForm _form;
+ readonly GDTokensForm _form;
public GDDictionaryKeyValueDeclaration()
{
- _form = new GDTokensForm(this);
+ _form = new GDTokensForm(this);
}
public override GDTokensForm Form => _form;
- public GDTokensForm TypedForm => _form;
+ public GDTokensForm TypedForm => _form;
internal override void HandleChar(char c, GDReadingState state)
{
if (this.ResolveSpaceToken(c, state))
diff --git a/src/GDShrapt.Reader/Declarations/GDEnumValueDeclaration.cs b/src/GDShrapt.Reader/Declarations/GDEnumValueDeclaration.cs
index ac81f4a..51691a5 100644
--- a/src/GDShrapt.Reader/Declarations/GDEnumValueDeclaration.cs
+++ b/src/GDShrapt.Reader/Declarations/GDEnumValueDeclaration.cs
@@ -37,12 +37,12 @@ public enum State
Completed
}
- readonly GDTokensForm _form;
+ readonly GDTokensForm _form;
public override GDTokensForm Form => _form;
- public GDTokensForm TypedForm => _form;
+ public GDTokensForm TypedForm => _form;
public GDEnumValueDeclaration()
{
- _form = new GDTokensForm(this);
+ _form = new GDTokensForm(this);
}
internal override void HandleChar(char c, GDReadingState state)
diff --git a/src/GDShrapt.Reader/GDTokensContainer.cs b/src/GDShrapt.Reader/GDTokensContainer.cs
index 452c2e4..18ccdc6 100644
--- a/src/GDShrapt.Reader/GDTokensContainer.cs
+++ b/src/GDShrapt.Reader/GDTokensContainer.cs
@@ -13,7 +13,7 @@ public GDTokensContainer(params GDSyntaxToken[] tokens)
ListForm = new GDTokensListForm(this);
for (int i = 0; i < tokens.Length; i++)
- ListForm.Add(tokens[i]);
+ ListForm.AddToEnd(tokens[i]);
}
public override GDNode CreateEmptyInstance()
diff --git a/src/GDShrapt.Reader/GDTokensForm.cs b/src/GDShrapt.Reader/GDTokensForm.cs
index 0279818..37edd79 100644
--- a/src/GDShrapt.Reader/GDTokensForm.cs
+++ b/src/GDShrapt.Reader/GDTokensForm.cs
@@ -5,303 +5,26 @@
namespace GDShrapt.Reader
{
- public class GDTokensListForm