MGrammar Quick Challenge 2 – Unordered and optional multi-projections

Given this grammar:

module test
{
    language test
    {
        syntax Main = OneTwo*;
        
        syntax OneTwo
            =  o:One t:Two "\r\n"
            => Result { One => true, Two => true }
            |  Two One "\r\n"
            => Result { One => true, Two => true }
            |  One "\r\n"
            => Result { One => true, Two => false }
            |  Two "\r\n"
            => Result { One => false, Two => true };
                
        token One = "one";
        token Two = "two";
        
        interleave Ignore = " ";
    }
}

How could I refactor the syntax “OneTwo” to have only a single projection?

Featured on techcareertips.com

Tavis Hudson is a Tech Headhunter who first recruited me in 2005 to work for Magenic. Over the years we have kept in contact and run into each other at a few events here and there. Recently, Tavis contacted me about doing an over the phone interview (as in journalism not recruiting) for his blog.

In the first of a series of blog posts he is authoring called “Prodigy Developers” he did a write up based on the conversation we had. I’ll try not to let that title go to my head but thanks for the vote of confidence Tavis.

One of the things he touches on in his post is something that I’d like to elaborate on a little more. This is something I consciously say to myself from time to time:

One thing that I have learned in college and in my career so far is that there are lots of people who are smarter than me. I mean downright geniuses. I am not a genius. I am constantly awed by these people and their mathematical abilities or their ability to grasp incredibly complex topics or the speed with which they are able to get to conclusions. This is not my strong point even though I am not an idiot by any means. Yet somehow, in a field generally regarded as primarily mathematical, I seem to thrive. It’s not to say that intelligence is overrated but I think that passion and dedication are, perhaps, underrated.

Sometimes I like to say that I’m an artist who can’t paint. I know that sounds corny but what I’m trying to say is just that I have to rely more on my creative side than my intellectual side when programming. I’m more of a right brainer than a left brainer, if that makes sense. Maybe more people than I realize would be able to associate with this notion but I feel like this is what has helped me more than anything, not that it’s more important but maybe that it’s rare.

Sorry, enough self congratulation and introspection. Head on over and read Prodigy Developers – Justin Chase, by Tavis Hudson.

Reflection vs. code generation – by Martin Fowler

Here is an interesting article by Martin Fowler on the subject of reflection vs. code generation.

http://www.javaworld.com/javaworld/jw-11-2001/jw-1102-codegen.html?

Here is a nice quote to sum it up (with which I couldn’t agree more).

Active code generation gives us all the benefits of reflection, but none of its limitations. Reflection will still be used, but only during the code generation process, and not during runtime.

Here is another endorsement he gives after many examples and justifications.

The benefits of reflection are obvious. When coupled with code generation it becomes an invaluable and, more importantly, a safe tool. There is often no other way to escape many seemingly redundant tasks. As for code generation: the more I work with it, the more I like it. With every refactoring and increase in functionality, the code becomes clearer and more understandable. However, runtime reflection has the opposite effect. The more I increase its functionality, the more it increases in complexity. So, in the future, if you feel you need to conquer a complicated problem using reflection, just remember one rule: don’t do it at runtime.

I couldn’t agree more, except I would go one step further and consider “code generation” just another form of transformation at compile time. At least that is what I’m hoping to accomplish with MetaSharp.

Actipro has a WPF MGrammar syntax editor

http://www.actiprosoftware.com/Products/DotNet/WPF/SyntaxEditor/Default.aspx

I haven’t tried to use this yet but it seems pretty interesting.

SyntaxEditor is a powerful text editing control that is packed with features for efficient code editing, including syntax highlighting, line numbers, block selection, IntelliPrompt UI, split views, zooming, bi-di support, and much more. It has many of the same code editing features found in the Visual Studio code editor.

SyntaxEditor is built on top of our next-generation extensible text/parsing framework. While over 20 sample languages are available to get you started (such as C#, VB, XML, and more), custom language definitions can be developed and distributed with your applications as well. SyntaxEditor is designed for use in IDE (integrated development environment) applications, however there are many other applications out there than can take advantage of such a control.

A free add-on is included that integrates domain-specific language (DSL) parsers created using Microsoft Olso’s MGrammar with SyntaxEditor, allowing it to syntax highlight code based on the DSL parser.