-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from AIexandrKotov/sltbase
0.3.0
- Loading branch information
Showing
55 changed files
with
1,258 additions
and
248 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
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,12 +1,15 @@ | ||
using System; | ||
using SLThree.Extensions; | ||
using System; | ||
|
||
namespace SLThree | ||
{ | ||
public class OperatorError : RuntimeError | ||
{ | ||
public OperatorError(ExpressionUnary unary, Type left) | ||
: base($"Operator {unary.Operator} not allow for {left?.Name ?? "null"}", unary.SourceContext) { } | ||
: base($"Operator {unary.Operator} not allow for {left?.GetTypeString() ?? "null"}", unary.SourceContext) { } | ||
public OperatorError(ExpressionBinary binary, Type left, Type right) | ||
: base($"Operator {binary.Operator} not allow for {left?.Name ?? "null"} and {right?.Name ?? "null"}", binary.SourceContext) { } | ||
: base($"Operator {binary.Operator} not allow for {left?.GetTypeString() ?? "null"} and {right?.GetTypeString() ?? "null"}", binary.SourceContext) { } | ||
public OperatorError(string op, Type cond, SourceContext context) | ||
: base($"Operator {op} not allow for {cond?.GetTypeString() ?? "null"}", context) { } | ||
} | ||
} |
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
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
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,5 +1,6 @@ | ||
using Pegasus.Common; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace SLThree | ||
{ | ||
|
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Pegasus.Common; | ||
using SLThree.Extensions; | ||
using System.Linq; | ||
|
||
namespace SLThree | ||
{ | ||
public class CreatorArray : BaseLexem | ||
{ | ||
public BaseLexem[] Lexems; | ||
|
||
public CreatorArray(BaseLexem[] lexems, Cursor cursor) : base(cursor) | ||
{ | ||
Lexems = lexems; | ||
} | ||
|
||
public override object GetValue(ExecutionContext context) | ||
{ | ||
return Lexems.ConvertAll(x => x.GetValue(context)).ToList(); | ||
} | ||
|
||
public override string ToString() => $"[{Lexems.JoinIntoString(", ")}]"; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Pegasus.Common; | ||
using SLThree.Extensions; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SLThree | ||
{ | ||
public class CreatorDictionary : BaseLexem | ||
{ | ||
public class Entry : BaseLexem | ||
{ | ||
public BaseLexem Key; | ||
public BaseLexem Value; | ||
public Entry(BaseLexem key, BaseLexem value, Cursor cursor) : base(cursor) | ||
{ | ||
Key = key; | ||
Value = value; | ||
} | ||
public override object GetValue(ExecutionContext context) | ||
{ | ||
return new KeyValuePair<object, object>(Key.GetValue(context), Value.GetValue(context)); | ||
} | ||
public override string ToString() => $"{Key}: {Value}"; | ||
} | ||
|
||
public Entry[] Entries; | ||
|
||
public CreatorDictionary(Entry[] entries, Cursor cursor) : base(cursor) | ||
{ | ||
Entries = entries; | ||
} | ||
|
||
public override object GetValue(ExecutionContext context) | ||
{ | ||
return Entries.Select(x => (KeyValuePair<object, object>)x.GetValue(context)).ToDictionary(x => x.Key, x => x.Value); | ||
} | ||
|
||
public override string ToString() => $"{{{Entries.JoinIntoString(", ")}}}"; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Pegasus.Common; | ||
using SLThree.Extensions; | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace SLThree | ||
{ | ||
public class CreatorTuple : BaseLexem | ||
{ | ||
public BaseLexem[] Lexems; | ||
|
||
public CreatorTuple(BaseLexem[] lexems, Cursor cursor) : base(cursor) | ||
{ | ||
Lexems = lexems; | ||
} | ||
|
||
public override object GetValue(ExecutionContext context) | ||
{ | ||
return Create(Lexems.ConvertAll(x => x.GetValue(context))); | ||
} | ||
|
||
public static ITuple Create(object[] objs, int index = 0) | ||
{ | ||
switch (objs.Length - index) | ||
{ | ||
case 0: throw new ArgumentException("Zero length array in objs"); | ||
case 1: return new Tuple<object>(objs[index]); | ||
case 2: return new Tuple<object, object>(objs[index], objs[index + 1]); | ||
case 3: return new Tuple<object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2]); | ||
case 4: return new Tuple<object, object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2], objs[index + 3]); | ||
case 5: return new Tuple<object, object, object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2], objs[index + 3], objs[index + 4]); | ||
case 6: return new Tuple<object, object, object, object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2], objs[index + 3], objs[index + 4], objs[index + 5]); | ||
case 7: return new Tuple<object, object, object, object, object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2], objs[index + 3], objs[index + 4], objs[index + 5], objs[index + 6]); | ||
default: return new Tuple<object, object, object, object, object, object, object, object>(objs[index + 0], objs[index + 1], objs[index + 2], objs[index + 3], objs[index + 4], objs[index + 5], objs[index + 6], Create(objs, index + 7)); | ||
} | ||
} | ||
public static object[] ToArray(ITuple tuple) | ||
{ | ||
var ret = new object[tuple.Length]; | ||
for (var i = 0; i < tuple.Length; i++) | ||
ret[i] = tuple[i]; | ||
return ret; | ||
} | ||
public override string ToString() => $"({Lexems.JoinIntoString(", ")})"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Pegasus.Common; | ||
|
||
namespace SLThree | ||
{ | ||
public class ExpressionBinaryAnd : ExpressionBinary | ||
{ | ||
public override string Operator => "&&"; | ||
public ExpressionBinaryAnd(BaseLexem left, BaseLexem right, Cursor cursor) : base(left, right, cursor) { } | ||
public ExpressionBinaryAnd() : base() { } | ||
public override object GetValue(ExecutionContext context) | ||
{ | ||
object left = Left.GetValue(context); | ||
object right = Right.GetValue(context); | ||
if (left is bool b1 && right is bool b2) return b1 && b2; | ||
context.Errors.Add(new OperatorError(this, left?.GetType(), right?.GetType())); | ||
return null; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.