April 20th, 2009

Creating a simple Textual DSL with Oslo, “M” Language, MGrammar and Intellipad

Cesar De la Torre
Principal Program Manager

image

I wrote a post about Oslo and “M” Language and how you can use it to model data. But in that case, we were not using our own custom Textual DSL, we were using just “M” Language. You can see that post here:

Starting using OSLO, “M” Language, Oslo Repository and Intellipad

http://blogs.msdn.com/cesardelatorre/archive/2009/04/20/starting-using-oslo-m-language-oslo-repository-and-intellipad.aspx

What I’m going to create now, is a Custom Textual DSL sample (DSL == Domain Specific Language), based on Oslo. It is going to be very, very simple. I just want to show the essence of “M” Language and MGrammar and how we can use Intellipad for that.

Intellipad is a text editor that comes with OSLO SDK, but as you can suppose (because of its name) it is kind of “intelligent”, I mean, it is Oslo Textual DSL oriented. 😉

I’m using OSLO SDK January CTP (Kind of a OSLO’s Pre-Beta). You can download it from this URL:

Microsoft “Oslo” SDK – January 2009 CTP (Refresh)

http://www.microsoft.com/downloads/details.aspx?FamilyID=f2f4544c-626c-44a3-8866-b2a9fe078956&displaylang=en

Basically, Intellipad gives you support for creating custom DSLs using the MGrammar language.

1.- Starting Intellipad with MGrammar support

Launch Intellipad with sample plug-ins loaded (from the start menu, Oslo SDK,  Icon called “Intellipad (Samples Enabled)”)or pass it a startup configuration file that includes the samples directory (startup config files are specified using the /c option). An example would be: ipad.exe /c: ipad-vs-samples.xaml

In the future, the MGrammar Language support will not require loading with samples. This is just because of this beta.

So now, change Intellipad mode to “M-Grammar”, like the following:

clip_image002

2.- Input file and our model’s text data

So, instead of starting writing M-Grammar like crazy (you should know its syntax, first), we’re going to start writing our model’s data, I mean, the simplified and even natural text I would like to provide as the origin.

Because of that, create an empty file (like a .TXT file) called “My DSL Input Data.input”, for instance. Put it in any folder you like.

Therefore, we need the pane to start writing in that ‘input file’. You get that pane/window when selecting “MGrammar Mode” menu and then select “Tree Preview”, like in the following screen:

clip_image004

Then, you’ll get a dialog asking for you input file, like this one:

clip_image006

Then, go and select that empty ‘My DSL Input Data’ file.

You’ll see Intellipad in the following form:

clip_image008

Cool!, so let’s start writing something we’d like to be consumed by our TEXTUAL DSL. For instance, the following text:

“Office 2007” by “Microsoft” is “nice”

“Windows 7” by “Microsoft” is “great”

“Visual Studio 2010” by “Microsoft” is “great”

Very simple, so, regarding that text, there are several products, company-names and adjectives, and, in this case, just the terms “by” and “is” are actually my language terms. You’ll see it like this:

clip_image010

So far, very simple. Now, I’m going to write my DSL program based on M-Grammar. You can copy & paste it on the MGrammar Mode pane:

module DemosOslo

{

language MyCatalogLanguage

{

syntax Main = a:Product+ => SoftwareCatalog { valuesof(a) };

syntax Product = productName:Name “by” company:Name “is” rating:Name

=> {ProductName = productName, CompanyName = company, Rating = rating};

token Name = ‘”‘ n:(any – ‘”‘)+ ‘”‘ => n;

interleave IgnoreMe = ” ” | “\n” | “\r”;

}

}

Then, you can see how MGrammar transforms the input text to the final form:

clip_image012

This is the generated data, in case you cannot read it on the copied screen:

SoftwareCatalog{
  {
    ProductName{
      “Office 2007”
    },
    CompanyName{
      “Microsoft”
    },
    Rating{
      “nice”
    }
  },
  {
    ProductName{
      “Windows 7”
    },
    CompanyName{
      “Microsoft”
    },
    Rating{
      “great”
    }
  }
}

Likewise, “M” Language works internally in a similar way, but it uses the M-Grammar program called M.mg (you can find it in the SDK, check it), instead the simple one we’re using here (I called it SoftwareCatalogMGrammar.mg).

Another great example is the new “MUrl” textual DSL, which is a M-based textual DSL and RunTime to build RESTFul Services clients (just the client) in a very simple way. I might write another post about MUrl, because it rocks! 🙂

There’s gonna be another textual DSL to actually build RESTFul services. It is called “MService”, but it is not still released. Douglas Purdy showed it a few weeks ago in MIX09, in Las Vegas. It really looks quite nice, as well.

Just want to highlight that Oslo, “M” Language and Quadrant are tools to create any kind of DSL Tools. Oslo is a “Modeling platform for ALL”. We’re not just talking about data or web-services, we’ll be talking about modeling ANYTHING!. 🙂

Topics
Oslo

Author

Cesar De la Torre
Principal Program Manager

Principal Program Manager at the Azure team.

0 comments

Discussion are closed.