From 48bba4b4cf7f35259365cd4fb32b39f7cf65d5fc Mon Sep 17 00:00:00 2001 From: elamaunt Date: Fri, 16 Jul 2021 03:32:48 +0500 Subject: [PATCH] WIP: Implemented custom styled node building --- src/GDShrapt.Reader.Tests/BuildingTests.cs | 63 + src/GDShrapt.Reader/Basics/GDNode.cs | 9 + ...GDBuildingExtensionMethods_DECLARATIONS.cs | 28 + .../GDBuildingExtensionMethods_EXPRESSIONS.cs | 99 +- .../GDBuildingExtensionMethods_LIST.cs | 70 ++ .../GDBuildingExtensionMethods_STATEMENTS.cs | 49 + .../GDBuildingExtensionMethods_SYNTAX.cs | 17 + src/GDShrapt.Reader/Building/GD_ATRIBUTE.cs | 2 + src/GDShrapt.Reader/Building/GD_BRANCH.cs | 3 + .../Building/GD_DECLARATION.cs | 10 + src/GDShrapt.Reader/Building/GD_EXPRESSION.cs | 16 +- src/GDShrapt.Reader/Building/GD_LIST.cs | 187 +-- src/GDShrapt.Reader/Building/GD_STATEMENT.cs | 5 + src/GDShrapt.Reader/Building/GD_SYNTAX.cs | 1 + .../GDDictionaryKeyValueDeclaration.cs | 6 +- .../Declarations/GDEnumValueDeclaration.cs | 6 +- src/GDShrapt.Reader/GDTokensContainer.cs | 2 +- src/GDShrapt.Reader/GDTokensForm.cs | 1025 ++++++++++------- src/GDShrapt.Reader/GDTokensListForm.cs | 306 +++++ .../Lists/GDClassAtributesList.cs | 2 +- .../Lists/GDClassMembersList.cs | 2 +- .../Lists/GDCommaSeparatedList.cs | 12 +- .../GDDictionaryKeyValueDeclarationList.cs | 4 +- src/GDShrapt.Reader/Lists/GDEnumValuesList.cs | 4 +- .../Lists/GDExportParametersList.cs | 4 +- .../Lists/GDExpressionsList.cs | 2 +- .../Lists/GDIntendedTokensList.cs | 6 +- src/GDShrapt.Reader/Lists/GDParametersList.cs | 4 +- src/GDShrapt.Reader/Lists/GDPathList.cs | 6 +- src/GDShrapt.Reader/Lists/GDSeparatedList.cs | 4 +- src/GDShrapt.Reader/SimpleTokens/GDAssign.cs | 2 +- src/GDShrapt.Reader/SimpleTokens/GDColon.cs | 2 +- .../SimpleTokens/GDPairToken.cs | 6 + 33 files changed, 1373 insertions(+), 591 deletions(-) create mode 100644 src/GDShrapt.Reader/GDTokensListForm.cs create mode 100644 src/GDShrapt.Reader/SimpleTokens/GDPairToken.cs 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 : GDTokensForm, IList - where TOKEN : GDSyntaxToken + public class GDTokensForm : GDTokensForm + where STATE : struct, System.Enum + where T0 : GDSyntaxToken { - internal GDTokensListForm(GDNode owner) - : base(owner) + static Type[] GenericTypes = new Type[] { - } + typeof(T0), + }; - public new int Count => _statePoints.Count; - public int TokensCount => base.Count; + public override Type[] Types => GenericTypes; - public TOKEN this[int index] + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) { - get => (TOKEN)_statePoints[index].Value; - set + switch (statePoint) { - var node = _statePoints[index]; - - if (node.Value == value) - return; - - if (node.Value != null) - node.Value.Parent = null; - - if (value != null) - { - value.Parent = _owner; - node.Value = value; - } - else - node.Value = null; + case 0: return token is T0; + default: + throw new IndexOutOfRangeException(); } } - - public void Add(TOKEN item) - { - item.Parent = _owner; - _statePoints.Add(_list.AddLast(item)); - StateIndex++; - } - - public override void Add(GDSyntaxToken value) - { - if (value is TOKEN token) - Add(token); - else - base.Add(value); - } - - public override void AddAfterToken(GDSyntaxToken newToken, GDSyntaxToken afterThisToken) - { - if (newToken is TOKEN token) - { - if (afterThisToken is TOKEN afterToken) - { - var node = _list.Find(afterToken); - - if (node == null) - throw new NullReferenceException("There is no specific token in the form"); - - var index = _statePoints.IndexOf(node); - - var nextIndex = index + 1; - - newToken.Parent = _owner; - - if (nextIndex == _statePoints.Count) - _statePoints.Add(_list.AddAfter(node, token)); - else - _statePoints.Insert(nextIndex, _list.AddAfter(node, token)); - } - else - { - var node = _list.Find(afterThisToken); - - if (node == null) - throw new NullReferenceException("There is no specific token in the form"); - - LinkedListNode nextTypedToken = null; - var next = node.Next; - while (next != null) - { - if (next.Value is TOKEN) - { - nextTypedToken = next; - break; - } - next = next.Next; - } - - newToken.Parent = _owner; - - if (nextTypedToken == null) - { - _statePoints.Add(_list.AddAfter(node, token)); - } - else - { - var index = _statePoints.IndexOf(nextTypedToken); - _statePoints.Insert(index, _list.AddAfter(node, token)); - } - } - } - else - { - base.AddAfterToken(newToken, afterThisToken); - } - } - - public override void AddBeforeToken(GDSyntaxToken newToken, GDSyntaxToken beforeThisToken) - { - if (newToken is TOKEN token) - { - if (beforeThisToken is TOKEN beforeToken) - { - var node = _list.Find(beforeToken); - - if (node == null) - throw new NullReferenceException("There is no specific token in the form"); - - var index = _statePoints.IndexOf(node); - - var previousIndex = index - 1; - newToken.Parent = _owner; - - _statePoints.Insert(previousIndex, _list.AddBefore(node, token)); - } - else - { - var node = _list.Find(beforeThisToken); - - if (node == null) - throw new NullReferenceException("There is no specific token in the form"); - - LinkedListNode nextTypedToken = null; - var next = node.Next; - while (next != null) - { - if (next.Value is TOKEN) - { - nextTypedToken = next; - break; - } - next = next.Next; - } - - newToken.Parent = _owner; - - if (nextTypedToken == null) - { - _statePoints.Add(_list.AddAfter(node, token)); - } - else - { - var index = _statePoints.IndexOf(nextTypedToken); - _statePoints.Insert(index, _list.AddAfter(node, token)); - } - } - } - else - { - base.AddBeforeToken(newToken, beforeThisToken); - } - } - - public override void AddBeforeToken(GDSyntaxToken newToken, int statePointIndex) - { - if (newToken is TOKEN token) - { - if (statePointIndex < _statePoints.Count) - { - var node = _statePoints[statePointIndex]; - newToken.Parent = _owner; - _statePoints.Insert(statePointIndex, _list.AddBefore(node, token)); - } - else - { - newToken.Parent = _owner; - _statePoints.Add(_list.AddLast(token)); - } - } - else - { - base.AddBeforeToken(newToken, statePointIndex); - } - } - - public bool Contains(TOKEN item) - { - if (item is null) - throw new ArgumentNullException(nameof(item)); - - return _list.Contains(item); - } - - public void CopyTo(TOKEN[] array, int arrayIndex) - { - for (int i = 0; i < _statePoints.Count; i++) - { - var node = _statePoints[i]; - - if (node == null || node.Value == null) - continue; - - array[arrayIndex++] = (TOKEN)node.Value; - } - } - - public int IndexOf(TOKEN item) - { - if (item is null) - throw new ArgumentNullException(nameof(item)); - - var node = _list.Find(item); - - if (node == null) - return -1; - - return _statePoints.IndexOf(node); - } - - public void Insert(int index, TOKEN item) - { - if (item is null) - throw new ArgumentNullException(nameof(item)); - - var node = _statePoints[index]; - var newNode =_list.AddBefore(node, item); - item.Parent = _owner; - _statePoints.Insert(index, newNode); - } - - public new void Clear() - { - var c = _statePoints.Count; - - for (int i = 0; i < c; i++) - { - var node = _statePoints[0]; - - if (node.Value != null) - node.Value.Parent = null; - - _list.Remove(node); - } - - _statePoints.Clear(); - } - - public void ClearAllTokens() => base.Clear(); - - public bool Remove(TOKEN item) - { - if (item is null) - throw new ArgumentNullException(nameof(item)); - - var node = _list.Find(item); - - if (node == null) - return false; - - item.Parent = null; - - _statePoints.Remove(node); - _list.Remove(node); - StateIndex--; - return true; - } - - public void RemoveAt(int index) - { - var node = _statePoints[index]; - - if (node.Value != null) - node.Value.Parent = null; - - _statePoints.RemoveAt(index); - _list.Remove(node); - StateIndex--; - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (int i = 0; i < _statePoints.Count; i++) - yield return (TOKEN)_statePoints[i].Value; - } - - new IEnumerator GetEnumerator() - { - return base.GetEnumerator(); - } - } - - public class GDTokensForm : GDTokensForm - where STATE : struct, System.Enum - where T0 : GDSyntaxToken - { internal GDTokensForm(GDNode owner) : base(owner, 1) { @@ -309,7 +32,7 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } } public class GDTokensForm : GDTokensForm @@ -317,15 +40,34 @@ public class GDTokensForm : GDTokensForm where T0 : GDSyntaxToken where T1 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 2) { } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } } public class GDTokensForm : GDTokensForm @@ -334,6 +76,27 @@ public class GDTokensForm : GDTokensForm where T1 : GDSyntaxToken where T2 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 3) { @@ -341,11 +104,11 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } } public class GDTokensForm : GDTokensForm @@ -355,6 +118,29 @@ public class GDTokensForm : GDTokensForm where T2 : GDSyntaxToken where T3 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 4) { @@ -362,13 +148,13 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } } public class GDTokensForm : GDTokensForm @@ -379,6 +165,31 @@ public class GDTokensForm : GDTokensForm where T3 : GDSyntaxToken where T4 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 5) { @@ -386,17 +197,15 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } - - + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } } public class GDTokensForm : GDTokensForm @@ -408,6 +217,33 @@ public class GDTokensForm : GDTokensForm where T4 : GDSyntaxToken where T5 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4), + typeof(T5) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 6) { @@ -415,17 +251,17 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } } public class GDTokensForm : GDTokensForm @@ -438,6 +274,35 @@ public class GDTokensForm : GDTokensForm GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 7) { @@ -445,19 +310,19 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } } public class GDTokensForm : GDTokensForm @@ -471,6 +336,37 @@ public class GDTokensForm : GDTokensForm where T6 : GDSyntaxToken where T7 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4), + typeof(T5), + typeof(T6), + typeof(T7) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 8) { @@ -478,21 +374,21 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } } public class GDTokensForm : GDTokensForm @@ -507,6 +403,39 @@ public class GDTokensForm : GDTokensF where T7 : GDSyntaxToken where T8 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4), + typeof(T5), + typeof(T6), + typeof(T7), + typeof(T8) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 9) { @@ -514,23 +443,23 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } } public class GDTokensForm : GDTokensForm @@ -546,6 +475,41 @@ public class GDTokensForm : GDTok where T8 : GDSyntaxToken where T9 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4), + typeof(T5), + typeof(T6), + typeof(T7), + typeof(T8), + typeof(T9) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + case 9: return token is T9; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 10) { @@ -553,25 +517,25 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } public void AddBeforeToken9(GDSyntaxToken token) => AddMiddle(token, 9); - public T9 Token9 { get => Get(9); set => Set(value, 9); } + public T9 Token9 { get => Get(9); set => ProtectedSet(value, 9); } } public class GDTokensForm : GDTokensForm @@ -588,6 +552,43 @@ public class GDTokensForm : where T9 : GDSyntaxToken where T10 : GDSyntaxToken { + static Type[] GenericTypes = new Type[] + { + typeof(T0), + typeof(T1), + typeof(T2), + typeof(T3), + typeof(T4), + typeof(T5), + typeof(T6), + typeof(T7), + typeof(T8), + typeof(T9), + typeof(T10) + }; + + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + case 9: return token is T9; + case 10: return token is T10; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 11) { @@ -595,27 +596,27 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } public void AddBeforeToken9(GDSyntaxToken token) => AddMiddle(token, 9); - public T9 Token9 { get => Get(9); set => Set(value, 9); } + public T9 Token9 { get => Get(9); set => ProtectedSet(value, 9); } public void AddBeforeToken10(GDSyntaxToken token) => AddMiddle(token, 10); - public T10 Token10 { get => Get(10); set => Set(value, 10); } + public T10 Token10 { get => Get(10); set => ProtectedSet(value, 10); } } public class GDTokensForm : GDTokensForm @@ -633,6 +634,45 @@ public class GDTokensForm GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + case 9: return token is T9; + case 10: return token is T10; + case 11: return token is T11; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 12) { @@ -640,29 +680,29 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } public void AddBeforeToken9(GDSyntaxToken token) => AddMiddle(token, 9); - public T9 Token9 { get => Get(9); set => Set(value, 9); } + public T9 Token9 { get => Get(9); set => ProtectedSet(value, 9); } public void AddBeforeToken10(GDSyntaxToken token) => AddMiddle(token, 10); - public T10 Token10 { get => Get(10); set => Set(value, 10); } + public T10 Token10 { get => Get(10); set => ProtectedSet(value, 10); } public void AddBeforeToken11(GDSyntaxToken token) => AddMiddle(token, 11); - public T11 Token11 { get => Get(11); set => Set(value, 11); } + public T11 Token11 { get => Get(11); set => ProtectedSet(value, 11); } } public class GDTokensForm : GDTokensForm @@ -681,6 +721,47 @@ public class GDTokensForm GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + case 9: return token is T9; + case 10: return token is T10; + case 11: return token is T11; + case 12: return token is T12; + default: + throw new IndexOutOfRangeException(); + } + } + internal GDTokensForm(GDNode owner) : base(owner, 13) { @@ -688,31 +769,31 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } public void AddBeforeToken9(GDSyntaxToken token) => AddMiddle(token, 9); - public T9 Token9 { get => Get(9); set => Set(value, 9); } + public T9 Token9 { get => Get(9); set => ProtectedSet(value, 9); } public void AddBeforeToken10(GDSyntaxToken token) => AddMiddle(token, 10); - public T10 Token10 { get => Get(10); set => Set(value, 10); } + public T10 Token10 { get => Get(10); set => ProtectedSet(value, 10); } public void AddBeforeToken11(GDSyntaxToken token) => AddMiddle(token, 11); - public T11 Token11 { get => Get(11); set => Set(value, 11); } + public T11 Token11 { get => Get(11); set => ProtectedSet(value, 11); } public void AddBeforeToken12(GDSyntaxToken token) => AddMiddle(token, 12); - public T12 Token12 { get => Get(12); set => Set(value, 12); } + public T12 Token12 { get => Get(12); set => ProtectedSet(value, 12); } } public class GDTokensForm : GDTokensForm @@ -732,6 +813,50 @@ public class GDTokensForm GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + switch (statePoint) + { + case 0: return token is T0; + case 1: return token is T1; + case 2: return token is T2; + case 3: return token is T3; + case 4: return token is T4; + case 5: return token is T5; + case 6: return token is T6; + case 7: return token is T7; + case 8: return token is T8; + case 9: return token is T9; + case 10: return token is T10; + case 11: return token is T11; + case 12: return token is T12; + case 13: return token is T13; + default: + throw new IndexOutOfRangeException(); + } + } + + internal GDTokensForm(GDNode owner) : base(owner, 14) { @@ -739,33 +864,33 @@ internal GDTokensForm(GDNode owner) } public void AddBeforeToken0(GDSyntaxToken token) => AddMiddle(token, 0); - public T0 Token0 { get => Get(0); set => Set(value, 0); } + public T0 Token0 { get => Get(0); set => ProtectedSet(value, 0); } public void AddBeforeToken1(GDSyntaxToken token) => AddMiddle(token, 1); - public T1 Token1 { get => Get(1); set => Set(value, 1); } + public T1 Token1 { get => Get(1); set => ProtectedSet(value, 1); } public void AddBeforeToken2(GDSyntaxToken token) => AddMiddle(token, 2); - public T2 Token2 { get => Get(2); set => Set(value, 2); } + public T2 Token2 { get => Get(2); set => ProtectedSet(value, 2); } public void AddBeforeToken3(GDSyntaxToken token) => AddMiddle(token, 3); - public T3 Token3 { get => Get(3); set => Set(value, 3); } + public T3 Token3 { get => Get(3); set => ProtectedSet(value, 3); } public void AddBeforeToken4(GDSyntaxToken token) => AddMiddle(token, 4); - public T4 Token4 { get => Get(4); set => Set(value, 4); } + public T4 Token4 { get => Get(4); set => ProtectedSet(value, 4); } public void AddBeforeToken5(GDSyntaxToken token) => AddMiddle(token, 5); - public T5 Token5 { get => Get(5); set => Set(value, 5); } + public T5 Token5 { get => Get(5); set => ProtectedSet(value, 5); } public void AddBeforeToken6(GDSyntaxToken token) => AddMiddle(token, 6); - public T6 Token6 { get => Get(6); set => Set(value, 6); } + public T6 Token6 { get => Get(6); set => ProtectedSet(value, 6); } public void AddBeforeToken7(GDSyntaxToken token) => AddMiddle(token, 7); - public T7 Token7 { get => Get(7); set => Set(value, 7); } + public T7 Token7 { get => Get(7); set => ProtectedSet(value, 7); } public void AddBeforeToken8(GDSyntaxToken token) => AddMiddle(token, 8); - public T8 Token8 { get => Get(8); set => Set(value, 8); } + public T8 Token8 { get => Get(8); set => ProtectedSet(value, 8); } public void AddBeforeToken9(GDSyntaxToken token) => AddMiddle(token, 9); - public T9 Token9 { get => Get(9); set => Set(value, 9); } + public T9 Token9 { get => Get(9); set => ProtectedSet(value, 9); } public void AddBeforeToken10(GDSyntaxToken token) => AddMiddle(token, 10); - public T10 Token10 { get => Get(10); set => Set(value, 10); } + public T10 Token10 { get => Get(10); set => ProtectedSet(value, 10); } public void AddBeforeToken11(GDSyntaxToken token) => AddMiddle(token, 11); - public T11 Token11 { get => Get(11); set => Set(value, 11); } + public T11 Token11 { get => Get(11); set => ProtectedSet(value, 11); } public void AddBeforeToken12(GDSyntaxToken token) => AddMiddle(token, 12); - public T12 Token12 { get => Get(12); set => Set(value, 12); } + public T12 Token12 { get => Get(12); set => ProtectedSet(value, 12); } public void AddBeforeToken13(GDSyntaxToken token) => AddMiddle(token, 13); - public T13 Token13 { get => Get(13); set => Set(value, 13); } + public T13 Token13 { get => Get(13); set => ProtectedSet(value, 13); } } public abstract class GDTokensForm : GDTokensForm @@ -802,6 +927,13 @@ public abstract class GDTokensForm : ICollection protected readonly GDNode _owner; readonly int _initialSize; + public abstract Type[] Types { get; } + + public virtual bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + return Types[statePoint].IsAssignableFrom(token.GetType()); + } + internal GDTokensForm(GDNode owner, int size) { _owner = owner; @@ -839,7 +971,7 @@ public virtual void AddBeforeToken(GDSyntaxToken newToken, int statePointIndex) if (statePointIndex < _statePoints.Count) AddMiddle(newToken, statePointIndex); else - Add(newToken); + AddToEnd(newToken); } public virtual void AddBeforeToken(GDSyntaxToken newToken, GDSyntaxToken beforeThisToken) @@ -874,7 +1006,8 @@ public virtual void AddAfterToken(GDSyntaxToken newToken, GDSyntaxToken afterThi _list.AddAfter(node, newToken); } - public virtual void Add(GDSyntaxToken value) + void ICollection.Add(GDSyntaxToken item) => AddToEnd(item); + public virtual void AddToEnd(GDSyntaxToken value) { if (value is null) throw new System.ArgumentNullException(nameof(value)); @@ -901,7 +1034,29 @@ protected void AddMiddle(GDSyntaxToken value, int index) } } - protected void Set(GDSyntaxToken value, int index) + public void Set(GDSyntaxToken value, int index) + { + if (value != null && !IsTokenAppropriateForPoint(value, index)) + throw new InvalidCastException($"Unable to set token {value.TypeName} to State point with type {Types[index]}"); + + if (index >= _statePoints.Count) // Only for ListForm + return; + + var node = _statePoints[index]; + + if (node.Value == value) + return; + + if (node.Value != null) + node.Value.Parent = null; + + if (value != null) + value.Parent = _owner; + + node.Value = value; + } + + protected void ProtectedSet(GDSyntaxToken value, int index) { var node = _statePoints[index]; @@ -930,6 +1085,9 @@ void SetOrAdd(GDSyntaxToken value, int index) else { var node = _statePoints[index]; + + if (node.Value == value) + return; if (node.Value != null) node.Value.Parent = null; @@ -944,9 +1102,76 @@ void SetOrAdd(GDSyntaxToken value, int index) public T Get(int statePointIndex) where T : GDSyntaxToken => (T)_statePoints[statePointIndex].Value; public GDSyntaxToken Get(int index) => _statePoints[index].Value; + public void SetFormUnsafe(params GDSyntaxToken[] tokens) + { + Clear(); + + if (tokens == null || tokens.Length == 0) + return; + + if (_statePoints.Count == 0) // For List forms + { + for (int i = 0; i < tokens.Length; i++) + { + var token = tokens[i]; + + if (token == null || IsTokenAppropriateForPoint(token, StateIndex)) + { + var node = _list.AddLast(token); + _statePoints.Add(node); + StateIndex++; + } + else + { + _list.AddLast(token); + } + } + } + else // For typed forms + { + for (int i = 0; i < tokens.Length; i++) + { + var token = tokens[i]; + + if (StateIndex < _statePoints.Count) + { + if (token == null) + { + _statePoints[StateIndex++].Value = token; + } + else + { + bool inserted = false; + for (int index = StateIndex; index < _statePoints.Count; index++) + { + if (IsTokenAppropriateForPoint(token, index)) + { + _statePoints[index].Value = token; + StateIndex = index + 1; + inserted = true; + break; + } + } + + if (!inserted) + _list.AddBefore(_statePoints[StateIndex], token); + } + } + else + { + if (token == null) + throw new GDInvalidStateException("Cant add a null token when the node state is Completed"); + + _list.AddLast(token); + } + } + } + } + public void Clear() { + StateIndex = 0; foreach (var token in _list) { if (token != null) @@ -958,7 +1183,7 @@ public void Clear() if (_initialSize > 0) for (int i = 0; i < _initialSize; i++) - _statePoints[i] = _list.AddLast((GDSyntaxToken)null); + _statePoints.Add(_list.AddLast((GDSyntaxToken)null)); } public bool Contains(GDSyntaxToken item) diff --git a/src/GDShrapt.Reader/GDTokensListForm.cs b/src/GDShrapt.Reader/GDTokensListForm.cs new file mode 100644 index 0000000..1c7f16e --- /dev/null +++ b/src/GDShrapt.Reader/GDTokensListForm.cs @@ -0,0 +1,306 @@ +using System; +using System.Collections.Generic; + +namespace GDShrapt.Reader +{ + public class GDTokensListForm : GDTokensForm, IList + where TOKEN : GDSyntaxToken + { + static Type[] GenericTypes = new Type[] { typeof(TOKEN) }; + public override Type[] Types => GenericTypes; + + public override bool IsTokenAppropriateForPoint(GDSyntaxToken token, int statePoint) + { + return token is TOKEN; + } + + internal GDTokensListForm(GDNode owner) + : base(owner) + { + } + + public new int Count => _statePoints.Count; + public new int TokensCount => base.Count; + + public TOKEN this[int index] + { + get => (TOKEN)_statePoints[index].Value; + set + { + var node = _statePoints[index]; + + if (node.Value == value) + return; + + if (node.Value != null) + node.Value.Parent = null; + + if (value != null) + { + value.Parent = _owner; + node.Value = value; + } + else + node.Value = null; + } + } + + public void Add(TOKEN item) + { + item.Parent = _owner; + _statePoints.Add(_list.AddLast(item)); + StateIndex++; + } + + public override void AddToEnd(GDSyntaxToken value) + { + if (value is TOKEN token) + Add(token); + else + base.AddToEnd(value); + } + + public override void AddAfterToken(GDSyntaxToken newToken, GDSyntaxToken afterThisToken) + { + if (newToken is TOKEN token) + { + if (afterThisToken is TOKEN afterToken) + { + var node = _list.Find(afterToken); + + if (node == null) + throw new NullReferenceException("There is no specific token in the form"); + + var index = _statePoints.IndexOf(node); + + var nextIndex = index + 1; + + newToken.Parent = _owner; + + if (nextIndex == _statePoints.Count) + _statePoints.Add(_list.AddAfter(node, token)); + else + _statePoints.Insert(nextIndex, _list.AddAfter(node, token)); + } + else + { + var node = _list.Find(afterThisToken); + + if (node == null) + throw new NullReferenceException("There is no specific token in the form"); + + LinkedListNode nextTypedToken = null; + var next = node.Next; + while (next != null) + { + if (next.Value is TOKEN) + { + nextTypedToken = next; + break; + } + next = next.Next; + } + + newToken.Parent = _owner; + + if (nextTypedToken == null) + { + _statePoints.Add(_list.AddAfter(node, token)); + } + else + { + var index = _statePoints.IndexOf(nextTypedToken); + _statePoints.Insert(index, _list.AddAfter(node, token)); + } + } + } + else + { + base.AddAfterToken(newToken, afterThisToken); + } + } + + public override void AddBeforeToken(GDSyntaxToken newToken, GDSyntaxToken beforeThisToken) + { + if (newToken is TOKEN token) + { + if (beforeThisToken is TOKEN beforeToken) + { + var node = _list.Find(beforeToken); + + if (node == null) + throw new NullReferenceException("There is no specific token in the form"); + + var index = _statePoints.IndexOf(node); + + var previousIndex = index - 1; + newToken.Parent = _owner; + + _statePoints.Insert(previousIndex, _list.AddBefore(node, token)); + } + else + { + var node = _list.Find(beforeThisToken); + + if (node == null) + throw new NullReferenceException("There is no specific token in the form"); + + LinkedListNode nextTypedToken = null; + var next = node.Next; + while (next != null) + { + if (next.Value is TOKEN) + { + nextTypedToken = next; + break; + } + next = next.Next; + } + + newToken.Parent = _owner; + + if (nextTypedToken == null) + { + _statePoints.Add(_list.AddAfter(node, token)); + } + else + { + var index = _statePoints.IndexOf(nextTypedToken); + _statePoints.Insert(index, _list.AddAfter(node, token)); + } + } + } + else + { + base.AddBeforeToken(newToken, beforeThisToken); + } + } + + public override void AddBeforeToken(GDSyntaxToken newToken, int statePointIndex) + { + if (newToken is TOKEN token) + { + if (statePointIndex < _statePoints.Count) + { + var node = _statePoints[statePointIndex]; + newToken.Parent = _owner; + _statePoints.Insert(statePointIndex, _list.AddBefore(node, token)); + } + else + { + newToken.Parent = _owner; + _statePoints.Add(_list.AddLast(token)); + } + } + else + { + base.AddBeforeToken(newToken, statePointIndex); + } + } + + public bool Contains(TOKEN item) + { + if (item is null) + throw new ArgumentNullException(nameof(item)); + + return _list.Contains(item); + } + + public void CopyTo(TOKEN[] array, int arrayIndex) + { + for (int i = 0; i < _statePoints.Count; i++) + { + var node = _statePoints[i]; + + if (node == null || node.Value == null) + continue; + + array[arrayIndex++] = (TOKEN)node.Value; + } + } + + public int IndexOf(TOKEN item) + { + if (item is null) + throw new ArgumentNullException(nameof(item)); + + var node = _list.Find(item); + + if (node == null) + return -1; + + return _statePoints.IndexOf(node); + } + + public void Insert(int index, TOKEN item) + { + if (item is null) + throw new ArgumentNullException(nameof(item)); + + var node = _statePoints[index]; + var newNode = _list.AddBefore(node, item); + item.Parent = _owner; + _statePoints.Insert(index, newNode); + } + + public new void Clear() + { + var c = _statePoints.Count; + + for (int i = 0; i < c; i++) + { + var node = _statePoints[0]; + + if (node.Value != null) + node.Value.Parent = null; + + _list.Remove(node); + } + + _statePoints.Clear(); + } + + public void ClearAllTokens() => base.Clear(); + + public bool Remove(TOKEN item) + { + if (item is null) + throw new ArgumentNullException(nameof(item)); + + var node = _list.Find(item); + + if (node == null) + return false; + + item.Parent = null; + + _statePoints.Remove(node); + _list.Remove(node); + StateIndex--; + return true; + } + + public void RemoveAt(int index) + { + var node = _statePoints[index]; + + if (node.Value != null) + node.Value.Parent = null; + + _statePoints.RemoveAt(index); + _list.Remove(node); + StateIndex--; + } + + IEnumerator IEnumerable.GetEnumerator() + { + for (int i = 0; i < _statePoints.Count; i++) + yield return (TOKEN)_statePoints[i].Value; + } + + new IEnumerator GetEnumerator() + { + return base.GetEnumerator(); + } + } +} diff --git a/src/GDShrapt.Reader/Lists/GDClassAtributesList.cs b/src/GDShrapt.Reader/Lists/GDClassAtributesList.cs index 57d5097..4a21ccf 100644 --- a/src/GDShrapt.Reader/Lists/GDClassAtributesList.cs +++ b/src/GDShrapt.Reader/Lists/GDClassAtributesList.cs @@ -49,7 +49,7 @@ public override GDNode CreateEmptyInstance() void ITokenReceiver.HandleReceivedToken(GDClassAtribute token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDClassMembersList.cs b/src/GDShrapt.Reader/Lists/GDClassMembersList.cs index 40e20b0..a38b752 100644 --- a/src/GDShrapt.Reader/Lists/GDClassMembersList.cs +++ b/src/GDShrapt.Reader/Lists/GDClassMembersList.cs @@ -46,7 +46,7 @@ public override GDNode CreateEmptyInstance() void ITokenReceiver.HandleReceivedToken(GDClassMember token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDCommaSeparatedList.cs b/src/GDShrapt.Reader/Lists/GDCommaSeparatedList.cs index def2e9e..1c86459 100644 --- a/src/GDShrapt.Reader/Lists/GDCommaSeparatedList.cs +++ b/src/GDShrapt.Reader/Lists/GDCommaSeparatedList.cs @@ -13,14 +13,14 @@ internal override void HandleChar(char c, GDReadingState state) { if (IsSpace(c)) { - ListForm.Add(state.Push(new GDSpace())); + ListForm.AddToEnd(state.Push(new GDSpace())); state.PassChar(c); return; } if (c == ',') { - ListForm.Add(new GDComma()); + ListForm.AddToEnd(new GDComma()); return; } else @@ -37,22 +37,22 @@ internal override void HandleChar(char c, GDReadingState state) internal override void HandleNewLineChar(GDReadingState state) { - ListForm.Add(new GDNewLine()); + ListForm.AddToEnd(new GDNewLine()); } void INewLineReceiver.HandleReceivedToken(GDNewLine token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } void ITokenReceiver.HandleReceivedToken(GDNewLine token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } void ITokenReceiver.HandleReceivedToken(GDComma token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDDictionaryKeyValueDeclarationList.cs b/src/GDShrapt.Reader/Lists/GDDictionaryKeyValueDeclarationList.cs index 06e0239..9238b31 100644 --- a/src/GDShrapt.Reader/Lists/GDDictionaryKeyValueDeclarationList.cs +++ b/src/GDShrapt.Reader/Lists/GDDictionaryKeyValueDeclarationList.cs @@ -6,7 +6,7 @@ public sealed class GDDictionaryKeyValueDeclarationList : GDCommaSeparatedList.HandleReceivedToken(GDDictionaryKeyValueDeclaration token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDEnumValuesList.cs b/src/GDShrapt.Reader/Lists/GDEnumValuesList.cs index 485972f..00ea0a1 100644 --- a/src/GDShrapt.Reader/Lists/GDEnumValuesList.cs +++ b/src/GDShrapt.Reader/Lists/GDEnumValuesList.cs @@ -6,7 +6,7 @@ public sealed class GDEnumValuesList : GDCommaSeparatedList.HandleReceivedToken(GDEnumValueDeclaration token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDExportParametersList.cs b/src/GDShrapt.Reader/Lists/GDExportParametersList.cs index 4fdb8a8..57a456d 100644 --- a/src/GDShrapt.Reader/Lists/GDExportParametersList.cs +++ b/src/GDShrapt.Reader/Lists/GDExportParametersList.cs @@ -15,7 +15,7 @@ internal override GDReader ResolveNode() internal override void HandleNewLineChar(GDReadingState state) { - ListForm.Add(new GDNewLine()); + ListForm.AddToEnd(new GDNewLine()); } public override GDNode CreateEmptyInstance() @@ -24,7 +24,7 @@ public override GDNode CreateEmptyInstance() } void ITokenReceiver.HandleReceivedToken(GDDataToken token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDExpressionsList.cs b/src/GDShrapt.Reader/Lists/GDExpressionsList.cs index bb05433..3182d31 100644 --- a/src/GDShrapt.Reader/Lists/GDExpressionsList.cs +++ b/src/GDShrapt.Reader/Lists/GDExpressionsList.cs @@ -21,7 +21,7 @@ public override GDNode CreateEmptyInstance() void ITokenReceiver.HandleReceivedToken(GDExpression token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDIntendedTokensList.cs b/src/GDShrapt.Reader/Lists/GDIntendedTokensList.cs index 3e48781..0363b75 100644 --- a/src/GDShrapt.Reader/Lists/GDIntendedTokensList.cs +++ b/src/GDShrapt.Reader/Lists/GDIntendedTokensList.cs @@ -18,17 +18,17 @@ public GDIntendedTokensList() void IIntendedTokenReceiver.HandleReceivedToken(GDIntendation token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } void INewLineReceiver.HandleReceivedToken(GDNewLine token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } void ITokenReceiver.HandleReceivedToken(TOKEN token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDParametersList.cs b/src/GDShrapt.Reader/Lists/GDParametersList.cs index 24bf34c..9904e12 100644 --- a/src/GDShrapt.Reader/Lists/GDParametersList.cs +++ b/src/GDShrapt.Reader/Lists/GDParametersList.cs @@ -11,7 +11,7 @@ internal override bool IsStopChar(char c) internal override GDReader ResolveNode() { var node = new GDParameterDeclaration(); - ListForm.Add(node); + ListForm.AddToEnd(node); return node; } @@ -22,7 +22,7 @@ public override GDNode CreateEmptyInstance() void ITokenReceiver.HandleReceivedToken(GDParameterDeclaration token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDPathList.cs b/src/GDShrapt.Reader/Lists/GDPathList.cs index 65ffbe8..27cd850 100644 --- a/src/GDShrapt.Reader/Lists/GDPathList.cs +++ b/src/GDShrapt.Reader/Lists/GDPathList.cs @@ -39,13 +39,13 @@ public override GDNode CreateEmptyInstance() void ITokenReceiver.HandleReceivedToken(GDIdentifier token) { _switch = !_switch; - ListForm.Add(token); + ListForm.AddToEnd(token); } void ITokenReceiver.HandleReceivedToken(GDRightSlash token) { _switch = !_switch; - ListForm.Add(token); + ListForm.AddToEnd(token); } void ITokenSkipReceiver.HandleReceivedTokenSkip() { @@ -59,7 +59,7 @@ void ITokenSkipReceiver.HandleReceivedTokenSkip() void ITokenReceiver.HandleReceivedToken(GDSpace token) { - ListForm.Add(token); + ListForm.AddToEnd(token); } } } diff --git a/src/GDShrapt.Reader/Lists/GDSeparatedList.cs b/src/GDShrapt.Reader/Lists/GDSeparatedList.cs index 55e14af..9feb651 100644 --- a/src/GDShrapt.Reader/Lists/GDSeparatedList.cs +++ b/src/GDShrapt.Reader/Lists/GDSeparatedList.cs @@ -22,7 +22,7 @@ public GDSeparatedList() internal override void HandleSharpChar(GDReadingState state) { - Form.Add(state.Push(new GDComment())); + Form.AddToEnd(state.Push(new GDComment())); state.PassSharpChar(); } @@ -37,7 +37,7 @@ internal override void HandleSharpChar(GDReadingState state) public void Add(NODE item) { - _form.Add(item); + _form.AddToEnd(item); } public void Clear() diff --git a/src/GDShrapt.Reader/SimpleTokens/GDAssign.cs b/src/GDShrapt.Reader/SimpleTokens/GDAssign.cs index e6d6538..04e8a14 100644 --- a/src/GDShrapt.Reader/SimpleTokens/GDAssign.cs +++ b/src/GDShrapt.Reader/SimpleTokens/GDAssign.cs @@ -1,6 +1,6 @@ namespace GDShrapt.Reader { - public sealed class GDAssign : GDSingleCharToken, IGDStructureToken + public sealed class GDAssign : GDPairToken, IGDStructureToken { public override char Char => '='; diff --git a/src/GDShrapt.Reader/SimpleTokens/GDColon.cs b/src/GDShrapt.Reader/SimpleTokens/GDColon.cs index 8ff3019..cddeb99 100644 --- a/src/GDShrapt.Reader/SimpleTokens/GDColon.cs +++ b/src/GDShrapt.Reader/SimpleTokens/GDColon.cs @@ -1,6 +1,6 @@ namespace GDShrapt.Reader { - public sealed class GDColon : GDSingleCharToken, IGDStructureToken + public sealed class GDColon : GDPairToken, IGDStructureToken { public override char Char => ':'; diff --git a/src/GDShrapt.Reader/SimpleTokens/GDPairToken.cs b/src/GDShrapt.Reader/SimpleTokens/GDPairToken.cs new file mode 100644 index 0000000..b785322 --- /dev/null +++ b/src/GDShrapt.Reader/SimpleTokens/GDPairToken.cs @@ -0,0 +1,6 @@ +namespace GDShrapt.Reader +{ + public abstract class GDPairToken : GDSingleCharToken + { + } +} \ No newline at end of file