Tuesday, May 11, 2010

DSL language for maximizing speed input

I recently had the following case . I was given the domain model bellow and was asked to provide a solution so a user could add schedules of the form Thu-Wen 14.15 / 16.45, Thu & Mon-Wen 22.15 /00.45, Sat,Sun 12.15 3D translated into with the maximum input speed.

image

Xaf by its self is going to create for us a view like the one bellow for allowing us to make such an input from one view but of course that view is out of the question ( too many keyboard strokes and clicks)

image

What we need is to define a Domain Specific Language (just the definition of our problem will do it :)) for our problem lets do it.

I am creating schedules. So the user  input schedules will be of the form
Thu-Wen 14.15 / 16.45, Thu & Mon-Wen 22.15 /00.45, Sat,Sun 12.15 3D translated
or
Thu-Wen 14.15 /16.45 Mon 14.15
given the characters TFSAMBW for each day of the week starting from thurday ->T ,friday->F and so on i would expect the following input for 1st schedule above
T-W14151645TM-W22150045SA1215DL
this way the user input speed is almost maximun

hmm k i could solve that with a very complex regex but would be really hard to have hour validation(<24) and minute and what if my user ask for something more later? How the heck i am going to dig in again in that complex regex? There must be a more .NET answer for this lets google it.

1st choice

ANTLR language defintion tool, which is a great tool but requires Java installation and is too complex too learn just for such a simple scenario

http://www.antlr.org/

2nd Choice

Spart – Parser Generator FrameWork . Seems a simple one and surely feeds my needs . Was written Jonathan de Halleux creator of undless open source project. We all thnk Pelli about its contribution to the community but not so sure about the support of Spart (Last updated 23 Dec 2003). Have to continue searching

Final Choice

Irony - .NET Language Implementation Kit.  is a development kit for implementing languages on .NET platform. It uses the flexibility and power of c# language and .NET Framework 3.5 to implement a completely new and streamlined technology of compiler construction. (>6000 download last update October 2009)

This seems to be the one!!! Support forums are also very active . Here is a very very interesting article that i suggest everyone to read it. Its all about the way of thinking when using the framework.

oK enough words after i read the YourFirstDSL article i was ready to try the framework but still was very inexperienced on its inner about and was on a deadline so i thought i could try their support. So i posted here my exact scenario as i wrote it above and Voilla after some hours Irony guys have implement it for me. Excellent work guys!!! What a great framework!!!.

The solution that support has given is able to create to create an xml structure of the following form. Which can be transformed easy to my business objects

image

what is left is to add a non persistent property to my Schedule class in order the user to input characters another one readonly properties that irony will display parser errors and messages and i have my solution ready!!!

ps:Irony framework provides a way of making the parsing of the xml easier but making it strongly type

Long live Irony!!!!

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus