{"id":1093,"date":"2009-04-20T13:12:00","date_gmt":"2009-04-20T13:12:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/cesardelatorre\/2009\/04\/20\/creating-a-simple-textual-dsl-with-oslo-m-language-mgrammar-and-intellipad\/"},"modified":"2009-04-20T13:12:00","modified_gmt":"2009-04-20T13:12:00","slug":"creating-a-simple-textual-dsl-with-oslo-m-language-mgrammar-and-intellipad","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/creating-a-simple-textual-dsl-with-oslo-m-language-mgrammar-and-intellipad\/","title":{"rendered":"Creating a simple Textual DSL with Oslo, \u201cM\u201d Language, MGrammar and Intellipad"},"content":{"rendered":"<p><P><IMG src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_2.png\" width=\"43\" height=\"43\"> <A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_2.png\"><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_thumb.png\" width=\"47\" height=\"45\"><\/A><\/P>\n<P>I wrote a post about Oslo and \u201cM\u201d 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 \u201cM\u201d Language. You can see that post here:<\/P>\n<P>Starting using OSLO, \u201cM\u201d Language, Oslo Repository and Intellipad<\/P>\n<P><A href=\"http:\/\/blogs.msdn.com\/cesardelatorre\/archive\/2009\/04\/20\/starting-using-oslo-m-language-oslo-repository-and-intellipad.aspx\">http:\/\/blogs.msdn.com\/cesardelatorre\/archive\/2009\/04\/20\/starting-using-oslo-m-language-oslo-repository-and-intellipad.aspx<\/A><\/P>\n<P>What I\u2019m going to create now, is a <B>Custom Textual DSL sample (DSL == Domain Specific Language)<\/B>, based on <STRONG>Oslo<\/STRONG>. It is going to be very, very simple. I just want to show the essence of \u201cM\u201d Language and MGrammar and how we can use Intellipad for that.<\/P>\n<P>Intellipad is a text editor that comes with OSLO SDK, but as you can suppose (because of its name) it is kind of \u201cintelligent\u201d, I mean, it is Oslo Textual DSL oriented. \ud83d\ude09<\/P>\n<P>I\u2019m using OSLO SDK January CTP (Kind of a OSLO\u2019s Pre-Beta). You can download it from this URL:<\/P>\n<P><B>Microsoft &#8220;Oslo&#8221; SDK &#8211; January 2009 CTP (Refresh)<\/B><\/P>\n<P><A href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=f2f4544c-626c-44a3-8866-b2a9fe078956&amp;displaylang=en\">http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=f2f4544c-626c-44a3-8866-b2a9fe078956&amp;displaylang=en<\/A><\/P>\n<P>Basically, <STRONG>Intellipad<\/STRONG> gives you support for creating <STRONG>custom DSLs<\/STRONG> using the <STRONG>MGrammar<\/STRONG> language. <\/P>\n<P><B>1.- Starting Intellipad with MGrammar support<\/B><\/P>\n<P>Launch Intellipad with sample plug-ins loaded (from the <B>start menu, Oslo SDK,&nbsp; Icon called \u201cIntellipad (Samples Enabled)\u201d<\/B>)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 <\/P>\n<P>In the future, the MGrammar Language support will not require loading with samples. This is just because of this beta.<\/P>\n<P>So now, change Intellipad mode to \u201cM-Grammar\u201d, like the following:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image002_2.jpg\"><IMG title=\"clip_image002\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image002_thumb.jpg\" width=\"684\" height=\"378\"><\/A><\/P>\n<P><B>2.- Input file and our model\u2019s text data<\/B><\/P>\n<P>So, instead of starting writing M-Grammar like crazy (you should know its syntax, first), we\u2019re going to start writing our model\u2019s data, I mean, the simplified and even natural text I would like to provide as the origin.<\/P>\n<P>Because of that, create an empty file (like a .TXT file) called \u201c<B>My DSL Input Data.input<\/B>\u201d, for instance. Put it in any folder you like.<\/P>\n<P>Therefore, we need the pane to start writing in that \u2018input file\u2019. You get that pane\/window when selecting \u201cMGrammar Mode\u201d menu and then select \u201cTree Preview\u201d, like in the following screen:<U><\/U><\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image004_2.jpg\"><IMG title=\"clip_image004\" border=\"0\" alt=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image004_thumb.jpg\" width=\"697\" height=\"229\"><\/A><\/P>\n<P>Then, you\u2019ll get a dialog asking for you input file, like this one:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image006_2.jpg\"><IMG title=\"clip_image006\" border=\"0\" alt=\"clip_image006\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image006_thumb.jpg\" width=\"701\" height=\"399\"><\/A><\/P>\n<P>Then, go and select that empty \u2018My DSL Input Data\u2019 file.<\/P>\n<P>You\u2019ll see <I>Intellipad<\/I> in the following form:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image008_2.jpg\"><IMG title=\"clip_image008\" border=\"0\" alt=\"clip_image008\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image008_thumb.jpg\" width=\"897\" height=\"466\"><\/A><\/P>\n<P>Cool!, so let\u2019s start writing something we\u2019d like to be consumed by our TEXTUAL DSL. For instance, the following text: \n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"576\">\n<P>&#8220;Office 2007&#8221; by &#8220;Microsoft&#8221; is &#8220;nice&#8221;<\/P>\n<P>&#8220;Windows 7&#8221; by &#8220;Microsoft&#8221; is &#8220;great&#8221;<\/P>\n<P>&#8220;Visual Studio 2010&#8221; by &#8220;Microsoft&#8221; is &#8220;great&#8221;<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P>Very simple, so, regarding that text, there are several products, company-names and adjectives, and, in this case, just the terms \u201cby\u201d and \u201cis\u201d are actually my language terms. You\u2019ll see it like this:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image010_2.jpg\"><IMG title=\"clip_image010\" border=\"0\" alt=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image010_thumb.jpg\" width=\"896\" height=\"357\"><\/A><\/P>\n<P>So far, very simple. Now, I\u2019m going to write my DSL program based on M-Grammar. You can copy &amp; paste it on the MGrammar Mode pane: \n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"576\">\n<P><STRONG>module<\/STRONG> DemosOslo<\/P>\n<P>{<\/P>\n<P><STRONG>language<\/STRONG> MyCatalogLanguage<\/P>\n<P>{<\/P>\n<P><STRONG>syntax<\/STRONG> Main = a:Product+ =&gt; SoftwareCatalog { valuesof(a) };<\/P>\n<P><STRONG>syntax<\/STRONG> Product = productName:Name &#8220;by&#8221; company:Name &#8220;is&#8221; rating:Name<\/P>\n<P>=&gt; {ProductName = productName, CompanyName = company, Rating = rating};<\/P>\n<P><STRONG>token<\/STRONG> Name = &#8216;&#8221;&#8216; n:(any &#8211; &#8216;&#8221;&#8216;)+ &#8216;&#8221;&#8216; =&gt; n;<\/P>\n<P><STRONG>interleave<\/STRONG> IgnoreMe = &#8221; &#8221; | &#8220;\\n&#8221; | &#8220;\\r&#8221;;<\/P>\n<P>} <\/P>\n<P>}<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P>Then, you can see how MGrammar transforms the input text to the final form:<\/P>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image012_2.jpg\"><IMG title=\"clip_image012\" border=\"0\" alt=\"clip_image012\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/clip_image012_thumb.jpg\" width=\"964\" height=\"448\"><\/A><\/P>\n<P>This is the generated data, in case you cannot read it on the copied screen:<\/P>\n<P>\n<TABLE border=\"1\" cellSpacing=\"0\" cellPadding=\"0\" width=\"485\">\n<TBODY>\n<TR>\n<TD vAlign=\"top\" width=\"483\">\n<P><STRONG>SoftwareCatalog<\/STRONG>{ <BR>&nbsp; { <BR>&nbsp;&nbsp;&nbsp; <STRONG>ProductName<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Office 2007&#8221; <BR>&nbsp;&nbsp;&nbsp; }, <BR>&nbsp;&nbsp;&nbsp; <STRONG>CompanyName<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Microsoft&#8221; <BR>&nbsp;&nbsp;&nbsp; }, <BR>&nbsp;&nbsp;&nbsp; <STRONG>Rating<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;nice&#8221; <BR>&nbsp;&nbsp;&nbsp; } <BR>&nbsp; }, <BR>&nbsp; { <BR>&nbsp;&nbsp;&nbsp; <STRONG>ProductName<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Windows 7&#8221; <BR>&nbsp;&nbsp;&nbsp; }, <BR>&nbsp;&nbsp;&nbsp; <STRONG>CompanyName<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Microsoft&#8221; <BR>&nbsp;&nbsp;&nbsp; }, <BR>&nbsp;&nbsp;&nbsp; <STRONG>Rating<\/STRONG>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;great&#8221; <BR>&nbsp;&nbsp;&nbsp; } <BR>&nbsp; } <BR>}<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/P>\n<P>Likewise, \u201cM\u201d Language works internally in a similar way, but it uses the M-Grammar program called <B>M.mg<\/B> (you can find it in the SDK, check it), instead the simple one we\u2019re using here (I called it <B>SoftwareCatalogMGrammar.mg<\/B>). <\/P>\n<P>Another great example is the new <B>\u201cMUrl\u201d textual DSL<\/B>, 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! \ud83d\ude42<\/P>\n<P>There\u2019s gonna be another textual DSL to actually build RESTFul services. It is called <B>\u201cMService\u201d<\/B>, 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. <\/P>\n<P>Just want to highlight that Oslo, \u201cM\u201d Language and Quadrant are tools to create any kind of DSL Tools. Oslo is a \u201cModeling platform for ALL\u201d. We\u2019re not just talking about data or web-services, we\u2019ll be talking about modeling ANYTHING!. \ud83d\ude42<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote a post about Oslo and \u201cM\u201d 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 \u201cM\u201d Language. You can see that post here: Starting using OSLO, \u201cM\u201d 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\u2019m [&hellip;]<\/p>\n","protected":false},"author":362,"featured_media":12806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[74],"class_list":["post-1093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cesardelatorre","tag-oslo"],"acf":[],"blog_post_summary":"<p>I wrote a post about Oslo and \u201cM\u201d 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 \u201cM\u201d Language. You can see that post here: Starting using OSLO, \u201cM\u201d 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\u2019m [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/comments?post=1093"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media\/12806"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media?parent=1093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/categories?post=1093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/tags?post=1093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}