diff --git a/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/Parser.cs b/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/Parser.cs index 4415edd..3452fee 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/Parser.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/Parser.cs @@ -40,11 +40,20 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler { return new String(r); } + Expression parse_quote(GroupingToken start, GroupingToken? end) { + Debug.Assert(end == null); + Debug.Assert("'".Contains(start.value)); + return Cons.FromList(new Expression[]{ new Symbol("quote"), parse()}); + } + Expression parse_grouping(GroupingToken start, GroupingToken? end) { - Debug.Assert(end != null); if ("\"".Contains(start.value)) { return parse_string(start, end); } + if ("'".Contains(start.value)) { + return parse_quote(start, end); + } + Debug.Assert(end != null); IList expressions = new List(); while (_sts.Available() > 0) { Token t = _sts.Get(); diff --git a/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/TokenStream.cs b/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/TokenStream.cs index b5064a3..d29f90c 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/TokenStream.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Lisp/Compiler/TokenStream.cs @@ -43,7 +43,7 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler { return null; } char t = program.Get(); - if ("()\"".Contains(t)) { + if ("()\"'".Contains(t)) { return new GroupingToken(t.ToString()); } return null; @@ -53,6 +53,8 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler { return new GroupingToken(")"); } else if (_value == ")") { return null; + } else if (_value == "'") { + return null; } return new GroupingToken(_value); } diff --git a/Tests/Tests.cs b/Tests/Tests.cs index a48b4ad..71ea7d5 100644 --- a/Tests/Tests.cs +++ b/Tests/Tests.cs @@ -66,6 +66,16 @@ namespace Tests sts = StringTokenStream.generate(program); p = new Parser(sts); Assert.Equal(program, string.Format("{0}", p.parse())); + + program = "(abc '(1 2 3))"; + sts = StringTokenStream.generate(program); + p = new Parser(sts); + Assert.Equal("(abc (quote (1 2 3)))", string.Format("{0}", p.parse())); + + program = "(abc \"'(1 2 3)\")"; + sts = StringTokenStream.generate(program); + p = new Parser(sts); + Assert.Equal(program, string.Format("{0}", p.parse())); } [Fact] @@ -236,6 +246,7 @@ namespace Tests //Assert.Equal("", e.eval("(rand)").ToString()); //Assert.Equal("", e.eval("(shuf (list 0 1 2 3 4 5 6))").ToString()); + Assert.Equal("(1 2 3 4 5 6 7)", e.eval("(qsort (lambda (a b) (> a b)) '(5 4 7 3 2 6 1))").ToString()); } } }