Skip to content

Commit

Permalink
WIP: completed tokens receiving handling for List nodes. Working with…
Browse files Browse the repository at this point in the history
… unspecified content resolving
  • Loading branch information
elamaunt committed Jul 18, 2021
1 parent 48bba4b commit 4965ce2
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 20 deletions.
10 changes: 6 additions & 4 deletions src/GDShrapt.Reader/GDScriptReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -105,10 +106,11 @@ public GDStatement ParseStatement(string content)

public List<GDSyntaxToken> ParseUnspecifiedContent(string content)
{
var state = new GDReadingState(Settings);
throw new NotImplementedException();
/*var state = new GDReadingState(Settings);
var receiver = new GDReceiver();
state.Push(new GDContentResolver(receiver, 0));
state.Push(new GDContentResolver(receiver));
var buffer = new char[Settings.ReadBufferSize];
int count = 0;
Expand All @@ -120,7 +122,7 @@ public List<GDSyntaxToken> ParseUnspecifiedContent(string content)
}
state.CompleteReading();
return receiver.Tokens;
return receiver.Tokens;*/
}

private void ParseBuffer(char[] buffer, int count, GDReadingState state)
Expand Down
78 changes: 68 additions & 10 deletions src/GDShrapt.Reader/Resolvers/GDContentResolver.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,86 @@
namespace GDShrapt.Reader
using System.Text;

namespace GDShrapt.Reader
{
internal class GDContentResolver : GDIntendedResolver
internal class GDContentResolver : GDResolver
{
new IIntendedTokenReceiver<GDNode> Owner { get; }
public GDContentResolver(IIntendedTokenReceiver<GDNode> owner, int lineIntendation)
: base(owner, lineIntendation)

readonly StringBuilder _sequence = new StringBuilder();

GDSpace _lastSpace;

public GDContentResolver(IIntendedTokenReceiver<GDNode> owner)
: base(owner)
{
Owner = owner;
}


internal override void HandleCharAfterIntendation(char c, GDReadingState state)
internal override void HandleChar(char c, GDReadingState state)
{
throw new System.NotImplementedException();
if (IsSpace(c))
{
if (_sequence.Length == 0)
{
state.PushAndPass(_lastSpace = new GDSpace(), c);
}
else
{
HandleSequence(_sequence.ToString());
}
}
else
{
//if (char.

if (char.IsLetter(c))
{
_sequence.Append(c);
return;
}
}
}

internal override void HandleNewLineAfterIntendation(GDReadingState state)
private void HandleSequence(string seq)
{
throw new System.NotImplementedException();

}

internal override void HandleSharpCharAfterIntendation(GDReadingState state)
internal override void HandleNewLineChar(GDReadingState state)
{
throw new System.NotImplementedException();
if (_sequence.Length == 0)
{
if (_lastSpace != null)
{
Owner.HandleReceivedToken(_lastSpace);
_lastSpace = null;
}

Owner.AddNewLine();
}
else
{
HandleSequence(_sequence.ToString());
}
}

internal override void HandleSharpChar(GDReadingState state)
{
if (_sequence.Length == 0)
{
if (_lastSpace != null)
{
Owner.HandleReceivedToken(_lastSpace);
_lastSpace = null;
}

Owner.HandleReceivedToken(state.PushAndPass(new GDComment(), '#'));
}
else
{
HandleSequence(_sequence.ToString());
}
}
}
}
26 changes: 25 additions & 1 deletion src/GDShrapt.Reader/Statements/GDForStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public sealed class GDForStatement : GDStatement,
ITokenOrSkipReceiver<GDInKeyword>,
ITokenOrSkipReceiver<GDIdentifier>,
ITokenOrSkipReceiver<GDColon>,
ITokenOrSkipReceiver<GDExpression>
ITokenOrSkipReceiver<GDExpression>,
ITokenOrSkipReceiver<GDStatementsList>
{
public GDForKeyword ForKeyword
{
Expand Down Expand Up @@ -272,5 +273,28 @@ void ITokenSkipReceiver<GDIdentifier>.HandleReceivedTokenSkip()

throw new GDInvalidStateException();
}

void ITokenReceiver<GDStatementsList>.HandleReceivedToken(GDStatementsList token)
{
if (_form.IsOrLowerState(State.Statements))
{
Statements = token;
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDStatementsList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}
}
}
28 changes: 28 additions & 0 deletions src/GDShrapt.Reader/Statements/GDIfStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public sealed class GDIfStatement : GDStatement,
IIntendedTokenOrSkipReceiver<GDIfBranch>,
IIntendedTokenOrSkipReceiver<GDElifBranchesList>,
IIntendedTokenOrSkipReceiver<GDElseBranch>
{
bool _waitForEndLine = true;
Expand Down Expand Up @@ -103,6 +104,7 @@ void ITokenReceiver<GDIfBranch>.HandleReceivedToken(GDIfBranch token)
if (_form.IsOrLowerState(State.IfBranch))
{
IfBranch = token;
_form.State = State.ElifBranches;
return;
}

Expand All @@ -112,7 +114,33 @@ void ITokenReceiver<GDIfBranch>.HandleReceivedToken(GDIfBranch token)
void ITokenSkipReceiver<GDIfBranch>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.IfBranch))
{
_form.State = State.ElifBranches;
return;
}

throw new GDInvalidStateException();
}

void ITokenReceiver<GDElifBranchesList>.HandleReceivedToken(GDElifBranchesList token)
{
if (_form.IsOrLowerState(State.ElifBranches))
{
ElifBranchesList = token;
_form.State = State.ElseBranch;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDElifBranchesList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.ElifBranches))
{
_form.State = State.ElseBranch;
return;
}

throw new GDInvalidStateException();
}
Expand Down
26 changes: 25 additions & 1 deletion src/GDShrapt.Reader/Statements/GDMatchStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public sealed class GDMatchStatement : GDStatement,
ITokenOrSkipReceiver<GDMatchKeyword>,
ITokenOrSkipReceiver<GDColon>,
ITokenOrSkipReceiver<GDExpression>
ITokenOrSkipReceiver<GDExpression>,
ITokenOrSkipReceiver<GDMatchCasesList>
{
public GDMatchKeyword MatchKeyword
{
Expand Down Expand Up @@ -169,5 +170,28 @@ void ITokenSkipReceiver<GDExpression>.HandleReceivedTokenSkip()

throw new GDInvalidStateException();
}

void ITokenReceiver<GDMatchCasesList>.HandleReceivedToken(GDMatchCasesList token)
{
if (_form.IsOrLowerState(State.Cases))
{
Cases = token;
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDMatchCasesList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Cases))
{
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}
}
}
26 changes: 25 additions & 1 deletion src/GDShrapt.Reader/Statements/GDWhileStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace GDShrapt.Reader
public sealed class GDWhileStatement : GDStatement,
ITokenOrSkipReceiver<GDWhileKeyword>,
ITokenOrSkipReceiver<GDExpression>,
ITokenOrSkipReceiver<GDColon>
ITokenOrSkipReceiver<GDColon>,
ITokenOrSkipReceiver<GDStatementsList>
{
public GDWhileKeyword WhileKeyword
{
Expand Down Expand Up @@ -196,5 +197,28 @@ void ITokenSkipReceiver<GDColon>.HandleReceivedTokenSkip()

throw new GDInvalidStateException();
}

void ITokenReceiver<GDStatementsList>.HandleReceivedToken(GDStatementsList token)
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
Statements = token;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDStatementsList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}
}
}
26 changes: 25 additions & 1 deletion src/GDShrapt.Reader/Statements/IfStatement/GDElifBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public sealed class GDElifBranch : GDNode,
ITokenOrSkipReceiver<GDElifKeyword>,
ITokenOrSkipReceiver<GDExpression>,
ITokenOrSkipReceiver<GDColon>
ITokenOrSkipReceiver<GDColon>,
ITokenOrSkipReceiver<GDStatementsList>
{
public GDElifKeyword ElifKeyword
{
Expand Down Expand Up @@ -188,5 +189,28 @@ void ITokenSkipReceiver<GDExpression>.HandleReceivedTokenSkip()

throw new GDInvalidStateException();
}

void ITokenReceiver<GDStatementsList>.HandleReceivedToken(GDStatementsList token)
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
Statements = token;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDStatementsList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}
}
}
26 changes: 25 additions & 1 deletion src/GDShrapt.Reader/Statements/IfStatement/GDElseBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public sealed class GDElseBranch : GDNode,
ITokenOrSkipReceiver<GDElseKeyword>,
ITokenOrSkipReceiver<GDColon>,
ITokenOrSkipReceiver<GDExpression>
ITokenOrSkipReceiver<GDExpression>,
ITokenOrSkipReceiver<GDStatementsList>
{
public GDElseKeyword ElseKeyword
{
Expand Down Expand Up @@ -166,5 +167,28 @@ void ITokenSkipReceiver<GDExpression>.HandleReceivedTokenSkip()

throw new GDInvalidStateException();
}

void ITokenReceiver<GDStatementsList>.HandleReceivedToken(GDStatementsList token)
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
Statements = token;
return;
}

throw new GDInvalidStateException();
}

void ITokenSkipReceiver<GDStatementsList>.HandleReceivedTokenSkip()
{
if (_form.IsOrLowerState(State.Statements))
{
_form.State = State.Completed;
return;
}

throw new GDInvalidStateException();
}
}
}
Loading

0 comments on commit 4965ce2

Please sign in to comment.