Skip to content

Commit

Permalink
Improved same line attributes parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
elamaunt committed Jan 28, 2024
1 parent f04f6c0 commit 63f00e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/GDShrapt.Reader.Tests/InvalidTokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ extends ResourceFormatSaver

@class.AllInvalidTokens.Select(x => x.ToString()).Should().BeEquivalentTo(new string[]
{
"123H+=Ter^5r3_-ain-DataSaver"
"123",
"H+=Ter^5r3_-ain-DataSaver"
});
}
}
Expand Down
70 changes: 27 additions & 43 deletions src/GDShrapt.Reader/Resolvers/GDClassMembersResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GDShrapt.Reader
{
internal class GDClassMembersResolver : GDIntendedResolver
{
bool _memberResolved;
bool _handleEndOfTheLineAsInvalid;

readonly StringBuilder _sequenceBuilder = new StringBuilder();

Expand All @@ -22,7 +22,7 @@ public GDClassMembersResolver(IIntendedTokenReceiver<GDClassMember> owner, int l

internal override void HandleCharAfterIntendation(char c, GDReadingState state)
{
if (_memberResolved)
if (_handleEndOfTheLineAsInvalid)
{
if (IsSpace(c))
{
Expand Down Expand Up @@ -83,7 +83,7 @@ internal override void HandleNewLineAfterIntendation(GDReadingState state)
return;
}

_memberResolved = false;
_handleEndOfTheLineAsInvalid = false;
ResetIntendation();
state.PassNewLine();
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private void Complete(GDReadingState state, string sequence)
return;
}

_memberResolved = true;
_handleEndOfTheLineAsInvalid = true;

void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool invalid = true)
{
Expand Down Expand Up @@ -193,30 +193,38 @@ void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool
{
case "@icon":
{
Owner.HandleReceivedToken(state.Push(new GDCustomAttribute()));
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
var a = new GDCustomAttribute();
HandleStaticIfMet(a, () => Owner.HandleReceivedToken(state.Push(a)));
a.Add(new GDAttribute().AddAt().Add(new GDIdentifier() { Sequence = "icon" }));

_handleEndOfTheLineAsInvalid = false;
}
break;
case "class_name":
{
Owner.HandleReceivedToken(state.Push(new GDClassNameAttribute()));
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
var a = new GDClassNameAttribute();
HandleStaticIfMet(a, () => Owner.HandleReceivedToken(state.Push(a)));
a.Add(new GDClassNameKeyword());

_handleEndOfTheLineAsInvalid = false;
}
break;
case "extends":
{
Owner.HandleReceivedToken(state.Push(new GDExtendsAttribute()));
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
var a = new GDExtendsAttribute();
HandleStaticIfMet(a, () => Owner.HandleReceivedToken(state.Push(a)));
a.Add(new GDExtendsKeyword());

_handleEndOfTheLineAsInvalid = false;
}
break;
case "tool":
{
Owner.HandleReceivedToken(state.Push(new GDToolAttribute()));
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
var a = new GDToolAttribute();
HandleStaticIfMet(a, () => Owner.HandleReceivedToken(state.Push(a)));
a.Add(new GDToolKeyword());

_handleEndOfTheLineAsInvalid = false;
}
break;
case "signal":
Expand All @@ -235,7 +243,7 @@ void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool
break;
case "static":
{
_memberResolved = false;
_handleEndOfTheLineAsInvalid = false;
_sequenceBuilder.Clear();

if (_staticMet)
Expand All @@ -259,30 +267,6 @@ void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool
m.Add(new GDFuncKeyword());
}
break;
/* case "export":
{
var m = new GDMethodDeclaration(LineIntendationThreshold);
_memberResolved = false;
Owner.HandleReceivedToken(state.Push(new GDClassMemberAttributeDeclaration(LineIntendationThreshold)));
if (sequence != null)
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
return;
}
case "onready":
{
var m = new GDMethodDeclaration(LineIntendationThreshold);
_memberResolved = false;
Owner.HandleReceivedToken(state.Push(new GDClassMemberAttributeDeclaration(LineIntendationThreshold)));
if (sequence != null)
for (int i = 0; i < sequence.Length; i++)
state.PassChar(sequence[i]);
return;
}*/
case "const":
{
var m = new GDVariableDeclaration(LineIntendationThreshold);
Expand All @@ -306,7 +290,7 @@ void HandleStaticIfMet(ITokenReceiver<GDSpace> spaceReceiver, Action push, bool
break;
default:
{
_memberResolved = false;
_handleEndOfTheLineAsInvalid = false;

HandleStaticIfMet(null, () => Owner.HandleReceivedToken(state.Push(new GDInvalidToken(x => x.IsSpace() || x.IsNewLine()))));

Expand All @@ -329,7 +313,7 @@ internal override void ForceComplete(GDReadingState state)
return;
}

if (!_memberResolved)
if (!_handleEndOfTheLineAsInvalid)
SendIntendationTokensToOwner();
base.ForceComplete(state);
}
Expand Down

0 comments on commit 63f00e7

Please sign in to comment.