Skip to content

Commit

Permalink
WIP: All tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
elamaunt committed Dec 20, 2023
1 parent f75f241 commit b8a51f3
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 143 deletions.
41 changes: 20 additions & 21 deletions src/GDShrapt.Reader.Tests/BigScriptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,33 @@ public void BigScriptParsingTest()
AssertHelper.NoInvalidTokens(declaration);
}

/* [TestMethod]
public void BigScriptParsingTest2()
{
var reader = new GDScriptReader();
[TestMethod]
public void BigScriptParsingTest2()
{
var reader = new GDScriptReader();

var path = Path.Combine("Scripts", "Sample2.gd");
var declaration = reader.ParseFile(path);
var path = Path.Combine("Scripts", "Sample2.gd");
var declaration = reader.ParseFile(path);

var fileText = File.ReadAllText(path);
var fileText = File.ReadAllText(path);

AssertHelper.CompareCodeStrings(fileText, declaration.ToString());
AssertHelper.NoInvalidTokens(declaration);
}
AssertHelper.CompareCodeStrings(fileText, declaration.ToString());
AssertHelper.NoInvalidTokens(declaration);
}

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

var path = Path.Combine("Scripts", "Sample3.gd");
var declaration = reader.ParseFile(path);
var path = Path.Combine("Scripts", "Sample3.gd");
var declaration = reader.ParseFile(path);

var fileText = File.ReadAllText(path);
var fileText = File.ReadAllText(path);

AssertHelper.CompareCodeStrings(fileText, declaration.ToString());
AssertHelper.NoInvalidTokens(declaration);
<<<<<<< Updated upstream
}*/
AssertHelper.CompareCodeStrings(fileText, declaration.ToString());
AssertHelper.NoInvalidTokens(declaration);
}

[TestMethod]
public void BigScriptParsingTest4()
Expand Down
69 changes: 61 additions & 8 deletions src/GDShrapt.Reader.Tests/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ public void StringTest()
var stringExpression = (GDStringExpression)statement;

Assert.IsNotNull(stringExpression.String);
Assert.IsFalse(stringExpression.String.Multiline);
Assert.AreEqual(GDStringBoundingChar.DoubleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual("test", stringExpression.String.Sequence);

Expand All @@ -640,7 +639,6 @@ public void StringTest2()
var stringExpression = (GDStringExpression)statement;

Assert.IsNotNull(stringExpression.String);
Assert.IsFalse(stringExpression.String.Multiline);
Assert.AreEqual(GDStringBoundingChar.SingleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual("te\"\"st", stringExpression.String.Sequence);

Expand All @@ -649,7 +647,7 @@ public void StringTest2()
}

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

Expand All @@ -663,16 +661,72 @@ public void MultilineStringTest()
var stringExpression = (GDStringExpression)statement;

Assert.IsNotNull(stringExpression.String);
Assert.IsTrue(stringExpression.String.Multiline);
Assert.AreEqual(GDStringBoundingChar.DoubleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual(GDStringBoundingChar.TripleDoubleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual("te\"\"st", stringExpression.String.Sequence);

AssertHelper.CompareCodeStrings(code, statement.ToString());
AssertHelper.NoInvalidTokens(statement);
}

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

var code = @"func _ready():
var s = ""Hello\\
World""
var s2 = ""Hello\
World""
var s3 = """"""Hello\
World""""""
var s4 = """"""Hello\\\
World""""""
var s5 = """"""Hello\\
World""""""
print(s)
print(s2)
print(s3)
print(s4)
print(s5)
pass # Replace with function body.";

var @class = reader.ParseFileContent(code);

Assert.IsNotNull(@class);

var stringExpressions = @class.AllNodes.OfType<GDStringExpression>().ToArray();

Assert.AreEqual(5, stringExpressions.Length);

var s = stringExpressions[0].String;
var s2 = stringExpressions[1].String;
var s3 = stringExpressions[2].String;
var s4 = stringExpressions[3].String;
var s5 = stringExpressions[4].String;

Assert.IsNotNull(s);
Assert.IsNotNull(s2);
Assert.IsNotNull(s3);
Assert.IsNotNull(s4);
Assert.IsNotNull(s5);

Assert.AreEqual("Hello\\\\\nWorld", s.Sequence);
Assert.AreEqual("HelloWorld", s2.Sequence);
Assert.AreEqual("HelloWorld", s3.Sequence);
Assert.AreEqual("Hello\\\\World", s4.Sequence);
Assert.AreEqual("Hello\\\\\nWorld", s5.Sequence);

AssertHelper.CompareCodeStrings(code, @class.ToString());
AssertHelper.NoInvalidTokens(@class);
}

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

Expand All @@ -686,8 +740,7 @@ public void MultilineStringTest2()
var stringExpression = (GDStringExpression)statement;

Assert.IsNotNull(stringExpression.String);
Assert.IsTrue(stringExpression.String.Multiline);
Assert.AreEqual(GDStringBoundingChar.SingleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual(GDStringBoundingChar.TripleSingleQuotas, stringExpression.String.BoundingChar);
Assert.AreEqual("te'\"st", stringExpression.String.Sequence);

AssertHelper.CompareCodeStrings(code, statement.ToString());
Expand Down
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader.Tests/Scripts/Sample2.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const CHUNK_MIDPOINT = Vector3(0.5, 0.5, 0.5) * Chunk.CHUNK_SIZE
const CHUNK_END_SIZE = Chunk.CHUNK_SIZE - 1

var render_distance setget _set_render_distance
var render_distance set = _set_render_distance
var _delete_distance = 0
var effective_render_distance = 0
var _old_player_chunk = Vector3() # TODO: Vector3i
Expand All @@ -14,7 +14,7 @@ var _deleting = false

var _chunks = {}

onready var player = $"../Player"
@onready var player = $"../Player"


func _process(_delta):
Expand Down
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader.Tests/Scripts/Sample3.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extends Label
# Displays some useful debug information in a Label.

onready var player = $"../Player"
onready var voxel_world = $"../VoxelWorld"
@onready var player = $"../Player"
@onready var voxel_world = $"../VoxelWorld"


func _process(_delta):
Expand Down
2 changes: 2 additions & 0 deletions src/GDShrapt.Reader/Basics/GDStringBoundingChar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public enum GDStringBoundingChar
{
SingleQuotas,
DoubleQuotas,
TripleDoubleQuotas,
TripleSingleQuotas
}
}
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader/Building/GD_EXPRESSION.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public static class Expression
public static GDIdentifierExpression Identifier(string name) => new GDIdentifierExpression() { Identifier = Syntax.Identifier(name) };
public static GDIdentifierExpression Identifier(GDIdentifier identifier) => new GDIdentifierExpression() { Identifier = identifier };

public static GDStringExpression String(string value, bool multiline = false, GDStringBoundingChar boundingChar = GDStringBoundingChar.DoubleQuotas) => new GDStringExpression()
public static GDStringExpression String(string value, GDStringBoundingChar boundingChar = GDStringBoundingChar.DoubleQuotas) => new GDStringExpression()
{
String = Syntax.String(value, multiline, boundingChar)
String = Syntax.String(value, boundingChar)
};

public static GDNumberExpression Number(string value) => new GDNumberExpression() { Number = Syntax.Number(value) };
Expand Down
58 changes: 36 additions & 22 deletions src/GDShrapt.Reader/Building/GD_SYNTAX.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GDShrapt.Reader
using System;

namespace GDShrapt.Reader
{
public static partial class GD
{
Expand All @@ -7,31 +9,43 @@ public static class Syntax
public static GDIdentifier Identifier(string name) => new GDIdentifier() { Sequence = name };
public static GDType Type(string name) => new GDType() { Sequence = name };

public static GDStringNode String(string value, bool multiline = false, GDStringBoundingChar boundingChar = GDStringBoundingChar.DoubleQuotas)
public static GDStringNode String(string value, GDStringBoundingChar boundingChar = GDStringBoundingChar.DoubleQuotas)
{
if (multiline)
{
if (boundingChar == GDStringBoundingChar.SingleQuotas)
{
return new GDMultilineDoubleQuotasStringNode() { Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } } };
}
else
{
return new GDMultilineDoubleQuotasStringNode() { Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } } };
}
}
else
switch (boundingChar)
{
if (boundingChar == GDStringBoundingChar.SingleQuotas)
{
return new GDSingleQuotasStringNode() { Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } } };
}
else
{
return new GDDoubleQuotasStringNode() { Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } } };
}
case GDStringBoundingChar.SingleQuotas:
return new GDSingleQuotasStringNode()
{
OpeningBounder = new GDSingleQuotas(),
Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } },
ClosingBounder = new GDSingleQuotas()
};
case GDStringBoundingChar.DoubleQuotas:
return new GDDoubleQuotasStringNode()
{
OpeningBounder = new GDDoubleQuotas(),
Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } },
ClosingBounder = new GDDoubleQuotas()
};
case GDStringBoundingChar.TripleDoubleQuotas:
return new GDTripleDoubleQuotasStringNode()
{
OpeningBounder = new GDTripleDoubleQuotas(),
Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } },
ClosingBounder = new GDTripleDoubleQuotas()
};
case GDStringBoundingChar.TripleSingleQuotas:
return new GDTripleSingleQuotasStringNode()
{
OpeningBounder = new GDTripleSingleQuotas(),
Parts = new GDStringPartsList() { new GDStringPart() { Sequence = value } },
ClosingBounder = new GDTripleSingleQuotas()
};
default:
throw new NotImplementedException();
}
}

public static GDNumber Number(string stringValue) => new GDNumber() { Sequence = stringValue };
public static GDNumber Number(int value) => new GDNumber() { ValueInt64 = value };
public static GDNumber Number(long value) => new GDNumber() { ValueInt64 = value };
Expand Down
6 changes: 2 additions & 4 deletions src/GDShrapt.Reader/Lists/GDStringPartsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ public class GDStringPartsList : GDSeparatedList<GDStringPart, GDMultiLineSplitT
{
bool _ended;
readonly GDStringBoundingChar _bounder;
readonly bool _multiline;

public GDStringPartsList()
{
}

internal GDStringPartsList(GDStringBoundingChar bounder, bool multiline)
internal GDStringPartsList(GDStringBoundingChar bounder)
{
_bounder = bounder;
_multiline = multiline;
}

internal override void HandleChar(char c, GDReadingState state)
Expand All @@ -26,7 +24,7 @@ internal override void HandleChar(char c, GDReadingState state)
return;
}

this.ResolveStringPart(c, state, _bounder, _multiline);
this.ResolveStringPart(c, state, _bounder);
}

internal override void HandleNewLineChar(GDReadingState state)
Expand Down
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader/Resolvers/GDResolvingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ public static void ResolveType(this ITokenOrSkipReceiver<GDTypeNode> receiver, c
state.PushAndPass(new GDTypeResolver(receiver), c);
}

public static void ResolveStringPart(this ITokenOrSkipReceiver<GDStringPart> receiver, char c, GDReadingState state, GDStringBoundingChar bounder, bool multiline)
public static void ResolveStringPart(this ITokenOrSkipReceiver<GDStringPart> receiver, char c, GDReadingState state, GDStringBoundingChar bounder)
{
state.PushAndPass(new GDStringPartResolver(receiver, bounder, multiline), c);
state.PushAndPass(new GDStringPartResolver(receiver, bounder), c);
}

public static bool ResolveSingleQuotas(this ITokenOrSkipReceiver<GDSingleQuotas> receiver, char c, GDReadingState state)
Expand Down
4 changes: 2 additions & 2 deletions src/GDShrapt.Reader/Resolvers/GDStringNodeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ protected override void PatternMatched(string pattern, GDReadingState state)
Owner.HandleReceivedToken(state.Push(new GDSingleQuotasStringNode()));
break;
case "\"\"\"":
Owner.HandleReceivedToken(state.Push(new GDMultilineDoubleQuotasStringNode()));
Owner.HandleReceivedToken(state.Push(new GDTripleDoubleQuotasStringNode()));
break;
case "'''":
Owner.HandleReceivedToken(state.Push(new GDMultilineSingleQuotasStringNode()));
Owner.HandleReceivedToken(state.Push(new GDTripleSingleQuotasStringNode()));
break;
default:
Owner.HandleReceivedTokenSkip();
Expand Down
Loading

0 comments on commit b8a51f3

Please sign in to comment.