scala.reflect.Code (aka expression trees / AST manipulation) would actually
be great -- what was proposed was far from it, though.

As I understand it, this approach has not advanced in about 2 years.  I'd be
happy to hear if it was a viable option, even if only on 2.8.

alex


On Sun, Dec 13, 2009 at 4:50 PM, Naftoli Gugenheim <naftoli...@gmail.com>wrote:

> Looks like a neat approach.
> It would be great if it was possible to get a better syntax though. It
> might not be worth the effort or stable enough, but have you seen
> scala.reflect.Code? scalac can compile code into an AST.
>
>
> -------------------------------------
> Marius Danciu<marius.dan...@gmail.com> wrote:
>
> All,
>
> I just want to see if there is any interest in the approach discussed here.
> As you know Lift has some interesting support for building JavaScript
> constructs from Scala code usig JsExp, JsCmd etc classes. I used quite a
> lot
> this support and it's great but if your JS code that you want to send down
> to the browser (say as an Ajax or Comet partial update response) gets a bit
> more complicated then constructing the JS fragment leads IMO to some
> cumbersome Scala code. I found myselft in quite a few situation to use
> JsRaw
> to write the JavaScript fragment in order for the code reader to understand
> what JavaScript code will be generated. But of course with JsRaw we put
> everything into a String so I'm not a big fan of this approach. So I
> started
> to define a JavaScript like "DSL" that IMO is closer to JavaScript form.
> Attached is a source code smaple of how this looks like, so for instance we
> can have something like:
>
>
> val js = JsFunc('myFunc, 'param1, 'param2) {
>    JsIf('param1 __< 30) {
>        Var('home) := Wrap(234 __- 3) __/ 2 `;`
>        Var('someArray) := JsArray(1, 2, 3, 4, 5) `;`
>        'myFunc(1, 2, "do it", 'home) `;`
>        $("#myID") >> 'attr("value", "123") `;`
>      } ~
>      JsForEach(Var('i) in 'someArray) {
>        'console >> 'log("Hi there " __+ 'i) `;`
>      } ~
>      JsAnonFunc('arg1, 'arg2) {
>       'alert("Anonymous function " __+ 'arg1 __+ 'arg2)
>      }(1, 2) `;`
>    }
>
>    println(js.toJs)
>
> this yields the following JavaScript code:
>
>
> function myFunc( param1, param2 ) {
> if (param1 < 30) {
> var home = ( 234 - 3 ) / 2;
> var someArray = [ 1, 2, 3, 4, 5 ];
> myFunc(1, 2, "do it", home);
> $("#myID").attr("value", "123");
> }
> for (var i in someArray) {
> console.log("Hi there " + i);
> }
> function ( arg1, arg2 ) {
> alert("Anonymous function " + arg1 + arg2)
> }(1, 2);
> }
>
>
> ... ok I just droped nonsense code in there for exemplification. A few
> words:
>
> 1. JsIf, JsForEach describe JavaScript if and for(each) statements
> 2. Functions like __<, __>, ... __+, __- are function that alows definition
> of boolean and/or algebraic expressions.
> 3. Wrap just wraps an expression into ()
> 4. Var defined a variable
> 5 := defines an assignment
> 6. JsFunc declares a JS function
> 7. JsAnonFunc declares an anonymous function
> 8. 'myFunc(1, 2, "do it", 'home)  is simply a javascript function
> invocation
> by providing 4 parameter.
> 9. ~ is just a function that chains statements that don;t necessarily end
> in
> ;
>
>
> Do you think that something like this would be usable in Lift?
>
> Br's,
> Marius
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to