-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved properties parsing. Fixed comma bugs
- Loading branch information
Showing
4 changed files
with
222 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
229 changes: 172 additions & 57 deletions
229
src/GDShrapt.Reader/Resolvers/GDSetGetAccessorsResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,209 @@ | ||
namespace GDShrapt.Reader | ||
using System.Text; | ||
|
||
namespace GDShrapt.Reader | ||
{ | ||
internal class GDSetGetAccessorsResolver<T> : GDIntendedPatternResolver | ||
internal class GDSetGetAccessorsResolver<T> : GDIntendedResolver | ||
where T : IIntendedTokenOrSkipReceiver<GDAccessorDeclaration> | ||
{ | ||
public new T Owner { get; } | ||
|
||
public GDSetGetAccessorsResolver(T owner, bool allowZeroIntendationOnFirstLine, int lineIntendation) | ||
: base(owner, lineIntendation) | ||
readonly StringBuilder _sequenceBuilder = new StringBuilder(8); | ||
|
||
State _state = State.Initial; | ||
bool _ignoreNewLine; | ||
|
||
private enum State | ||
{ | ||
AllowZeroIntendationOnFirstLine = allowZeroIntendationOnFirstLine; | ||
Owner = owner; | ||
Initial, | ||
GotSetKeyword, | ||
GotGetKeyword, | ||
} | ||
|
||
public override string[] GeneratePatterns() | ||
public GDSetGetAccessorsResolver(T owner, bool allowZeroIntendationOnFirstLine, int lineIntendation) | ||
: base(owner, lineIntendation) | ||
{ | ||
return new string[] | ||
{ | ||
"get", | ||
"set", | ||
|
||
"get=", | ||
"set=", | ||
|
||
"get:", | ||
"set(" | ||
}; | ||
AllowZeroIntendationOnFirstLine = allowZeroIntendationOnFirstLine; | ||
Owner = owner; | ||
} | ||
|
||
protected override void PatternMatched(string pattern, GDReadingState state) | ||
internal override void HandleCharAfterIntendation(char c, GDReadingState state) | ||
{ | ||
if (pattern != null) | ||
SendIntendationTokensToOwner(); | ||
|
||
switch (pattern) | ||
switch (_sequenceBuilder.Length) | ||
{ | ||
case "set": | ||
case 0: | ||
if (c == 's') | ||
{ | ||
// TODO: check the colon | ||
var accessor = new GDSetAccessorMethodDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
_sequenceBuilder.Append(c); | ||
_state = State.GotSetKeyword; | ||
} | ||
case "set=": | ||
else if (c == 'g') | ||
{ | ||
var accessor = new GDSetAccessorMethodDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
_sequenceBuilder.Append(c); | ||
_state = State.GotGetKeyword; | ||
} | ||
case "set(": | ||
else | ||
{ | ||
// TODO: check spaces | ||
var accessor = new GDSetAccessorBodyDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
Owner.HandleReceivedTokenSkip(); | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
state.PassChar(c); | ||
} | ||
case "get": | ||
break; | ||
case 1: | ||
if (c == 'e') | ||
{ | ||
// TODO: check the colon | ||
var accessor = new GDGetAccessorMethodDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
_sequenceBuilder.Append(c); | ||
} | ||
case "get=": | ||
else | ||
{ | ||
Owner.HandleReceivedTokenSkip(); | ||
|
||
state.Pop(); | ||
PassIntendationSequence(state); | ||
state.PassChar(_sequenceBuilder[0]); | ||
state.PassChar(c); | ||
} | ||
break; | ||
case 2: | ||
if (c == 't') | ||
{ | ||
_sequenceBuilder.Append(c); | ||
} | ||
else | ||
{ | ||
Owner.HandleReceivedTokenSkip(); | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
state.PassChar(_sequenceBuilder[0]); | ||
state.PassChar(_sequenceBuilder[1]); | ||
state.PassChar(c); | ||
} | ||
break; | ||
default: | ||
if (c.IsSpace()) | ||
{ | ||
_sequenceBuilder.Append(c); | ||
return; | ||
} | ||
|
||
if (_state == State.GotGetKeyword && c == ':') | ||
{ | ||
var accessor = new GDGetAccessorMethodDeclaration(LineIntendationThreshold); | ||
SendIntendationTokensToOwner(); | ||
state.Pop(); | ||
var accessor = new GDGetAccessorBodyDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
PassStoredSequence(state); | ||
state.PassChar(c); | ||
return; | ||
} | ||
case "get:": | ||
|
||
if (_state == State.GotSetKeyword && c == '(') | ||
{ | ||
var accessor = new GDGetAccessorBodyDeclaration(LineIntendationThreshold); | ||
SendIntendationTokensToOwner(); | ||
state.Pop(); | ||
var accessor = new GDSetAccessorBodyDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
state.Push(accessor); | ||
break; | ||
PassStoredSequence(state); | ||
state.PassChar(c); | ||
return; | ||
} | ||
default: | ||
|
||
if (c == '=') | ||
{ | ||
SendIntendationTokensToOwner(); | ||
state.Pop(); | ||
|
||
GDReader reader; | ||
if (_state == State.GotGetKeyword) | ||
{ | ||
var accessor = new GDGetAccessorMethodDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
reader = accessor; | ||
} | ||
else | ||
{ | ||
var accessor = new GDSetAccessorMethodDeclaration(LineIntendationThreshold); | ||
Owner.HandleReceivedToken(accessor); | ||
reader = accessor; | ||
} | ||
|
||
state.Push(reader); | ||
PassStoredSequence(state); | ||
state.PassChar(c); | ||
|
||
return; | ||
} | ||
|
||
Owner.HandleReceivedTokenSkip(); | ||
break; | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
PassStoredSequence(state); | ||
state.PassChar(c); | ||
return; | ||
} | ||
} | ||
|
||
protected override void OnIntendationThresholdMet(GDReadingState state) | ||
{ | ||
Owner.HandleReceivedTokenSkip(); | ||
base.OnIntendationThresholdMet(state); | ||
} | ||
|
||
internal override void HandleNewLineAfterIntendation(GDReadingState state) | ||
{ | ||
if (_ignoreNewLine) | ||
{ | ||
_sequenceBuilder.Append('\n'); | ||
_ignoreNewLine = false; | ||
return; | ||
} | ||
|
||
if (pattern != null) | ||
Owner.HandleReceivedTokenSkip(); | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
PassStoredSequence(state); | ||
state.PassNewLine(); | ||
} | ||
|
||
internal override void HandleSharpCharAfterIntendation(GDReadingState state) | ||
{ | ||
Owner.HandleReceivedTokenSkip(); | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
PassStoredSequence(state); | ||
state.PassSharpChar(); | ||
} | ||
|
||
internal override void HandleLeftSlashCharAfterIntendation(GDReadingState state) | ||
{ | ||
if (_sequenceBuilder.Length < 3) | ||
{ | ||
for (int i = 0; i < pattern.Length; i++) | ||
state.PassChar(pattern[i]); | ||
Owner.HandleReceivedTokenSkip(); | ||
state.Pop(); | ||
PassIntendationSequence(state); | ||
PassStoredSequence(state); | ||
state.PassLeftSlashChar(); | ||
return; | ||
} | ||
|
||
_sequenceBuilder.Append('\\'); | ||
_ignoreNewLine = true; | ||
} | ||
|
||
private void PassStoredSequence(GDReadingState state) | ||
{ | ||
for (int i = 0; i < _sequenceBuilder.Length; i++) | ||
state.PassChar(_sequenceBuilder[i]); | ||
} | ||
|
||
internal override void ForceComplete(GDReadingState state) | ||
{ | ||
base.ForceComplete(state); | ||
Owner.HandleReceivedTokenSkip(); | ||
PassIntendationSequence(state); | ||
PassStoredSequence(state); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters