New anon macro.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

New anon macro.

sledorze
Hi!

I've just committed a new macro;
A macro I've missed for too much time and has just become unavoidable as I do more mongo queries those days.
It allows to generate anon object with fancy identifiers names like that:


    var res =
      "
      {
        $inc : {
          toto.tata : 5,
          xzzzz : {
            tetete : '12',
            $inc : 5,
            $dec : 15,
            tototo : '54',
          }
          tata : 6,
        },
        $dec : {
          foo : 5
        },
      }
      ".anon();

this generates this code:

  {
    var r_e_s = { };
    Reflect.setField(r_e_s, '$inc', {
      var r_e_s = {
        xzzzz : {
          var r_e_s = {
            tetete : '12',
            tototo : '54'
          };
          Reflect.setField(r_e_s, '$inc', 5);
          Reflect.setField(r_e_s, '$dec', 15);
          r_e_s;
        },
        tata : 6
      };
      Reflect.setField(r_e_s, 'toto.tata', 5);
      r_e_s;
    });
    Reflect.setField(r_e_s, '$dec', {
      foo : 5
    });
    r_e_s;
  }

The code is on my still missnamed github account : https://github.com/sledorze/haxeExtensionBuilder

A known limitation is that I've done a basic parser for this macro and it may fail if your values contain either a '{', '}' or ':' in it.
I will upgrade it with a correct one as soon as remaining more importants needs I have are fufilled.

Enjoy!
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: New anon macro.

sledorze
Oh.. as the example does not show it; every normal part will not generate extra code.
Reply | Threaded
Open this post in threaded view
|

Re: New anon macro.

Tarwin Stroh-Spijer
Sweet! Thanks heaps - had that stupid MongoDB problem :(


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Fri, Nov 4, 2011 at 4:58 PM, sledorze <[hidden email]> wrote:
Oh.. as the example does not show it; every normal part will not generate
extra code.


--
View this message in context: http://haxe.1354130.n2.nabble.com/New-anon-macro-tp6964568p6964580.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org