Skip to content

Instantly share code, notes, and snippets.

@Simn
Created March 21, 2016 15:56
Show Gist options
  • Save Simn/fbb670a0196b4bf42d97 to your computer and use it in GitHub Desktop.
Save Simn/fbb670a0196b4bf42d97 to your computer and use it in GitHub Desktop.
Nicolas about Haxe #3
import haxe.macro.Context;
import haxe.macro.Expr;
class MyMacro {
public static function build( url : String ) {
var h = haxe.Http.requestUrl(url);
//trace(h);
var r = ~/id=["']([A-Za-z0-9]+)["']/;
var ids = [];
while ( r.match(h) ) {
var id = r.matched(1);
ids.remove(id);
ids.push(id);
h = r.matchedRight();
}
var fields = Context.getBuildFields();
var gtype = TAnonymous([for ( id in ids ) { name : id, pos : Context.currentPos(), kind : FVar(macro : String) }]);
var gids : Field = {
name : "gids",
pos : Context.currentPos(),
kind : FVar(gtype),
access : [AStatic],
};
fields.push(gids);
return fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment