Microsoft Developer Network > 포럼 홈 > Microsoft SQL Server Modeling > Changing default values in MGrammar
질문하기질문하기
 

답변됨Changing default values in MGrammar

  • 2009년 6월 25일 목요일 오후 8: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
      }
    ]

    • 편집됨justncase80 2009년 6월 25일 목요일 오후 8:38formatting
    •  

답변

  • 2009년 6월 25일 목요일 오후 10: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)
    • 답변으로 표시됨justncase80 2009년 6월 25일 목요일 오후 10:04
    •  

모든 응답

  • 2009년 6월 25일 목요일 오후 10: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)
    • 답변으로 표시됨justncase80 2009년 6월 25일 목요일 오후 10:04
    •