From efc5dbb038672dc25abf73cf1fae017a07e174eb Mon Sep 17 00:00:00 2001 From: falsycat Date: Fri, 4 Oct 2019 00:00:00 +0000 Subject: [PATCH] [add] Added the test for sjscript. --- sjscript/src/sjscript/package.d | 4 +++- sjscript/test/parse.d | 18 ++++++++++++++++++ sjscript/test/test01.sj | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 sjscript/test/parse.d create mode 100644 sjscript/test/test01.sj diff --git a/sjscript/src/sjscript/package.d b/sjscript/src/sjscript/package.d index c063b59..8e696eb 100644 --- a/sjscript/src/sjscript/package.d +++ b/sjscript/src/sjscript/package.d @@ -1,7 +1,8 @@ /// License: MIT module sjscript; -import std.algorithm; +import std.algorithm, + std.range; import dast.tokenize : Tokenize; @@ -21,6 +22,7 @@ ParametersBlock[] CreateScriptAst(string src) { Tokenize!TokenType(). filter!(x => x.type != TokenType.Whitespace). filter!(x => x.type != TokenType.Comment). + chain([Token("", TokenType.End)]). Preprocess(). Parse(); } diff --git a/sjscript/test/parse.d b/sjscript/test/parse.d new file mode 100755 index 0000000..6268dbe --- /dev/null +++ b/sjscript/test/parse.d @@ -0,0 +1,18 @@ +#!/usr/bin/env dub +/+ dub.json: +{ + "name": "parse", + "dependencies": { + "sjscript": {"path": "../"} + } +} +/ + +import std; + +import sjscript; + +int main(string[] args) { + enforce(args.length >= 2); + args[1].readText.CreateScriptAst().writeln; + return 0; +} diff --git a/sjscript/test/test01.sj b/sjscript/test/test01.sj new file mode 100644 index 0000000..07c7661 --- /dev/null +++ b/sjscript/test/test01.sj @@ -0,0 +1,16 @@ +// this is comment + +$define horming { + translate_x += cos(atan(player_y, player_x)) * $horming_speed; + translate_y += sin(atan(player_y, player_x)) * $horming_speed; +} + +A [0..10] { + translate_x = 0.5 + sin(rtime)*0.5; + translate_y = 0.5 + cos(rtime)*0.5; +} + +B [5..15] { + $define horming_speed {0.1} + $horming +}