[nap] multi-purpose bool expression evaluator for nap
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
-lib uuid
|
-lib uuid
|
||||||
-lib kiss
|
-lib kiss
|
||||||
|
-lib hscript
|
||||||
-cp src
|
-cp src
|
||||||
--main nap.Main
|
--main nap.Main
|
||||||
--interp
|
--interp
|
||||||
1
projects/nap/example-archive/song1.json
Normal file
1
projects/nap/example-archive/song1.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"name":"Villain Alcohol","id":"song1","components":{"Tag":["song"]}}
|
||||||
15
projects/nap/haxelib.json
Normal file
15
projects/nap/haxelib.json
Normal 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": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package nap;
|
package nap;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
import sys.FileSystem;
|
import sys.FileSystem;
|
||||||
|
import sys.io.File;
|
||||||
|
import haxe.Json;
|
||||||
|
|
||||||
|
using haxe.io.Path;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class Archive {}
|
class Archive {}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
(defnew [archiveDir]
|
(defnew [archiveDir]
|
||||||
[:Map<String,Entry> entries
|
[:Map<String,Entry> entries
|
||||||
(let [entryFiles (FileSystem.readDirectory archiveDir)]
|
(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
|
: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)))
|
||||||
17
projects/nap/src/nap/BoolExpInterp.hx
Normal file
17
projects/nap/src/nap/BoolExpInterp.hx
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,4 +4,4 @@ package nap;
|
|||||||
* All types of user input events to the NAP system. Archive handles these, acting as a backend
|
* All types of user input events to the NAP system. Archive handles these, acting as a backend
|
||||||
* for whichever front-end generates the Events.
|
* for whichever front-end generates the Events.
|
||||||
*/
|
*/
|
||||||
enum Event {}
|
enum Event {}
|
||||||
|
|||||||
9
projects/nap/src/nap/Lib.hx
Normal file
9
projects/nap/src/nap/Lib.hx
Normal 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 {}
|
||||||
@@ -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)))
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
(defun :Void main []
|
(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
|
(let [archiveDir
|
||||||
// TODO pattern matching program arguments will be more complicated once --cache and other arguments are introduced
|
// TODO optional flags like --cache will complicate this way of handling args
|
||||||
(ifLet [[dir] (Sys.args)]
|
(.shift (Sys.args))
|
||||||
dir
|
|
||||||
(Sys.getCwd))
|
|
||||||
archive
|
archive
|
||||||
(new Archive archiveDir)]
|
(new Archive archiveDir)]
|
||||||
|
// TODO run a front-end -- could be a test frontend that sends predetermined list of events
|
||||||
(archive.process)))
|
(archive.process)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
package nap;
|
package nap;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class System {}
|
class System {}
|
||||||
|
|||||||
@@ -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"))
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
package nap.components;
|
package nap.components;
|
||||||
|
|
||||||
typedef Tag = String;
|
typedef Tag = String;
|
||||||
|
|||||||
6
projects/nap/src/nap/systems/TagSystem.hx
Normal file
6
projects/nap/src/nap/systems/TagSystem.hx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nap.systems;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class TagSystem extends System {}
|
||||||
4
projects/nap/src/nap/systems/TagSystem.kiss
Normal file
4
projects/nap/src/nap/systems/TagSystem.kiss
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
(defnew [&prop :String tagFilterString])
|
||||||
|
|
||||||
|
(defmethod &override :Bool canProcessEntry [:Entry e]
|
||||||
|
)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
haxe build.hxml
|
haxelib dev nap .
|
||||||
|
haxelib run nap example-archive
|
||||||
Reference in New Issue
Block a user