Skip to content

Commit

Permalink
ClassName invalid token fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elamaunt committed Dec 23, 2023
1 parent 9ec9a7b commit 3b993a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
23 changes: 22 additions & 1 deletion src/GDShrapt.Reader.Tests/InvalidTokenTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace GDShrapt.Reader.Tests
Expand Down Expand Up @@ -35,5 +36,25 @@ public void DoubleStaticTest()
Assert.AreEqual("static", declaration.AllInvalidTokens.First().Sequence);
AssertHelper.CompareCodeStrings(code, declaration.ToString());
}

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

var code = @"tool
class_name 123H+=Ter^5r3_-ain-DataSaver
extends ResourceFormatSaver
";

var @class = reader.ParseFileContent(code);
Assert.IsNotNull(@class);

@class.AllInvalidTokens.Select(x => x.ToString()).Should().BeEquivalentTo(new string[]
{
"123",
"H+=Ter^5r3_-ain-DataSaver"
});
}
}
}
5 changes: 1 addition & 4 deletions src/GDShrapt.Reader/GDReadingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ internal class GDReadingState
{
public GDReadSettings Settings { get; }

private readonly StackTrace _stackTrace;

/// <summary>
/// Main reading stack
/// </summary>
Expand All @@ -23,7 +21,6 @@ internal class GDReadingState
public GDReadingState(GDReadSettings settings)
{
Settings = settings;
_stackTrace = new StackTrace(false);
}

/// <summary>
Expand Down Expand Up @@ -121,7 +118,7 @@ public T Push<T>(T reader)
if (Settings.MaxReadingStack.HasValue && _readersStack.Count == Settings.MaxReadingStack.Value)
throw new StackOverflowException("Maximum reading reading stack is reached.");

if (Settings.MaxStacktraceFramesCount.HasValue && _stackTrace.FrameCount >= Settings.MaxStacktraceFramesCount.Value)
if (Settings.MaxStacktraceFramesCount.HasValue && new StackTrace(false).FrameCount >= Settings.MaxStacktraceFramesCount.Value)
throw new StackOverflowException("Maximum stackTrace frames count is reached.");

_readersStack.Push(reader);
Expand Down
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader/GDShrapt.Reader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0</AssemblyVersion>
<FileVersion>4.0.0</FileVersion>
<AssemblyVersion>4.0.1</AssemblyVersion>
<FileVersion>4.0.1</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/GDShrapt.Reader/Resolvers/GDClassMembersResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal override void HandleCharAfterIntendation(char c, GDReadingState state)
else
{
SendIntendationTokensToOwner();
Owner.HandleReceivedToken(state.Push(new GDInvalidToken(x => x != '@' || char.IsLetter(x) || x.IsSpace() || x.IsNewLine())));
Owner.HandleReceivedToken(state.Push(new GDInvalidToken(x => x == '@' || char.IsLetter(x) || x.IsSpace() || x.IsNewLine())));
}

state.PassChar(c);
Expand Down

0 comments on commit 3b993a0

Please sign in to comment.