Is there a way to escape the $ in haxe macro expressions?

As the title suggests, is there a way to escape the $ sign in macro context to prevent reification.

I have the following in Haxe which doesn’t work:

var searchable = searchableFields[0];

var searchBody = macro {
    var items = manager.search($$$searchable.like(value));

};

The manager.search function is from record-macros which is a function which takes an macro Expr, so I need a way somehow to escape the $ character so that it’s used in place rather than reified with the following expression.

The value of searchable would be title, which I would expect to translate to $title.like(value).

Is this possible?

I’m not sure if it’s possible with reification (maybe it should be), but you can always construct Expr instances directly and pass a string with $ to CIdent, EField and friends :slight_smile:

If you want to generate an identifier $title, then your searchable should contain a string "$title" and then this should work: macro $i{searchable}.
http://try-haxe.mrcdk.com/#83Bea

Ahhhh… I didn’t think of that. Thank you. I will test it out soon.

I often write this: macro $i{"$type"}(value)

That could be written as macro $$type(value)

1 Like