feat: parser, ignore comments.
This commit is contained in:
parent
6d7cd33d04
commit
87dd4358d8
3 changed files with 29 additions and 1 deletions
|
@ -40,6 +40,19 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
return new String(r);
|
||||
}
|
||||
|
||||
Expression parse_comment(GroupingToken start, GroupingToken? end) {
|
||||
Debug.Assert(end != null);
|
||||
Debug.Assert(";".Contains(start.value));
|
||||
while (_sts.Available() > 0) {
|
||||
Token<string> t = _sts.Get();
|
||||
if (t.value == end.value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_sts.Commit();
|
||||
return parse();
|
||||
}
|
||||
|
||||
Expression parse_quote(GroupingToken start, GroupingToken? end) {
|
||||
Debug.Assert(end == null);
|
||||
Debug.Assert("'".Contains(start.value));
|
||||
|
@ -53,6 +66,9 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
if ("'".Contains(start.value)) {
|
||||
return parse_quote(start, end);
|
||||
}
|
||||
if (";".Contains(start.value)) {
|
||||
return parse_comment(start, end);
|
||||
}
|
||||
Debug.Assert(end != null);
|
||||
IList<Expression> expressions = new List<Expression>();
|
||||
while (_sts.Available() > 0) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -55,6 +55,8 @@ namespace Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler {
|
|||
return null;
|
||||
} else if (_value == "'") {
|
||||
return null;
|
||||
} else if (_value == ";") {
|
||||
return new GroupingToken("\n");
|
||||
}
|
||||
return new GroupingToken(_value);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,16 @@ namespace Tests
|
|||
sts = StringTokenStream.generate(program);
|
||||
p = new Parser(sts);
|
||||
Assert.Equal(program, string.Format("{0}", p.parse()));
|
||||
|
||||
program = """
|
||||
(begin ;this too
|
||||
;;; this is a comment
|
||||
t
|
||||
)
|
||||
""";
|
||||
sts = StringTokenStream.generate(program);
|
||||
p = new Parser(sts);
|
||||
Assert.Equal("(begin t)", string.Format("{0}", p.parse()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Loading…
Reference in a new issue