Compare commits
No commits in common. "d74f9a807491da19ec95263c1dd91a7f0617733a" and "f1dcb3168256857577fe694f09af9128b6758f3a" have entirely different histories.
d74f9a8074
...
f1dcb31682
4 changed files with 4 additions and 29 deletions
|
@ -211,7 +211,7 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
public override string ToString() {
|
||||
return _value.ToString();
|
||||
}
|
||||
public static Expression FromBase(object o) {
|
||||
public static Atom FromBase(object o) {
|
||||
switch (o) {
|
||||
case bool b:
|
||||
return new Boolean(b);
|
||||
|
@ -219,8 +219,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
return new Integer(i);
|
||||
case string s:
|
||||
return new String(s);
|
||||
case IEnumerable<object> e:
|
||||
return new List(e.Select(x => Object.FromBase(x)).ToList());
|
||||
default:
|
||||
return new Object(o);
|
||||
}
|
||||
|
@ -269,9 +267,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
public Parser(StringTokenStream tokens) {
|
||||
_sts = tokens;
|
||||
}
|
||||
public Parser(string s) {
|
||||
_sts = StringTokenStream.generate(s);
|
||||
}
|
||||
|
||||
public Expression parse() {
|
||||
Token<string> token = _sts.Get();
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
return null;
|
||||
}
|
||||
public void Set(string k, Expression v) {
|
||||
this[k] = v;
|
||||
Add(k, v);
|
||||
}
|
||||
|
||||
public IEnvironment<string, Expression>? Find(string k) {
|
||||
|
@ -76,12 +76,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
}
|
||||
}
|
||||
|
||||
public class DefaultEnvironment: Environment {
|
||||
public DefaultEnvironment() {
|
||||
this["find"] = new Parser("(lambda (item list) (if (= list ()) nil (if (= item (car list)) (car list) (find item (cdr list)))))").parse();
|
||||
}
|
||||
}
|
||||
|
||||
public class SubEnvironment : Dictionary<string, Expression>, IEnvironment<string, Expression> {
|
||||
private IEnvironment<string, Expression> _super;
|
||||
public SubEnvironment(IEnvironment<string, Expression> super) {
|
||||
|
@ -118,7 +112,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
this["<="] = _le;
|
||||
this["eq?"] = _eq;
|
||||
this["="] = _eq;
|
||||
this["!="] = _ne;
|
||||
this["abs"] = _abs;
|
||||
this["append"] = _append;
|
||||
this["begin"] = _begin;
|
||||
|
@ -130,6 +123,7 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
this["haskeys"] = _haskeys;
|
||||
this["getitems"] = _getitems;
|
||||
this["invoke"] = _invoke;
|
||||
//this[new Symbol("!=")] = _ne;
|
||||
}
|
||||
|
||||
private static T _agg<T>(Func<T, T, T> op, IList<T> args) {
|
||||
|
@ -381,11 +375,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
_builtins = builtins;
|
||||
_builtinsLater = builtinsLater;
|
||||
}
|
||||
public Executor(IEnvironment<string, Expression> environment) {
|
||||
_environment = environment;
|
||||
_builtins = new Builtins();
|
||||
_builtinsLater = new BuiltinsLater();
|
||||
}
|
||||
public Executor() {
|
||||
_environment = new Environment();
|
||||
_builtins = new Builtins();
|
||||
|
@ -423,8 +412,6 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp {
|
|||
return i;
|
||||
case Compiler.String s:
|
||||
return s;
|
||||
case Compiler.Object o:
|
||||
return o;
|
||||
case Procedure p:
|
||||
return p;
|
||||
case List list:
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks {
|
|||
private IEnumerable<Guid> FilterPlaylistItems(IEnumerable<BaseItem> items, User user, SmartPlaylistDto smartPlaylist) {
|
||||
List<Guid> results = new List<Guid>();
|
||||
Expression expression = new Parser(StringTokenStream.generate(smartPlaylist.Program)).parse();
|
||||
Executor executor = new Executor(new DefaultEnvironment());
|
||||
Executor executor = new Executor();
|
||||
executor.environment.Set("user", new Lisp_Object(user));
|
||||
foreach (var i in items) {
|
||||
executor.environment.Set("item", new Lisp_Object(i));
|
||||
|
|
|
@ -172,12 +172,5 @@ namespace Tests
|
|||
r = e.eval("(begin (define find (lambda (item list) (if (= list ()) nil (if (= item (car list)) (car list) (find item (cdr list)))))) (find 0 (1 2 3 4)))");
|
||||
Assert.Equal(string.Format("{0}", r), "nil");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void DefaultEnvironmentTest() {
|
||||
Executor e = new Executor(new DefaultEnvironment());
|
||||
Assert.Equal("nil", e.eval("(find 0 (1 2 3 4))").ToString());
|
||||
Assert.Equal("3", e.eval("(find 3 (1 2 3 4))").ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue