MetaSharp on CodePlex

I finally managed to get the source code for the little side project I’ve been working on into CodePlex.

Give it a shot and let me know how it works out for you! There are definitely known limitations at this point, there is almost certainly language syntax that doesn’t work right for starters. Most of the basic stuff is there but l haven’t really tested abstract members much or events and things like that. I also haven’t implemented “macros” yet, which isn’t very hard to do in the parser but is much harder to do in the compiler. I’ll probably hook that up for v0.2.

I’m also in dire need of cleaning up some regular project maintenance stuff such as versions for the assemblies, automated build, many more unit tests, code analysis, etc.

If you’re still scratching your head about what I’m even trying to do here check out these two wiki pages

Basic Workflow

Song Sample

If you’re still scratching your head please let me know, because I’m either not explaining it right or this is more confusing than I thought.

By the way, this project is not an official Microsoft project in any way. This is something I have done in the evenings and weekends for my own enjoyment. Please don’t ask anyone else for support and don’t blame them if you think this project is lame 🙂

Uninstalling Visual Studio 2008 on Windows 7 Beta

It turns out I accidentally installed the Trial version of VS 2008 off of MSDN. So that makes me a bonehead but as a dose of extra punishment it turns out there is a bug in the VS 2008 uninstaller on windows 7. So that is a real bummer. I’ve been struggling to uninstall it for a couple days now and I finally figured it out.

First I’ll start by saying I uninstalled everything related to VS. My Live writer plug-ins, my XNA stuff and Oslo stuff and I was still failing to uninstall. The trick is to go to the uninstall screen in the control panel and select “view installed updates”. There is an update for VS 2008 with almost the same title as the application itself, uninstall that then go back to the main uninstall screen and try again. This time it should work!

What an ordeal!

Groovy Meta Programming at the TCLangUG

Head over to the Twin Cities Languages User Groupmeeting tomorrow night for a meta programming event. Here is a description of the event:


Ruby’s monkeypatching brought the idea of metaprogramming to the masses, or at least to those that weren’t exposed to it in Lisp or C. At its best, metaprogramming can greatly improve productivity, as is the case with Grails, but at its worst it can destroy expectations and induce versioning confusion. This talk introduces the myriad metaprogramming techniques Groovy and dynamic typing allows, shows how some of them are used in real life, and compares them to what’s available in other languages. Oh yeah, all code will be written live.

MetaSharp code generation success!

I finally have an end to end example of code generation with MGrammar I’m happy with. It’s pretty simple too I think. What I have working right now is the scenario where you author a grammar for use as an external DSL and would like to use it in existing applications. You are able to add templates to any .NET project and generate code in the native language. Which means the same template will work for C#, VB, F#, Boo or whatever projects since it compiles down to the CodeDom.

In addition to your MGrammar language definition you can now create a template in MetaSharp, there is a MSBuild task that compiles that template file into a Template class in the native language of your project. That template class knows how to generate code that binds to a model (MGraph objects or CLR objects). Here is a visual example.

Here is an example of a template in MetaSharp.

namespace Samples.Song.Templates:
    import System;
    import System.Collections.Generic;
    import System.Threading;
    import System.Text;
    public class {Song.Name} as Song:
        public constructor:
            @for(b in {Song.Bars as enumerable}):
                super.Bars.Add(new Bar(

Its a very simple language, the interesting parts are the ‘@’ characters and the {…} groups. The @ symbol puts that line into template mode. Meaning that will be a literal line in the template. The curly bracket groups are Binding statements, similar to what you see in Xaml only much less expressive at this point. So far you just specify a path and an optional type to cast it to. “enumerable” is just a helper to cast it to IEnumerable, or in the case if MGraph to get the sequence for the node.

So if you take the song DSL file from the Song Sample included in the Oslo SDK.

Song Fun
- - - D
C C# F G
E E - D
A E - E
G F - E

And apply that to the template above you end up with this code (in C# in this case):

// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.3521
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>

namespace Samples.Song.Templates
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Text;

    public class Fun : Song

        public Fun()
            base.Bars.Add(new Bar("-", "-", "-", "D"));
            base.Bars.Add(new Bar("C", "C#", "F", "G"));
            base.Bars.Add(new Bar("E", "E", "-", "D"));
            base.Bars.Add(new Bar("A", "E", "-", "E"));
            base.Bars.Add(new Bar("G", "F", "-", "E"));
            base.Bars.Add(new Bar("D", "C", "D", "E"));
            base.Bars.Add(new Bar("A", "E", "D", "D"));
            base.Bars.Add(new Bar("D", "E", "A", "C"));

So this is really cool! This will allow you to create MGrammar DSLs without having to write complicated code to consume the object graph. And it all happens at build time! I’m planning on doing a little more cleanup then probably creating a CodePlex project for this. This is exactly what I wanted for NBusiness… hopefully I can get back to that soon, haha!

Web OS? Here comes Project Gazelle

Very interesting…

The Multi-Principal OS Construction of the Gazelle Web Browser

Helen J. Wang, Chris Grier, Alexander Moshchuk, Sam King, Piali Choudhury, Herman Venter
19 Feb. 2009

Web browsers originated as applications that people used to view static web sites sequentially. As web sites evolved into dynamic web applications composing content from various web sites, browsers have become multi-principal operating environments with resources shared among mutually distr…

Other interesting links: