Задайте вопросЗадайте вопрос
 

ОтвеченоMGrammar - Unordered and optional multi-projections?

  • 26 июня 2009 г. 15:40justncase80 Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     С кодом
    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? In my real language I have a bunch of other tokens before and after the two optional and unordered items and the | list can be quite extensive and long if I have to enumerate every possible combination. Furthermore if you have a third item ("OneTwoThree" for example) then your | list can get exponentially grow. 

    Is there a trick to defining unordered and optional items in the middle of a complex syntax?

Ответы

Все ответы