Rants and Raves

Thanks for visiting my blog!

Using Classifications in MGrammar's Intellipad
Using Classifications in MGrammar's Intellipad
December 15, 2008

Url: http://social.msdn.microsoft.com/Forums/en-US/o…
Silverlight Logo
UPDATE: Added a couple of screenshots to clarify what the coloring does.

I am spending quite a bit of time this week writing my own MGrammar using the Oslo SDK. When writing a MGrammar, you can use something like attributes to help Intellipad know how to color your text to help make it more readable. For example,

@{CaseSensitive[false]}
language PricingLanguage

These attributes are used by different parts of the Oslo stack to hint the system with additional information (like Attritubes in .NET). The one that I was particularly interested in was the Classification attribute. This attribute allows you to tell IntelliPad how to format the part of the language. For example:

@{Classification["Comment"]}
token Comment = "//" ^("\r" | "\n")+;

The only two types of classifications that I could find or guess were seen in the PDC videos:  “Comment” and “Keyword”. The MGrammar and IntelliPad docs didn’t mention anything about classifications so I asked up on the Oslo Forums. While it isn’t documented anywhere, I was told about a configuration file call ClassificationFormats.xcml that resides in the Settings folder of Intellipad (usually c:\Program Files\Microsoft Oslo SDK 1.0\Bin\IntelliPad\Settings). This lead me to two important pieces of information: a fuller list of classification types (i.e. Strings, Delimiter, Type, etc.) but also showed me how to customize the coloring as the default Intellipad coloring is starkly monochromatic. This file is a simple XAML file that contains individual classifications and how they are formatted:

<ls:ClassificationFormat Name='Keyword' 
                         FontSize='13' 
                         FontFamily='Consolas' 
                         Foreground='#FF333333' />

Each of these can be changed to specify the color (Foreground) and even the font and size (if you want unreadable code). You can edit this file and just use the Shift-Alt-F5 hotkey in Intellipad to reload the settings to tweak the colors as you like.

For example, I’ve edited the Keyword and Operator colors to show blue and red respectively. So that in my MGrammar if I use the Classification attribute to specify parts of my DSL are Keyword tokens or Operator tokens as shown here:

Then my language is colored based on my ClassificationFormats.xcml file:

Nice…