After watching this talk :
http://www.infoq.com/presentations/Design-Your-Own-DSL-with-Groovy

I remembered that I wanted to write about internal DSL in ActionScript.

So first of all what is DSL (for those who are to lazy to follow the wikipedia link)

DSL (Domain Specific Language) is a language that you use for some specific type of problems.
For example you want to draw stuff. You know that if you want to draw something you have to declare a shape that is described by points. The language you create for this one and only problem, should be very specific and clear, so that it is fun to read and write.

There are two ways of creating a Domain Specific Language and also two types of DSLs.

External DSL is a language with natural language syntax that you have to parse by RegEx or a parser.

Internal DSL created by appliance of the language you write this DSL with.

In the talk I have mentioned above, the speaker describes what are the possibilities to create an internal DSL with Groovy, and it is pretty cool ;) .

In my opinion ActionScript provides you with three posibilities of creating a DSL:

First: XML
If you think about it, MXML is also an internal DSL written in XML and read by MXMLC compiler. You could write a framework that could read XML and process something out of this. For example painted something on the stage.

<shape>
  <point x='10', y= '20'/>
  <point x='30' y='40'/>
  <point x='25 y='25'/>
</shape>

Second: Plane Text
Write your domain specific stuff in plain text and parse it with RegEx. Natural language is alway easier to read and write if you describe some simple rules or state.

Third: Object initializer
In my opinion it is the powerful one, because you can add behavior to your DSL

?View Code ACTIONSCRIPT
  var shape = {
     points: [
        {x:10, y:20},
        {x:30, y:40},
        {x:25, y:25}
     ],
     onClick: function(){
          trace(this.points)
     }
  }

As you can see you could create a framework as powerful as Flex that works on DSL created with object intializer syntax, that would look JavaFx like ;) .

3 Responses to “Internal DSL”

  1. [...] can be divided in two categories. One that use internal DSL and others that use external DSL. (for a few months I wrote a short post on internal DSL in ActionScript) In my opinion the problem with internal DSL approach is that you can mix the code inside your [...]

  2. One of the downsides of such DSLs – is lack of autocomplete. I was playing with Lisp-wannabe made of arrays once upon a time like [+, 1, 2, 3] or [define as Function, ...] when I was writing AI for game prototype, but lack of support eventually made it almost useless.

  3. The problem with the tool support is that a tool needs a grammar definition in order to be able to support you :)
    For example if you provide a XSD or DTD for your XML than you will get validation and in some tools autocomplete.

    If you look at JavaFx (I know that the language is dead but still) you have object initialization like in ActionScript or JavaScript, but you provide the type of the object. So the grammar for this DSL is the class definition.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Before you submit form:
Human test by Not Captcha

© 2011 Max Blog Suffusion theme by Sayontan Sinha