Skip to content

Commit

Permalink
Merge pull request #30 from roblox-csharp/test/extra-tests
Browse files Browse the repository at this point in the history
Extra tests
  • Loading branch information
R-unic authored Jan 8, 2025
2 parents 4cb66b3 + 0e3d9d5 commit 42b8615
Show file tree
Hide file tree
Showing 72 changed files with 1,549 additions and 1,509 deletions.
29 changes: 14 additions & 15 deletions RobloxCS.Luau/AST/AST.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public class AST : Node
{
public class AST : Node
{
public List<Statement> Statements { get; }
public List<Statement> Statements { get; }

public AST(List<Statement> statements)
{
Statements = statements;
AddChildren(Statements);
}
public AST(List<Statement> statements)
{
Statements = statements;
AddChildren(Statements);
}

public override void Render(LuauWriter luau)
{
foreach (var statement in Statements)
statement.Render(luau);
public override void Render(LuauWriter luau)
{
foreach (var statement in Statements)
statement.Render(luau);

luau.WriteReturn();
}
luau.WriteReturn();
}
}
57 changes: 28 additions & 29 deletions RobloxCS.Luau/AST/AnonymousFunction.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public class AnonymousFunction : Expression
{
public class AnonymousFunction : Expression
{
public ParameterList ParameterList { get; }
public Block? Body { get; }
public TypeRef? ReturnType { get; }
public List<AttributeList> AttributeLists { get; }
public ParameterList ParameterList { get; }
public Block? Body { get; }
public TypeRef? ReturnType { get; }
public List<AttributeList> AttributeLists { get; }

public AnonymousFunction(ParameterList parameterList, TypeRef? returnType = null,
Block? body = null,
List<AttributeList>? attributeLists = null)
public AnonymousFunction(ParameterList parameterList, TypeRef? returnType = null,
Block? body = null,
List<AttributeList>? attributeLists = null)
{
ParameterList = parameterList;
Body = body;
Body = body;
ReturnType = returnType;
AttributeLists = attributeLists ?? []; AddChild(ParameterList);
AddChild(ParameterList);
if (ReturnType != null)
{
AddChild(ReturnType);
}
if (Body != null)
{
ParameterList = parameterList;
Body = body;
Body = body;
ReturnType = returnType;
AttributeLists = attributeLists ?? []; AddChild(ParameterList);
AddChild(ParameterList);
if (ReturnType != null)
{
AddChild(ReturnType);
}
if (Body != null)
{
AddChild(Body);
}
AddChildren(AttributeLists);
AddChild(Body);
}

public override void Render(LuauWriter luau) =>
luau.WriteFunction(null, false, ParameterList, ReturnType, Body, AttributeLists,
inlineAttributes: true, createNewline: false);
AddChildren(AttributeLists);
}

public override void Render(LuauWriter luau) =>
luau.WriteFunction(null, false, ParameterList, ReturnType, Body, AttributeLists,
inlineAttributes: true, createNewline: false);
}
26 changes: 11 additions & 15 deletions RobloxCS.Luau/AST/Argument.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
namespace RobloxCS.Luau
{
public class Argument : Expression
{
public Expression Expression { get; set; }
namespace RobloxCS.Luau;

public Argument(Expression expression)
{
Expression = expression;
AddChild(Expression);
}
public class Argument : Expression
{
public Expression Expression { get; set; }

public override void Render(LuauWriter luau)
{
Expression.Render(luau);
}
public Argument(Expression expression)
{
Expression = expression;
AddChild(Expression);
}
}

public override void Render(LuauWriter luau) => Expression.Render(luau);
}
29 changes: 14 additions & 15 deletions RobloxCS.Luau/AST/ArgumentList.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public class ArgumentList : Expression
{
public class ArgumentList : Expression
{
public List<Argument> Arguments { get; set; }
public List<Argument> Arguments { get; set; }

public ArgumentList(List<Argument> arguments)
{
Arguments = arguments;
AddChildren(Arguments.OfType<Node>().ToList());
}
public ArgumentList(List<Argument> arguments)
{
Arguments = arguments;
AddChildren(Arguments);
}

public override void Render(LuauWriter luau)
{
luau.Write('(');
luau.WriteNodesCommaSeparated(Arguments);
luau.Write(')');
}
public override void Render(LuauWriter luau)
{
luau.Write('(');
luau.WriteNodesCommaSeparated(Arguments);
luau.Write(')');
}
}
18 changes: 9 additions & 9 deletions RobloxCS.Luau/AST/ArrayType.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public class ArrayType : TypeRef
{
public class ArrayType : TypeRef
{
public TypeRef ElementType { get; }
public TypeRef ElementType { get; }

public ArrayType(TypeRef elementType)
: base("{ " + elementType.Path + " }", true)
{
ElementType = elementType;
}
public ArrayType(TypeRef elementType)
: base("{ " + elementType.Path + " }", true)
{
ElementType = elementType;
AddChild(ElementType);
}
}
35 changes: 17 additions & 18 deletions RobloxCS.Luau/AST/Assignment.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public sealed class Assignment : Expression
{
public sealed class Assignment : Expression
{
public AssignmentTarget Target { get; }
public Expression Value { get; private set; }
public AssignmentTarget Target { get; }
public Expression Value { get; private set; }

public Assignment(AssignmentTarget target, Expression value)
{
Target = target;
Value = value;
AddChildren([Target, Value]);
}
public Assignment(AssignmentTarget target, Expression value)
{
Target = target;
Value = value;
AddChildren([Target, Value]);
}

public override void Render(LuauWriter luau)
{
Node value = Value;
luau.WriteDescendantStatements(ref value);
Value = (Expression)value;
luau.WriteAssignment(Target, Value);
}
public override void Render(LuauWriter luau)
{
Node value = Value;
luau.WriteDescendantStatements(ref value);
Value = (Expression)value;
luau.WriteAssignment(Target, Value);
}
}
29 changes: 0 additions & 29 deletions RobloxCS.Luau/AST/AssignmentFunctionName.cs

This file was deleted.

9 changes: 3 additions & 6 deletions RobloxCS.Luau/AST/AssignmentTarget.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
namespace RobloxCS.Luau
{
public abstract class AssignmentTarget : Expression
{
}
}
namespace RobloxCS.Luau;

public abstract class AssignmentTarget : Expression;
36 changes: 21 additions & 15 deletions RobloxCS.Luau/AST/AttributeList.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
namespace RobloxCS.Luau
namespace RobloxCS.Luau;

public class AttributeList : Statement
{
public class AttributeList : Statement
{
public List<BaseAttribute> Attributes { get; }
public bool Inline { get; set; } = false;
public List<Node> Attributes { get; }
public bool Inline { get; set; } = false;

public AttributeList(List<BaseAttribute> attributes)
{
Attributes = attributes;
}
public AttributeList(List<Node> attributes)
{
Attributes = attributes;
AddChildren(Attributes);
}

public override void Render(LuauWriter luau)
public override void Render(LuauWriter luau)
{
foreach (var attribute in Attributes)
{
foreach (var attribute in Attributes)
if (attribute is BuiltInAttribute)
{
attribute.Render(luau);
if (!Inline)
{
luau.WriteLine();
}

if (Inline) continue;
luau.WriteLine();
}
else
{
// TODO: user-defined attribute stuff
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions RobloxCS.Luau/AST/BaseAttribute.cs

This file was deleted.

40 changes: 18 additions & 22 deletions RobloxCS.Luau/AST/BinaryOperator.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
namespace RobloxCS.Luau
{
public class BinaryOperator : Expression
{
public Expression Left { get; }
public string Operator { get; }
public Expression Right { get; }
namespace RobloxCS.Luau;

public BinaryOperator(Expression left, string @operator, Expression right)
{
Left = left;
Operator = @operator;
Right = right;
AddChildren([Left, Right]);
}
public class BinaryOperator : Expression
{
public Expression Left { get; }
public string Operator { get; }
public Expression Right { get; }

public override void Render(LuauWriter luau)
{
Left.Render(luau);
luau.Write($" {Operator} ");
Right.Render(luau);
}
public BinaryOperator(Expression left, string @operator, Expression right)
{
Left = left;
Operator = @operator;
Right = right;
AddChildren([Left, Right]);
}

public BinaryOperator WithLeft(Expression left) => new BinaryOperator(left, Operator, Right);
public BinaryOperator WithRight(Expression right) => new BinaryOperator(Left, Operator, right);
public override void Render(LuauWriter luau)
{
Left.Render(luau);
luau.Write($" {Operator} ");
Right.Render(luau);
}
}
Loading

0 comments on commit 42b8615

Please sign in to comment.