Microsoft 开发人员网络 > 论坛主页 > Microsoft SQL Server Modeling > Changing default values in MGrammar
提出问题提出问题
 

已答复Changing default values in MGrammar

  • 2009年6月25日 20:38justncase80 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I have a syntax something like this:

    syntax Foo 
         =   b:Bar z:Baz?
         => Foo { Bar => b, Baz => z }

    But if Baz doesn't match then the graph projects to be:

    Foo { Bar => Bar { ... }, Baz => null }

    What I'd really like is for Baz to not project to null but something else instead (such as Baz { }). The only way I could get it to work so far is to completely duplicate the syntax one with Baz required and one with Baz totally missing and change the greater projection.



    Here is a more complete example

    Given the input text "bar", modify this language:

    module test
    {
        language test
        {
            syntax Main = Foo;
            
            syntax Foo 
                =  b:Bar z:Baz?
                => Foo { Bar => b, Baz => z };
            
            token Bar = "bar" => true;
            token Baz = "baz" => true;
        }
    }

    To produce the graph:

    Main[
      Foo{
        Bar => true,
        Baz => false
      }
    ]

答案

  • 2009年6月25日 22:04justncase80 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Rocky Lhotka helped me solve this perfectly by pointing out the "empty" keyword.

    b : (b : Bar => b | empty => false)
    z : (b : Baz => b | empty => false)

全部回复

  • 2009年6月25日 22:04justncase80 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Rocky Lhotka helped me solve this perfectly by pointing out the "empty" keyword.

    b : (b : Bar => b | empty => false)
    z : (b : Baz => b | empty => false)