Skip to content

Commit

Permalink
Fixed static parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
elamaunt committed Jan 20, 2024
1 parent 924c23d commit b15e4a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
30 changes: 30 additions & 0 deletions src/GDShrapt.Reader.Tests/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,5 +2620,35 @@ func curry_test(f):
AssertHelper.CompareCodeStrings(code, @class.ToString());
AssertHelper.NoInvalidTokens(@class);
}

[TestMethod]
public void ParseStaticsTest()
{
var reader = new GDScriptReader();

var code = @"
class_name A
static var a = ""Hello""
static func my_int_function() -> int:
return 0";

var @class = reader.ParseFileContent(code);

Assert.AreEqual(2, @class.Members.Count);

var variable = (GDVariableDeclaration)@class.Members[0];
var method = (GDMethodDeclaration)@class.Members[1];

Assert.AreEqual(true, variable.IsStatic);
Assert.AreEqual(true, method.IsStatic);

Assert.AreEqual("static var a = \"Hello\"", variable.ToString());
Assert.AreEqual("my_int_function", method.Identifier.Sequence);

AssertHelper.CompareCodeStrings(code, @class.ToString());
AssertHelper.NoInvalidTokens(@class);
}
}
}
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader/Declarations/GDVariableDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public GDAccessorDeclaration SecondAccessorDeclarationNode
}

public bool IsConstant => ConstKeyword != null;
public override bool IsStatic => false;
public override bool IsStatic => StaticKeyword != null;

public enum State
{
Expand Down Expand Up @@ -226,7 +226,7 @@ void ITokenSkipReceiver<GDConstKeyword>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Const))
{
_form.State = State.Var;
_form.State = State.Static;
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/GDShrapt.Reader/GDShrapt.Reader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>4.1.2-alpha</Version>
<Version>4.1.3-alpha</Version>
<Authors>elamaunt</Authors>
<Product>GDShrapt</Product>
<Description>GDShrapt.Reader is .Net library and object-oriented one-pass parser of GDScript. It can build a lexical tree of GDScript code or generate a new code from scratch.
Expand All @@ -16,8 +16,8 @@ Usage: Just create a GDScriptReader instance and call methods from it.</Descript
<RepositoryUrl>https://github.com/elamaunt/GDShrapt</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>GDShrapt GDScript reader parser codegeneration Godot lexical analyzer</PackageTags>
<AssemblyVersion>4.1.2</AssemblyVersion>
<FileVersion>4.1.2</FileVersion>
<AssemblyVersion>4.1.3</AssemblyVersion>
<FileVersion>4.1.3</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/GDShrapt.Reader/Resolvers/GDClassMembersResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool
_spaceAfterStatic = null;
}
}

_staticMet = false;
}

switch (sequence)
Expand Down

0 comments on commit b15e4a7

Please sign in to comment.