Macro question, want to find the "expected identifier"

67 views
Skip to first unread message

Drakim

unread,
Aug 16, 2016, 3:53:20 AM8/16/16
to Haxe

static getExpectedType ():Null<Type>

Returns the type which is expected at the place the macro is called.

This affects usages such as var x:Int = macroCall(), where the expected type will be reported as Int.

Might return null if no specific type is expected or if the calling macro is not an expression-macro.

Source

I need this thing, but instead of the type I wanna know the identifier, I want the "x" part rather than the ":Int" part. Is there a function that already does this, or is it possible to do with some clever macro pattern matching?

(the reason for this is because if the identifier already holds a value, I want to incorporate it into the macro call)

Skial Bainn

unread,
Aug 16, 2016, 1:03:21 PM8/16/16
to haxe...@googlegroups.com
I've thrown together a quick macro over on github that works on the two simple examples in `Main.hx`, which is as far as I've experimented with, but should give you some ideas.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Drakim

unread,
Aug 16, 2016, 4:14:53 PM8/16/16
to Haxe
Thanks Skial, this is amazing!
Reply all
Reply to author
Forward
0 new messages