Microsoft Developer Network > 포럼 홈 > Microsoft SQL Server Modeling > MGrammar: using tabs to denote blocks
질문하기질문하기
 

답변됨MGrammar: using tabs to denote blocks

  • 2008년 12월 2일 화요일 오후 7:47justncase80 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    Suppose I wanted something like this
    if e1:   
      while e2:   
        call()   
    else   
      return e3   
       
    call() 

    Meaning, if you have the same number of whitespace characters as the line above you then you're in the same block. The ":" denotes the end of a block a decrease in indentation denotes an end of a block.

    How the heck do I do this??

답변

  • 2008년 12월 4일 목요일 오전 7:35vbbalaMSFT사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
     In the current bits, there is no easy way to do this -- perhaps registering a token event listener for the indenting whitespace may get you closer to doing this manually.  For the next drop, we are already looking into generating 'Indent' and 'Unindent' tokens from the lexer.  That will make it easier to support scoping by indentation.
    • 답변으로 제안됨Mike Weinhardt 2008년 12월 5일 금요일 오후 7:37
    • 답변으로 표시됨justncase80 2008년 12월 7일 일요일 오전 4:32
    •  

모든 응답

  • 2008년 12월 2일 화요일 오후 11:55justncase80 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    So far I'm thinking I can just keep track of the whitespace since the last newline and in the code behind just do the logic check. Does anyone second that idea?
  • 2008년 12월 3일 수요일 오후 2:52justncase80 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    After messing with this for a while I was able to sort of come up with something:

    module count  
    {  
        import Language;  
        import Microsoft.Languages;  
          
        export test;  
        language test  
        {  
            syntax Main = l:Line* => Lines[valuesof(l)];  
                         
            syntax Line  
                = "-" NL  
                | l:L(" ""-") => Indent[l];  
                   
            syntax L(previous, valid)  
                = previous v:valid NL => v  
                | previous l:L(" ", valid) => Indent[l];  
                  
            token NL = Base.NewLine;  
        }  

    This doesn't quite enforce indentations (couldn't figure out how to do that) but it does tell you how indented you are in each line. Somehow what I need to do is to use this to determine the start of code blocks... I think I'm on the right trail. I tried to do something like this:

    token Indent(i)  
      = " " " "#i..; // at least 1 more space

    But that doesn't work, you can't have a parameter be apart of the number constraints. Those appear to be hard coded.
  • 2008년 12월 4일 목요일 오전 7:35vbbalaMSFT사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
     In the current bits, there is no easy way to do this -- perhaps registering a token event listener for the indenting whitespace may get you closer to doing this manually.  For the next drop, we are already looking into generating 'Indent' and 'Unindent' tokens from the lexer.  That will make it easier to support scoping by indentation.
    • 답변으로 제안됨Mike Weinhardt 2008년 12월 5일 금요일 오후 7:37
    • 답변으로 표시됨justncase80 2008년 12월 7일 일요일 오전 4:32
    •  
  • 2008년 12월 7일 일요일 오전 4:32justncase80 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    what is a token event listener?
  • 2009년 6월 23일 화요일 오전 10:11Martin Dvorak -1- 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi vbbala,
    Are there some news on this front, i.e. are there some new features in current bits which would make it easier to support scoping by indentation? Or are there any planned for next CTP release? I've been looking for 'Indent' and 'Unindent' you mention in current M language specification (May 09 CTP) but found nothing.
    Thanks, Martin
    -md-
  • 2009년 6월 23일 화요일 오후 2:55justncase80 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I don't think it's improved much on this front. There is a new "nest" keyword which I haven't looked into which might make it more feasible. But I think the answer is that you have to not interleave whitespace but instead carefully create tokens for keeping track of indentation. 
  • 2009년 6월 24일 수요일 오전 10:45Martin Dvorak -1- 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Thanks for reply. Since my language is really simple with maximum three levels of indentation, I solved this by simply interleaving all whitespace except new line characters and handling new line characters in syntax/tokens. Nevertheless I still hope M will somehow support scoping by indentation in the future because it is very useful for simple easily readable custom languages.
    -md-