Boo Flex DSL

Posted on November 20, 2007

XML is supposed to be human-readable not writable so here is a prototype of Boo DSL for Adobe Flex 3 aka BooFlex ;-)

BooFlex Code (version 1.0 generated from ASDoc)

Example of BooFlex program (looks very LISPy)

nnamespace NAXSoft.MX.Demo
import NAXSoft.BooFlex.MxDsl
import NAXSoft.BooFlex.MxDslExtra
import NAXSoft.BooFlex.MxLiterals

Application {"xmlns:mx": "http://www.adobe.com/2006/mxml" }:
    Script { source: "file1.as" }
    DataGrid { id: "myGrid", dataProvider: "{initDG}", variableRowHeight: "true" }:
        Columns:
             DataGridColumn { dataField: "Artist"}
             DataGridColumn { dataField: "Album" }
             DataGridColumn { dataField: "Cover" }:
                 ItemRenderer:
                     Component {id: "CoverRenderer", className: "CoverRenderer"}:
                         VBox:
                             Script   { source: "file2.ac" }    
                             Text     { id: "albumName", text: "{data.Album}" }
                             Image    { id: "albumImage", source: "data.Cover" }
                             TextArea { text: "{’Renderer localVar= ‘ + localVar}" }
                             TextArea { text: "{outerDocument.localVar}" }
             DataGridColumn { dataField: "Price" }

And the result:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script source="file1.as" />
<mx:DataGrid variableRowHeight="true" dataProvider="{initDG}" id="myGrid" >
<mx:columns >
<mx:DataGridColumn dataField="Artist" />
<mx:DataGridColumn dataField="Album" />
<mx:DataGridColumn dataField="Cover" >
<mx:ItemRenderer >
<mx:Component className="CoverRenderer" id="CoverRenderer" >
<mx:VBox >
<mx:Script source="file2.ac" />
<mx:Text id="albumName" text="{data.Album}" />
<mx:Image source="data.Cover" id="albumImage" />
<mx:TextArea text="{’Renderer localVar= ‘ + localVar}" />
<mx:TextArea text="{outerDocument.localVar}" />
</mx:VBox>
</mx:Component>
</mx:ItemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="Price" />
</mx:columns>
</mx:DataGrid>
</mx:Application>

What do you think?

Filed Under Uncategorized |

9 Comments so far
  1. Guillaume Theoret November 22, 2007 2:01 pm

    I don’t know flex so perhaps it isn’t even needed but does flex use nothing but xml properties? Doesn’t is ever have something like text?

    One more thing.. wouldn’t it be easier to make your parser perhaps a bit more complex (depending on your definition of complex) but not have to write out cases for each element? That way your dsl could instead look like
    Group {’type’:'application’}:
    Group {’type’:'dataGrid’, ‘id’:'datagrid}:
    Element {’type’:'dataGridColumn’, ‘headerText’:'Column 1′, ‘dataField’:'col1′ }

    etc
    This would also allow you to define a ‘body’ that does something like:
    Element {’type’:'dataGridColumn’, ‘headerText’:'Column 1′, ‘dataField’:'col1′, ‘body’:’some text’ }
    =>
    some text

  2. Guillaume Theoret November 22, 2007 2:03 pm

    Hmm your comments don’t like < and > tags.

    “something like text?” is supposed to be:
    something like <button>text</button>

    and the last line: “some text” is supposed to be:
    <mx:DataGridColumn dataField=”col1″ headerText=”Column 1″>some text</mx:DataGridColumn>

  3. David S. November 22, 2007 3:48 pm

    Ok let me get this straight, you made a parser in order to not have to write “mx:” ??
    YOU LAZY BASTARD!

  4. elendal November 22, 2007 4:22 pm

    What I don’t like is the verbosity of XML. I like the how easy to read BooFlex script is.

    I think it is OK to create UI layout in it. But I don’t want to buy IDE to create XML UI.

    What I think to do next is to write a parser for AsDOC (ActionScript doc (the MXML is actually translated to ActionScript where every XML element is a class in ActionScript (very cool))) to generate BooFlex builder. Which I could use to generate MXML.

    Why would I try to do this? Well I could use IDE that supports Boo and get all kind of nice features (code completion, help, refactoring).

    I made some small changes to the script. I will upload it later.

  5. elendal November 22, 2007 5:55 pm

    Testing tags:

    <?php
    echo "<a href=’foo.php?text=".urlencode("foo?&bar!")."’>link</a>";
    ?>

  6. elendal November 22, 2007 5:56 pm

    Guillaume you should add htmlspecialchars(..) to your wp-comments-post.php too.

    Like this:
    $comment_content = trim(htmlspecialchars($_POST[’comment’]));

  7. elendal November 22, 2007 6:07 pm

    Guillaume <button>text</button> can be easily done with:

    1: button:
    2: text "Hello, world!"

    1: def blockTag(tagName as string, block as Block):
    2: print "<${tagName}>"
    3: block()
    4: print "</${tagName}>"
    5: def text(s as string):
    6: print s

  8. elendal November 22, 2007 6:27 pm

    > One more thing.. wouldn’t it be easier to make your parser
    > perhaps a bit more complex but not have to write out cases
    > for each element?

    It’s not yet a parser. It’s a code generator.
    I may write a parser to generate it from Adobe code.

    > That way your dsl could instead look like
    > Group {’type’:’application’}:
    > Group {’type’:’dataGrid’, ‘id’:’datagrid}:

    I think I will generate all useful combinations for each mx:element.

    static def element(args as Hash, block as Block):
    blockTag "mx:Element", args, block

    static def element(args as Hash):
    shortTag "mx:Element", args

    static def element(block as Block):
    blockTag "mx:Element", {}, block

  9. elendal November 23, 2007 2:56 am

    v1.0 Generate booFlex builder from ASDoc source.

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name

Email

Website

Comments

For spam detection purposes, please copy the number 8922 to the field below:

© Copyright 0xDEADBEEFCAFE • Powered by Wordpress • Design by Sebastin.

free web hit counter