Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kinosang committed Dec 23, 2019
2 parents 6304f60 + a31482b commit aa97ff2
Show file tree
Hide file tree
Showing 33 changed files with 607 additions and 268 deletions.
10 changes: 10 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: pipeline
name: default

steps:
- name: build
image: mcr.microsoft.com/dotnet/core/sdk:3.1
commands:
- dotnet restore
- dotnet build -c Release
- dotnet test -c Release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ _TeamCity*
*.coverage
*.coveragexml

# coverlet and OpenCover
coverage.opencover.xml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
image: Visual Studio 2019
version: '0.1.0-ci.{build}'
version: "0.1.0-ci.{build}"
init:
- ps: |
if ($env:APPVEYOR_REPO_TAG -eq "false")
Expand All @@ -12,8 +12,8 @@ skip_branch_with_pr: true
dotnet_csproj:
patch: true
file: '**\*.csproj;**\*.props'
version: '{version}'
package_version: '{version}'
version: "{version}"
package_version: "{version}"
install:
- appveyor-retry dotnet restore -v Minimal
- appveyor-retry choco install codecov
Expand All @@ -34,7 +34,7 @@ deploy:
api_key:
secure: 9EKvm3W60xQMcta7WZW0BISOOISgd1535xd3ie/D/uLcuFAjzDLBRzn2myEcd5xC
on:
branch: master
branch: develop
- provider: NuGet
name: NuGet
api_key:
Expand Down
2 changes: 1 addition & 1 deletion samples/GalaToaster/GalaToaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>The GalaScript Toaster</Description>

<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
7 changes: 1 addition & 6 deletions samples/GalaToaster/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -50,9 +48,6 @@ public MainWindow()

_engine = new ScriptEngine(true);

decimal Add(decimal[] arguments) => arguments.Sum();
_engine.Register("add", (Func<decimal[], decimal>)Add);

_engine.OnStartedHandler += () => Dispatcher.UIThread.InvokeAsync(() =>
{
_scriptBox.IsReadOnly = true;
Expand Down
1 change: 0 additions & 1 deletion samples/GalaToaster/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Logging.Serilog;

namespace GalaToaster
Expand Down
15 changes: 15 additions & 0 deletions src/GalaScript/Attributes/AliasAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace GalaScript.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
class AliasAttribute : Attribute
{
public string Name { get; }

public AliasAttribute(string name)
{
Name = name;
}
}
}
21 changes: 21 additions & 0 deletions src/GalaScript/Evaluators/AbstractEvaluator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using GalaScript.Interfaces;

namespace GalaScript.Evaluators
{
public abstract class AbstractEvaluator : IEvaluator
{
protected IScriptEvaluator _caller;

public virtual void SetCaller(IScriptEvaluator caller)
{
_caller = caller;
}

public virtual object Evaluate() => throw new NotImplementedException();

public virtual string ToScriptString() => throw new NotImplementedException();

public override string ToString() => ToScriptString();
}
}
13 changes: 7 additions & 6 deletions src/GalaScript/Evaluators/AliasEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace GalaScript.Evaluators
{
public class AliasEvaluator : IEvaluator
public class AliasEvaluator : AbstractEvaluator
{
private readonly IScriptEngine _engine;
private IScriptEvaluator _caller;

private readonly string _name;
private readonly IEvaluator _value;
Expand All @@ -17,14 +16,14 @@ public AliasEvaluator(IScriptEngine engine, string name, IEvaluator value = null
_value = value;
}

public void SetCaller(IScriptEvaluator caller)
public override void SetCaller(IScriptEvaluator caller)
{
_caller = caller;

_value?.SetCaller(caller);

base.SetCaller(caller);
}

public object Evaluate()
public override object Evaluate()
{
if (_value == null)
{
Expand All @@ -37,5 +36,7 @@ public object Evaluate()

return result;
}

public override string ToScriptString() => _value == null ? $"{_name}" : $"{_value} : {_name}";
}
}
30 changes: 21 additions & 9 deletions src/GalaScript/Evaluators/ConstantEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
using GalaScript.Interfaces;
using System.Collections.Generic;

namespace GalaScript.Evaluators
{
public class ConstantEvaluator : IEvaluator
public class ConstantEvaluator : AbstractEvaluator
{
private readonly Dictionary<string, object> _constant = new Dictionary<string, object>
{
["true"] = true,
["false"] = false,
["null"] = null,
};

private readonly string _k;

public ConstantEvaluator(string k)
{
_k = k;
_k = k.ToLower() switch
{
var l when _constant.ContainsKey(l) => l,
_ => k,
};
}

public void SetCaller(IScriptEvaluator caller)
public override object Evaluate()
{
//
return _k switch
{
_ when _constant.TryGetValue(_k, out var c) => c,
_ => _k,
};
}

public object Evaluate()
{
return _k;
}
public override string ToScriptString() => _k;
}
}
13 changes: 5 additions & 8 deletions src/GalaScript/Evaluators/DecimalConstantEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GalaScript.Interfaces;
using System.Globalization;

namespace GalaScript.Evaluators
{
public class DecimalConstantEvaluator : IEvaluator
public class DecimalConstantEvaluator : AbstractEvaluator
{
private readonly decimal _decimal;

Expand All @@ -11,14 +11,11 @@ public DecimalConstantEvaluator(decimal @decimal)
_decimal = @decimal;
}

public void SetCaller(IScriptEvaluator caller)
{
//
}

public object Evaluate()
public override object Evaluate()
{
return _decimal;
}

public override string ToScriptString() => $"{_decimal.ToString("0.0", CultureInfo.InvariantCulture)}m";
}
}
24 changes: 18 additions & 6 deletions src/GalaScript/Evaluators/FunctionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

namespace GalaScript.Evaluators
{
public class FunctionEvaluator : IEvaluator
public class FunctionEvaluator : AbstractEvaluator
{
private readonly IScriptEngine _engine;
private IScriptEvaluator _caller;

private readonly string _name;
private readonly IEvaluator[] _parameters;
Expand All @@ -18,19 +17,32 @@ public FunctionEvaluator(IScriptEngine engine, string name, IEvaluator[] paramet
_parameters = parameters;
}

public void SetCaller(IScriptEvaluator caller)
public override void SetCaller(IScriptEvaluator caller)
{
_caller = caller;

foreach (var parameter in _parameters)
{
parameter?.SetCaller(caller);
}

base.SetCaller(caller);
}

public object Evaluate()
public override object Evaluate()
{
return _engine.Call(_caller, _name, _parameters?.Select(p => p?.Evaluate()).ToArray());
}

public override string ToScriptString()
{
var @string = $"[{_name}";
var parameters = _parameters?.Select(p => p?.ToString());

if (parameters != null)
{
@string += $" {string.Join(" ", parameters)}";
}

return @string + "]";
}
}
}
21 changes: 21 additions & 0 deletions src/GalaScript/Evaluators/IntegerConstantEvaluator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;

namespace GalaScript.Evaluators
{
public class IntegerConstantEvaluator : AbstractEvaluator
{
private readonly long _integer;

public IntegerConstantEvaluator(long integer)
{
_integer = integer;
}

public override object Evaluate()
{
return _integer;
}

public override string ToScriptString() => $"{_integer.ToString(CultureInfo.InvariantCulture)}L";
}
}
11 changes: 4 additions & 7 deletions src/GalaScript/Evaluators/LabelEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

namespace GalaScript.Evaluators
{
public class LabelEvaluator : IEvaluator, INamedEvaluator
public class LabelEvaluator : AbstractEvaluator, INamedEvaluator
{
public LabelEvaluator(string label)
{
Name = label;
}

public void SetCaller(IScriptEvaluator caller)
{
//
}

public object Evaluate()
public override object Evaluate()
{
return Name;
}

public string Name { get; }

public override string ToScriptString() => $"* {Name}";
}
}
24 changes: 24 additions & 0 deletions src/GalaScript/Evaluators/MacroEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GalaScript.Interfaces;

namespace GalaScript.Evaluators
Expand Down Expand Up @@ -49,5 +50,28 @@ public void SetArguments(object[] arguments)
}

public string Name { get; }

public override string ToScriptString()
{
var @string = $"!{Name}";

var parameters = _parameters?.Select(p => p?.ToString());

if (parameters != null && parameters.Any())
{
@string += $" [{string.Join(" ", parameters)}]";
}

@string += "\n";

var script = Script?.Select(s => s?.ToString());

if (script != null)
{
@string += $" {string.Join("\n ", script)}";
}

return @string.TrimEnd() + "\n!";
}
}
}
25 changes: 25 additions & 0 deletions src/GalaScript/Evaluators/NamedParameterEvaluator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using GalaScript.Interfaces;

namespace GalaScript.Evaluators
{
public class NamedParameterEvaluator : AbstractEvaluator, INamedEvaluator
{
private IEvaluator _evaluator;

public NamedParameterEvaluator(string name, IEvaluator evaluator)
{
Name = name;
_evaluator = evaluator;
}

public override object Evaluate()
{
return new KeyValuePair<string, object>(Name, _evaluator.Evaluate());
}

public string Name { get; }

public override string ToScriptString() => $"{Name}={_evaluator.ToString()}";
}
}
Loading

0 comments on commit aa97ff2

Please sign in to comment.