Skip to content

Commit

Permalink
Merge pull request #126 from AIexandrKotov/release
Browse files Browse the repository at this point in the history
0.8.0
  • Loading branch information
AIexandrKotov authored Jun 21, 2024
2 parents 1ca8873 + fd301cb commit ff0d575
Show file tree
Hide file tree
Showing 125 changed files with 3,844 additions and 1,126 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ namespace TestSLThree

### LANG and REPL compatibility

Starting from language version 0.8.0, REPL no longer supports multiple versions at once and is built for each language update.

| REPL version | LANG version |
|-----------------|-----------------|
| 2.0.0 | 0.7.0+ |
| 2.0.0 | 0.7.0 |
| 1.* | 0.2.0 — 0.6.0 |

### Download
[![stable](https://img.shields.io/badge/REPL_stable-2.0.0-00cc00)](https://github.com/AIexandrKotov/SLThree/releases/tag/0.7.0) [![stable](https://img.shields.io/badge/LANG_exp-0.7.0-ccaa00)](https://github.com/AIexandrKotov/SLThree/releases/tag/0.7.0)
[![stable](https://img.shields.io/badge/stable-0.8.0-00cc00)](https://github.com/AIexandrKotov/SLThree/releases/tag/0.8.0)
186 changes: 88 additions & 98 deletions SLThree.HTMLCreator/HTMLCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,42 +114,7 @@ public override void VisitExpression(TypenameExpression expression)
CurrentString.Append(Replace(">"));
}
}
public void VisitExpression(CreatorContext expression, bool newline, bool hasnew)
{
if (hasnew)
CurrentString.Append(GetKeyword1("new context "));
else
CurrentString.Append(GetKeyword1("context "));
if (expression.HasName)
{
CurrentString.Append(expression.Name + " ");
}
if (expression.HasCast)
{
CurrentString.Append(": ");
VisitExpression(expression.Typecast);
CurrentString.Append(" ");
}
if (expression.HasBody)
{
CurrentString.Append("{ ");
CurrentTab += 1;
foreach (var x in expression.Body)
{
if (newline) Newline();
else CurrentString.Append(" ");
VisitStatement(x);
}
CurrentTab -= 1;
if (newline) Newline();
else CurrentString.Append(" ");
CurrentString.Append("}");
}
}
public override void VisitExpression(CreatorContext expression)
{
VisitExpression(expression, ContextElementNewLine, true);
}

public override void VisitExpression(MemberAccess expression)
{
VisitExpression(expression.Left);
Expand All @@ -167,7 +132,7 @@ public override void VisitExpression(InvokeExpression expression)
if (memberAccess.Right is NameExpression nameExpression1)
CurrentString.Append(GetCall(nameExpression1.Name));
}
else if (expression.Left is LambdaExpression lambda)
else if (expression.Left is FunctionDefinition lambda)
{
CurrentString.Append("(");
VisitExpression(lambda);
Expand Down Expand Up @@ -420,7 +385,8 @@ public override void VisitExpression(NameExpression expression)
VisitExpression(expression.TypeHint);
CurrentString.Append(" ");
}
CurrentString.Append(expression.Name);
if (expression.Name == "constructor") CurrentString.Append(GetKeyword1("constructor"));
else CurrentString.Append(expression.Name);
}
public override void VisitExpression(UnaryOperator expression)
{
Expand Down Expand Up @@ -479,35 +445,49 @@ public override void VisitExpression(InterpolatedString expression)
CurrentString = sb;
CurrentString.Append(GetString("$\"" + string.Format(expression.Value, arr) + "\""));
}
public override void VisitExpression(LambdaExpression expression)
public override void VisitExpression(FunctionDefinition expression)
{
foreach (var x in expression.Modificators)
{
CurrentString.Append(GetKeyword1(x));
CurrentString.Append(" ");
}
if (expression.FunctionName != null)
{
if (expression.Modificators.Length > 0) CurrentString.Append(" ");
VisitExpression(expression.FunctionName);
}
if (expression.GenericArguments.Length > 0)
{
CurrentString.Append(Replace("<"));
for (var i = 0; i < expression.GenericArguments.Length; i++)
{
CurrentString.Append(GetTypeSpan(expression.GenericArguments[i].Name));
if (i != expression.GenericArguments.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(Replace(">"));
}
CurrentString.Append("(");
for (var i = 0; i < expression.Left.Arguments.Length; i++)
for (var i = 0; i < expression.Arguments.Length; i++)
{
VisitExpression(expression.Left.Arguments[i]);
if (i != expression.Left.Arguments.Length - 1) CurrentString.Append(", ");
VisitExpression(expression.Arguments[i]);
if (i != expression.Arguments.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(")");
if (expression.ReturnTypeHint != null)
{
CurrentString.Append(": ");
VisitExpression(expression.ReturnTypeHint);
}
CurrentString.Append(Replace(" => "));
if (expression.Right.Statements.Length == 1 && expression.Right.Statements[0] is ReturnStatement ret && ret.Expression != null)
if (expression.FunctionBody.Statements.Length == 1 && expression.FunctionBody.Statements[0] is ReturnStatement ret && ret.Expression != null)
{
CurrentString.Append(Replace(" => "));
VisitExpression(ret.Expression);
}
else
{
CurrentString.Append(" {");
CurrentTab += 1;
foreach (var x in expression.Right.Statements)
foreach (var x in expression.FunctionBody.Statements)
{
Newline();
VisitStatement(x);
Expand All @@ -517,42 +497,40 @@ public override void VisitExpression(LambdaExpression expression)
CurrentString.Append("}");
}
}
public override void VisitExpression(LambdaGenericExpression expression)

public void VisitExpression(CreatorUsing expression, bool hasnew)
{
foreach (var x in expression.Modificators)
if (hasnew)
CurrentString.Append(GetKeyword1("new "));
CurrentString.Append(GetKeyword1("using "));
VisitExpression(expression.Type);
}
public override void VisitExpression(CreatorContext expression)
{
CurrentString.Append(GetKeyword1(expression.CreatorBody == null || expression.CreatorBody.Statements.Length == 0 ? "new context" : "context"));
if (expression.HasName)
{
CurrentString.Append(GetKeyword1(x));
CurrentString.Append(" ");
VisitExpression(expression.Name);
}
CurrentString.Append(Replace("<"));
for (var i = 0; i < expression.Generics.Length; i++)
{
CurrentString.Append(GetTypeSpan(expression.Generics[i].Name));
if (i != expression.Generics.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(Replace(">"));
CurrentString.Append("(");
for (var i = 0; i < expression.Left.Arguments.Length; i++)
{
VisitExpression(expression.Left.Arguments[i]);
if (i != expression.Left.Arguments.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(")");
if (expression.ReturnTypeHint != null)
RestOfContext(expression);
}
public void RestOfContext(CreatorContext expression)
{
if (expression.Ancestors.Length > 0)
{
CurrentString.Append(": ");
VisitExpression(expression.ReturnTypeHint);
}
CurrentString.Append(Replace(" => "));
if (expression.Right.Statements.Length == 1 && expression.Right.Statements[0] is ReturnStatement ret)
{
VisitExpression(ret.Expression);
for (var i = 0; i < expression.Ancestors.Length; i++)
{
VisitExpression(expression.Ancestors[i]);
if (i != expression.Ancestors.Length - 1) CurrentString.Append(", ");
}
}
else
if (expression.CreatorBody != null && expression.CreatorBody.Statements.Length > 0)
{
CurrentString.Append(" {");
CurrentString.Append(" {\n");
CurrentTab += 1;
foreach (var x in expression.Right.Statements)
foreach (var x in (expression.CreatorBody).Statements)
{
Newline();
VisitStatement(x);
Expand All @@ -562,28 +540,31 @@ public override void VisitExpression(LambdaGenericExpression expression)
CurrentString.Append("}");
}
}
public void VisitExpression(CreatorUsing expression, bool hasnew)
{
if (hasnew)
CurrentString.Append(GetKeyword1("new "));
CurrentString.Append(GetKeyword1("using "));
VisitExpression(expression.Type);
}
public override void VisitExpression(CreatorUsing expression)
{
VisitExpression(expression, true);
}
public override void VisitExpression(NewExpression expression)
public override void VisitExpression(CreatorInstance expression)
{
CurrentString.Append(GetKeyword1("new "));
VisitExpression(expression.Typename);
CurrentString.Append("(");
for (var i = 0; i < expression.Arguments.Length; i++)
VisitExpression(expression.Type);
if (expression.Arguments.Length > 0)
{
VisitExpression(expression.Arguments[i]);
if (i < expression.Arguments.Length - 1) CurrentString.Append(", ");
CurrentString.Append("(");
for (var i = 0; i < expression.Arguments.Length; i++)
{
VisitExpression(expression.Arguments[i]);
if (i < expression.Arguments.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(")");
}
CurrentString.Append(")");
if (expression.Name != null)
{
CurrentString.Append(" ");
VisitExpression(expression.Name);
}
if (expression.CreatorContext != null)
RestOfContext(expression.CreatorContext);
}
public override void VisitExpression(ReflectionExpression expression)
{
Expand All @@ -592,13 +573,13 @@ public override void VisitExpression(ReflectionExpression expression)
VisitExpression(expression.Right);
if (expression.MethodGenericArguments?.Length > 0)
{
CurrentString.Append("<");
CurrentString.Append(Replace("<"));
for (var i = 0; i < expression.MethodGenericArguments.Length; i++)
{
VisitExpression(expression.MethodGenericArguments[i]);
if (i < expression.MethodGenericArguments.Length - 1) CurrentString.Append(", ");
}
CurrentString.Append(">");
CurrentString.Append(Replace(">"));
}
if (expression.MethodArguments?.Length > 0)
{
Expand All @@ -612,11 +593,12 @@ public override void VisitExpression(ReflectionExpression expression)
CurrentString.Append(")");
}
}

public override void VisitStatement(ContextStatement statement)
public override void VisitExpression(StaticExpression expression)
{
VisitExpression(statement.Creator, ContextElementNewLine, false);
CurrentString.Append(GetKeyword1("static "));
VisitExpression(expression.Right);
}

public override void VisitStatement(BreakStatement statement)
{
CurrentString.Append(GetKeyword2("break") + ";");
Expand All @@ -625,13 +607,13 @@ public override void VisitStatement(ContinueStatement statement)
{
CurrentString.Append(GetKeyword2("continue") + ";");
}
public override void VisitStatement(UsingStatement statement)
public override void VisitExpression(UsingExpression statement)
{
VisitExpression(statement.Using, false);
if (statement.Alias != null)
{
CurrentString.Append(GetKeyword1( " as "));
CurrentString.Append(statement.Alias.Name);
VisitExpression(statement.Alias);
}
CurrentString.Append(";");
}
Expand Down Expand Up @@ -736,13 +718,13 @@ public override void VisitStatement(ForeachLoopStatement statement)
CurrentString.Append("}");
}
}
public override void VisitStatement(ConditionStatement statement)
public override void VisitExpression(ConditionExpression expression)
{
CurrentString.Append(GetKeyword2("if") + " (");
VisitExpression(statement.Condition);
VisitExpression(expression.Condition);
CurrentString.Append(")");

var ifbody = statement.IfBody;
var ifbody = expression.IfBody;
if (ifbody.Length < 2)
{
CurrentTab += 1;
Expand All @@ -765,7 +747,7 @@ public override void VisitStatement(ConditionStatement statement)
}


var elsebody = statement.ElseBody;
var elsebody = expression.ElseBody;
if (elsebody.Length == 0) return;
Newline();
CurrentString.Append(GetKeyword2("else "));
Expand Down Expand Up @@ -821,6 +803,14 @@ public override void VisitStatement(WhileLoopStatement statement)
public override void VisitStatement(ExpressionStatement statement)
{
base.VisitExpression(statement.Expression);
if (statement.Expression is ConditionExpression
|| (statement.Expression is CreatorContext cont && (cont.CreatorBody != null && cont.CreatorBody.Statements.Length > 0))
|| (statement.Expression is CreatorInstance inst && inst.CreatorContext?.CreatorBody != null)
|| statement.Expression is MatchExpression
|| (statement.Expression is FunctionDefinition func && !(func.FunctionBody.Statements.Length == 1 && func.FunctionBody.Statements[0] is ReturnStatement ret && !ret.VoidReturn)))
{
return;
}
CurrentString.Append(";");
}

Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions SLThree/.msbump

This file was deleted.

Loading

0 comments on commit ff0d575

Please sign in to comment.