smooch
This commit is contained in:
@@ -68,9 +68,12 @@ typedef KissState = {
|
||||
|
||||
class Kiss {
|
||||
#if macro
|
||||
public static function defaultKissState():KissState {
|
||||
var className = Context.getLocalClass().get().name;
|
||||
|
||||
public static function defaultKissState(?name):KissState {
|
||||
var className = if(name == null){
|
||||
Context.getLocalClass().get().name;
|
||||
}else{
|
||||
name;
|
||||
}
|
||||
var k = {
|
||||
className: className,
|
||||
file: "",
|
||||
@@ -273,7 +276,7 @@ class Kiss {
|
||||
/**
|
||||
Build macro: add fields to a class from a corresponding .kiss file
|
||||
**/
|
||||
public static function build(?kissFile:String, ?k:KissState, useClassFields = true):Array<Field> {
|
||||
public static function build(?kissFile:String, ?k:KissState, useClassFields = true, ?className:String):Array<Field> {
|
||||
|
||||
var classPath = Context.getPosInfos(Context.currentPos()).file;
|
||||
// (load... ) relative to the original file
|
||||
@@ -289,7 +292,7 @@ class Kiss {
|
||||
trace(kissFile);
|
||||
#end
|
||||
if (k == null)
|
||||
k = defaultKissState();
|
||||
k = defaultKissState(className);
|
||||
|
||||
if (useClassFields) {
|
||||
k.fieldList = Context.getBuildFields();
|
||||
|
8
projects/smooch/build.hxml
Normal file
8
projects/smooch/build.hxml
Normal file
@@ -0,0 +1,8 @@
|
||||
-lib kiss
|
||||
-cp src
|
||||
--macro kiss.Kiss.setup()
|
||||
--macro KissFrontend.use()
|
||||
-lib tink_syntaxhub
|
||||
--main smooch.Main
|
||||
--interp
|
||||
|
17
projects/smooch/haxelib.json
Normal file
17
projects/smooch/haxelib.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"main": "smooch.Main",
|
||||
"name": "smooch",
|
||||
"description": "auto build kiss scripts",
|
||||
"classPath": "src/",
|
||||
"dependencies": {
|
||||
"kiss": ""
|
||||
},
|
||||
"url": "https://github.com/NQNStudios/kisslang",
|
||||
"contributors": [
|
||||
"NQNStudios"
|
||||
],
|
||||
"version": "0.0.0",
|
||||
"releasenote": "",
|
||||
"tags": [],
|
||||
"license": "LGPL"
|
||||
}
|
29
projects/smooch/src/KissFrontend.hx
Normal file
29
projects/smooch/src/KissFrontend.hx
Normal file
@@ -0,0 +1,29 @@
|
||||
package;
|
||||
|
||||
import kiss.Kiss;
|
||||
import tink.syntaxhub.*;
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr.ImportMode;
|
||||
|
||||
class KissFrontend implements FrontendPlugin {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function extensions()
|
||||
return ['kiss'].iterator();
|
||||
|
||||
public function parse(file:String, context:FrontendContext):Void {
|
||||
|
||||
final fields = Kiss.build(file,null,false,context.name);
|
||||
var pos = Context.makePosition({ file: file, min: 0, max: 999 });
|
||||
trace(context.name);
|
||||
final type = context.getType();
|
||||
context.addImport('kiss.Prelude',INormal,pos);
|
||||
for (field in fields){
|
||||
type.fields.push(field);
|
||||
}
|
||||
}
|
||||
static function use()
|
||||
tink.SyntaxHub.frontends.whenever(new KissFrontend());
|
||||
}
|
15
projects/smooch/src/LeetCode.kiss
Normal file
15
projects/smooch/src/LeetCode.kiss
Normal file
@@ -0,0 +1,15 @@
|
||||
// solution to: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
|
||||
(function :Array<Int> twosum [:Array<Int> numbers target]
|
||||
(let [di (new Map<Int,Int>)]
|
||||
(doFor [i num] (enumerate numbers 1)
|
||||
// (print "$i $num")
|
||||
(if (di.exists (- target num))
|
||||
(return [(dictGet di (- target num)) i]))
|
||||
(dictSet di num i)))
|
||||
(return null))
|
||||
|
||||
(assert (= (.toString [2 3]) (.toString (twosum [1 2 3 4 5 6] 5))))
|
||||
(assert (= (.toString [1 2]) (.toString (twosum [2 7 11 15] 9))))
|
||||
(assert (= (.toString [1 3]) (.toString (twosum [2 3 4] 6))))
|
||||
(assert (= (.toString [1 2]) (.toString (twosum [-1 0] -1))))
|
||||
(trace "here")
|
10
projects/smooch/src/smooch/Main.hx
Normal file
10
projects/smooch/src/smooch/Main.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
package smooch;
|
||||
|
||||
import LeetCode;
|
||||
|
||||
class Main{
|
||||
static public function main(){
|
||||
trace('main');
|
||||
@:privateAccess LeetCode.main();
|
||||
}
|
||||
}
|
3
projects/smooch/test.sh
Executable file
3
projects/smooch/test.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#! /bin/bash
|
||||
|
||||
haxe build.hxml
|
Reference in New Issue
Block a user