MGrammar Quick Challenge 2 - Unordered and optional multi-projections

by justin 25. June 2009 22:43

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?

Tags: , , ,

MGrammar | MetaSharp | DSL | Oslo

Comments

6/24/2009 6:27:34 PM #

Hi. Had the same issue last year. Gio promised to fix it Smile

social.msdn.microsoft.com/.../3d5cb0ce-ac57-47e0-a17c-55e977f2b56b

Lars C |

6/24/2009 8:50:40 PM #

Yeah that sounds like the exact same issue. But they didn't solve it yet?

justin |

6/25/2009 6:48:41 PM #

Maybe we should add a issue to the bug tracker and start voting.

Lars C |

6/25/2009 6:51:31 PM #

The problem is, that a language normally doesn't say, one and two must both occur, but in any order. Usually you rather have: statement*; and statement = one | two; That's why I called it mixing lanugage syntax and semantics.

In a GPL, you would process those things in the compiler and throw errors. But especially for DSLs, you often wan't some semantics builtin to the language, cause it is easier and the languages are small.

Lars C |

6/27/2009 4:29:56 AM #

Agreed, specifically for me I'm trying to implement a "Property". So I want to be able to do:

int x: get; set; end
int x: set; get; end
int x: get; end
int x: set; end

With the current system I end up having to write four syntax's to support these variations, and they're all long. But actually, if I treated them as a collection rather than maybe I could do it in one... except that changes my projection and I'm not entirely sure I like that. Hmmmm.

justin |

6/27/2009 4:42:12 AM #

I added an issue to connect for this:
connect.microsoft.com/.../ViewFeedback.aspx

justin |

Comments are closed

About Me

sweetest hat ever

I'm a software developer from Minnesota and this blog largely focuses on various technical concepts I am thinking about at the moment. I currently work for Microsoft in the St. Paul office of the Expression product group.

RecentPosts