[nap] multi-purpose bool expression evaluator for nap

This commit is contained in:
2021-05-18 17:43:01 -06:00
parent 89f30882cd
commit 238bdfd9ff
16 changed files with 101 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
-lib uuid
-lib kiss
-lib hscript
-cp src
--main nap.Main
--interp

View File

@@ -0,0 +1 @@
{"name":"Villain Alcohol","id":"song1","components":{"Tag":["song"]}}

15
projects/nap/haxelib.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "nap",
"url": "https://github.com/hissvn/kisslang",
"license": "LGPL",
"tags": ["cross"],
"description": "",
"version": "0.0.0",
"releasenote": "It isn't safe to use this library yet.",
"contributors": ["NQNStudios"],
"classPath": "src/",
"main": "nap.Main",
"dependencies": {
"kiss": ""
}
}

View File

@@ -1,6 +1,11 @@
package nap;
import kiss.Prelude;
import sys.FileSystem;
import sys.io.File;
import haxe.Json;
using haxe.io.Path;
@:build(kiss.Kiss.build())
class Archive {}
class Archive {}

View File

@@ -1,11 +1,13 @@
(defnew [archiveDir]
[:Map<String,Entry> entries
(let [entryFiles (FileSystem.readDirectory archiveDir)]
(doFor ))
(for file entryFiles =>(file.withoutExtension) ~(Json.parse (File.getContent (Path.join [archiveDir file])))))
:Array<System> systems []] // TODO also create systems
// TODO register entities to systems that want them
)
(defun loadFromDir [archiveDir]
)
(defmethod :Void handleEvent [:Event e]
(throw "can't handle $e"))
(defmethod :Void handleEvent [:Event e])
(defmethod :Void process []
(doFor system systems (system.process)))

View File

@@ -0,0 +1,17 @@
package nap;
import kiss.KissInterp;
class BoolExpInterp extends KissInterp {
public function new() {
super();
}
override function resolve(id:String):Dynamic {
return try {
super.resolve(id);
} catch (e:Dynamic) {
false;
}
}
}

View File

@@ -4,4 +4,4 @@ package nap;
* All types of user input events to the NAP system. Archive handles these, acting as a backend
* for whichever front-end generates the Events.
*/
enum Event {}
enum Event {}

View File

@@ -0,0 +1,9 @@
package nap;
import kiss.Prelude;
import kiss.Stream;
import hscript.Parser;
import hscript.Interp;
@:build(kiss.Kiss.build())
class Lib {}

View File

@@ -0,0 +1,9 @@
(defun evalBoolExp [:String expStr :Array<String> activeConditions]
(let [hscriptExp
(.parseString (new Parser)
(Prelude.convertToHScript expStr))
interp
(new BoolExpInterp)]
(doFor condition activeConditions
(interp.variables.set condition true))
?(interp.execute hscriptExp)))

View File

@@ -1,11 +1,17 @@
(defun :Void main []
~(Lib.evalBoolExp "true" [])
~(Lib.evalBoolExp "false" [])
~(Lib.evalBoolExp "flag" [])
~(Lib.evalBoolExp "flag" ["flag"])
~(Lib.evalBoolExp "(and flag false)" ["flag"])
~(Lib.evalBoolExp "(or flag otherFlag)" ["otherFlag"])
//trace(error);
(let [archiveDir
// TODO pattern matching program arguments will be more complicated once --cache and other arguments are introduced
(ifLet [[dir] (Sys.args)]
dir
(Sys.getCwd))
// TODO optional flags like --cache will complicate this way of handling args
(.shift (Sys.args))
archive
(new Archive archiveDir)]
// TODO run a front-end -- could be a test frontend that sends predetermined list of events
(archive.process)))

View File

@@ -1,4 +1,6 @@
package nap;
import kiss.Prelude;
@:build(kiss.Kiss.build())
class System {}
class System {}

View File

@@ -1 +1,10 @@
(defprop :List<Entry> entries [])
(defprop :List<Entry> entries (new List))
(defmethod :Void process []
(entries.map processEntry))
(defmethod :Void processEntry [:Entry e]
(throw "can't process $e"))
(defmethod :Bool canProcessEntry [:Entry e]
(throw "can't decide whether to process $e"))

View File

@@ -1,3 +1,3 @@
package nap.components;
typedef Tag = String;
typedef Tag = String;

View File

@@ -0,0 +1,6 @@
package nap.systems;
import kiss.Prelude;
@:build(kiss.Kiss.build())
class TagSystem extends System {}

View File

@@ -0,0 +1,4 @@
(defnew [&prop :String tagFilterString])
(defmethod &override :Bool canProcessEntry [:Entry e]
)

View File

@@ -1,3 +1,4 @@
#! /bin/bash
haxe build.hxml
haxelib dev nap .
haxelib run nap example-archive