added meta parser
This commit is contained in:
1
extraParams.hxml
Normal file
1
extraParams.hxml
Normal file
@@ -0,0 +1 @@
|
||||
--macro haxework.parser.Parser.auto()
|
||||
@@ -4,7 +4,7 @@
|
||||
"license": "BSD",
|
||||
"tags": ["flash", "openfl"],
|
||||
"description": "Framework.",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"releasenote": "Update.",
|
||||
"contributors": ["shmyga"],
|
||||
"classPath": "src/main",
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package haxework.gui;
|
||||
|
||||
#if macro
|
||||
import haxework.gui.build.Builder;
|
||||
#end
|
||||
|
||||
@:remove @:autoBuild(haxework.gui.ViewBuilderImpl.build())
|
||||
extern interface ViewBuilder {}
|
||||
|
||||
class ViewBuilderImpl {
|
||||
#if macro
|
||||
public static function build() {
|
||||
return new Builder().build();
|
||||
}
|
||||
public static function build() {
|
||||
return new Builder().build();
|
||||
}
|
||||
#end
|
||||
}
|
||||
75
src/main/haxework/parser/Parser.hx
Normal file
75
src/main/haxework/parser/Parser.hx
Normal file
@@ -0,0 +1,75 @@
|
||||
package haxework.parser;
|
||||
|
||||
import haxe.macro.Expr;
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
#end
|
||||
import haxe.macro.Type;
|
||||
import haxe.macro.Type.ClassType;
|
||||
import haxe.macro.Type.Ref;
|
||||
|
||||
|
||||
class Parser {
|
||||
|
||||
#if macro
|
||||
private static function auto():Void {
|
||||
haxe.macro.Compiler.addGlobalMetadata("", "@:build(haxework.parser.Parser.autoRun())", true, true, false);
|
||||
}
|
||||
|
||||
private static macro function autoRun():Array<Field> {
|
||||
var t:Type = Context.getLocalType();
|
||||
switch (t) {
|
||||
case null: return null;
|
||||
case Type.TInst(_.get() => ct, _):
|
||||
var hasMeta:Bool = false;
|
||||
var hasAutoBuild:Bool = false;
|
||||
for (md in ct.meta.get())
|
||||
if (md.name == ":haxework") {
|
||||
hasMeta = true;
|
||||
}
|
||||
if (hasMeta) {
|
||||
var result:Array<Field> = [];
|
||||
var fields:Array<Field> = Context.getBuildFields();
|
||||
for (field in fields) {
|
||||
var remove:Bool = false;
|
||||
for (md in field.meta)
|
||||
if (md.name == ":provide") {
|
||||
var type:ComplexType = switch field.kind {
|
||||
case FieldType.FVar(t): t;
|
||||
default: null;
|
||||
}
|
||||
var name:String = switch type {
|
||||
case ComplexType.TPath(p): p.name;
|
||||
default: null;
|
||||
}
|
||||
remove = true;
|
||||
result.push({
|
||||
name: field.name,
|
||||
access: [Access.APublic],
|
||||
pos: field.pos,
|
||||
kind: FieldType.FProp('get', 'never', type)
|
||||
});
|
||||
result.push({
|
||||
name: 'get_${field.name}',
|
||||
access: field.access,
|
||||
pos: field.pos,
|
||||
kind: FieldType.FFun({
|
||||
args: [],
|
||||
expr: Context.parse('return haxework.provider.Provider.get(${name})', field.pos),
|
||||
params: [],
|
||||
ret: type
|
||||
})
|
||||
});
|
||||
}
|
||||
if (!remove) {
|
||||
result.push(field);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
Reference in New Issue
Block a user