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?

Author: justinmchase

I'm a Software Developer from Minnesota.

%d bloggers like this: