Macro: Expression As A String Without The expr: { ExprDef } Notation

66 views
Skip to first unread message

Arnim Schachtschabel

unread,
Jul 8, 2016, 8:35:41 AM7/8/16
to Haxe
Hello Community,

I would like to convert the "original" expression as a string as it is. It's supposed not be the HAXE expression notation, that simply could be retrieved.

E.g.:
var arr : Array<String> = [ "Toll!!!", "Fantastisch!", "Großartig!!!" ];

becomes

"var arr : Array<String> = [ "Toll!!!", "Fantastisch!", "Großartig!!!" ];"

instead of

"{ expr => EArrayDecl([{ expr => EConst(CString(Toll!!!)), pos => #pos(src/Main.hx:231: characters 36-45) },
{ expr => EConst(CString(Fantastisch!)), pos => #pos(src/Main.hx:231: characters 47-61) },
{ expr => EConst(CString(Großartig!!!)), pos => #pos(src/Main.hx:231: characters 63-78) }]),
pos => #pos(src/Main.hx:231: characters 34-80) }"


Do I need to put it together sub-expression by sub-expression?
Or is there a handy trick (with one click)?



Background:

I would like to have inspected code shown as it is in the original HAXE notation as well as a nested structure carrying some more informations that can be evaluated or can be filtered out.

So, it becomes possible to check different variables at different times or to debugg a whole network of informations...

This differs from the conventional debugging concepts, that usually throw out specific variable values at the time they occur.

Let yourself be suprised what debugging might become...
;-)

I am curious for your suggestions.

Kind regards
Arnim

Andreas Mokros

unread,
Jul 8, 2016, 8:44:51 AM7/8/16
to haxe...@googlegroups.com
Hi.

On Fri, 8 Jul 2016 05:35:40 -0700 (PDT)
Arnim Schachtschabel <in...@loxogon.de> wrote:
> I would like to convert the "original" expression as a string as it is.

What about ExprTools.toString?

--
Mockey

Arnim Schachtschabel

unread,
Jul 8, 2016, 9:03:39 AM7/8/16
to Haxe

Hello Mockey,

thank you very much.

Yes, you are absolutely right. I thaught, this would lead to the complex expression notation... Stupid me ;-)

Kind regards
Arnim

szczepan

unread,
Jul 8, 2016, 12:12:50 PM7/8/16
to Haxe
Are you trying to parse Haxe source code to inspect it? If so, then I think it's counterproductive - Haxe macros already provide those facilities and you won't be able to inspect macro transformed code.

You could run Haxe compiler with original compile flags adding '--no-output' and '--macro your.inspection.Macro.inspect()' with a macro doing code analysis and what not. You can run it as a compilation server and store results in memory (if I remember correctly Jason's compile-time library has an example of complex structure stored by macro) or save it to file and read it first on every run (server or not).

Arnim Schachtschabel

unread,
Jul 8, 2016, 12:58:11 PM7/8/16
to Haxe

Hello Szczepan,

thank you for your hint.

I am writing an inspector that does not deliver an output 1:1 like a conventional debugger.

I have asked about the expression to string, because I want to show the original source code for each inspection step. 

A conventional debugger helps you, to run through the code. And every step shows a specific variable with a specific value or a specific function call.

But it only delivers a certain information at a certain time.

My concept is to collect a maximum of information during runtime and to integrate it into a complexe and nested structure. When this is done, it is evaluated by showing the whole structure. Specific scopes and variable states can be scipped and/ or focussed.

It is handled like conventional debugging (to get the same "look-&-feel"). But it will offer more possibilities for evaluation. For example, it will be possible to change the focus. So, you can look at different aspects of the runtime values without to start your debugging process from the very beginning.

The concept is drafted at gitHub

When it is finished, it will become more clearly, what I mean, and it will be much better documented then now...

Kind regards
Arnim


Reply all
Reply to author
Forward
0 new messages