Closed jcward closed 6 years ago
Example type gen: https://github.com/ncannasse/castle/blob/master/cdb/Module.hx
import haxe.macro.Printer;
import haxe.macro.Expr;
...
var fakePos = { file:'Untitled', min:0, max:0 };
var td:TypeDefinition = {
pack:[],
name:'Foo',
pos:fakePos,
meta:[],
params:[],
kind:TDStructure,
fields:[]
}
td.fields.push( { name : "abc", pos : fakePos, kind : FVar(macro :Int), meta:[{ name:':optional', pos:fakePos }] } );
trace(td);
var p = new Printer();
trace(p.printTypeDefinition(td));
Prints:
typedef Foo = {
@:optional
var abc : Int;
}
Fixed via fragment_wip branch merge.
Introduced intermediate AST data structures, some of which are Haxe-compatible and mapped through the haxe.macro.Printer
. Though I had to copy & modify Printer.hx
to output the preferred short format structs.
For the macro workflow, it will be necessary to generate Haxe AST (e.g.
Array<TypeDefinition>
) instead of writing Haxe strings directly.