MGrammar: using tabs to denote blocksSuppose I wanted something like this<br class=Apple-interchange-newline> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px"></font><font style="color:blue">if</font><font style="font-size:11px"> e1:   </font></td></tr> <tr> <td style="background-color:#f7f7f7">  </font><font style="color:blue">while</font><font style="font-size:11px"> e2:   </font></td></tr> <tr> <td>    call()   </td></tr> <tr> <td style="background-color:#f7f7f7"></font><font style="color:blue">else</font><font style="font-size:11px">   </font></td></tr> <tr> <td>  </font><font style="color:blue">return</font><font style="font-size:11px"> e3   </font></td></tr> <tr> <td style="background-color:#f7f7f7">   </td></tr> <tr> <td>call() </td></tr></tbody></table></div><br>Meaning, if you have the same number of whitespace characters as the line above you then you're in the same block. The &quot;:&quot; denotes the end of a block a decrease in indentation denotes an end of a block.<br><br>How the heck do I do this?? © 2009 Microsoft Corporation. All rights reserved.Wed, 24 Jun 2009 10:45:50 Z4a58694d-6eb2-44fd-9d37-824a3ab92bc1http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#4a58694d-6eb2-44fd-9d37-824a3ab92bc1http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#4a58694d-6eb2-44fd-9d37-824a3ab92bc1justncase80http://social.msdn.microsoft.com/Profile/en-US/?user=justncase80MGrammar: using tabs to denote blocksSuppose I wanted something like this<br class=Apple-interchange-newline> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px"></font><font style="color:blue">if</font><font style="font-size:11px"> e1:   </font></td></tr> <tr> <td style="background-color:#f7f7f7">  </font><font style="color:blue">while</font><font style="font-size:11px"> e2:   </font></td></tr> <tr> <td>    call()   </td></tr> <tr> <td style="background-color:#f7f7f7"></font><font style="color:blue">else</font><font style="font-size:11px">   </font></td></tr> <tr> <td>  </font><font style="color:blue">return</font><font style="font-size:11px"> e3   </font></td></tr> <tr> <td style="background-color:#f7f7f7">   </td></tr> <tr> <td>call() </td></tr></tbody></table></div><br>Meaning, if you have the same number of whitespace characters as the line above you then you're in the same block. The &quot;:&quot; denotes the end of a block a decrease in indentation denotes an end of a block.<br><br>How the heck do I do this?? Tue, 02 Dec 2008 19:47:24 Z2008-12-02T19:47:24Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#6f46adcb-3837-42dd-9a35-8b3b93a73e83http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#6f46adcb-3837-42dd-9a35-8b3b93a73e83justncase80http://social.msdn.microsoft.com/Profile/en-US/?user=justncase80MGrammar: using tabs to denote blocksSo 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?Tue, 02 Dec 2008 23:55:14 Z2008-12-02T23:55:14Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#ec97d9f7-1bfe-43db-8389-cdcb68371f49http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#ec97d9f7-1bfe-43db-8389-cdcb68371f49justncase80http://social.msdn.microsoft.com/Profile/en-US/?user=justncase80MGrammar: using tabs to denote blocks After messing with this for a while I was able to sort of come up with something:<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">module count  </font></td></tr> <tr> <td style="background-color:#f7f7f7">{  </td></tr> <tr> <td>    </font><font style="color:blue">import</font><font style="font-size:11px"> Language;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">import</font><font style="font-size:11px"> Microsoft.Languages;  </font></td></tr> <tr> <td>      </td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">export</font><font style="font-size:11px"> test;  </font></td></tr> <tr> <td>    language test  </td></tr> <tr> <td style="background-color:#f7f7f7">    {  </td></tr> <tr> <td>        syntax Main = l:Line* =&gt; Lines[valuesof(l)];  </td></tr> <tr> <td style="background-color:#f7f7f7">                     </td></tr> <tr> <td>        syntax Line  </td></tr> <tr> <td style="background-color:#f7f7f7">            = </font><font style="color:blue">&quot;-&quot;</font><font style="font-size:11px"> NL  </font></td></tr> <tr> <td>            | l:L(</font><font style="color:blue">&quot; &quot;</font><font style="font-size:11px">, </font><font style="color:blue">&quot;-&quot;</font><font style="font-size:11px">) =&gt; Indent[l];  </font></td></tr> <tr> <td style="background-color:#f7f7f7">               </td></tr> <tr> <td>        syntax L(previous, valid)  </td></tr> <tr> <td style="background-color:#f7f7f7">            = previous v:valid NL =&gt; v  </td></tr> <tr> <td>            | previous l:L(</font><font style="color:blue">&quot; &quot;</font><font style="font-size:11px">, valid) =&gt; Indent[l];  </font></td></tr> <tr> <td style="background-color:#f7f7f7">              </td></tr> <tr> <td>        token NL = Base.NewLine;  </td></tr> <tr> <td style="background-color:#f7f7f7">    }  </td></tr> <tr> <td>} </td></tr></tbody></table></div><br>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:<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">token Indent(i)  </font></td></tr> <tr> <td style="background-color:#f7f7f7">  = &quot; &quot; &quot; &quot;#i..; // at least 1 more space</td></tr></tbody></table></div><br>But that doesn't work, you can't have a parameter be apart of the number constraints. Those appear to be hard coded.Wed, 03 Dec 2008 14:52:12 Z2008-12-03T14:52:12Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#bcfdc6e4-b36d-43d6-bad9-4e6a61f613cahttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#bcfdc6e4-b36d-43d6-bad9-4e6a61f613cavbbalahttp://social.msdn.microsoft.com/Profile/en-US/?user=vbbalaMGrammar: using tabs to denote blocks 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.<br>Thu, 04 Dec 2008 07:35:37 Z2008-12-04T07:35:37Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#d91de614-b000-4afe-bc1b-f63e18bfc314http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#d91de614-b000-4afe-bc1b-f63e18bfc314justncase80http://social.msdn.microsoft.com/Profile/en-US/?user=justncase80MGrammar: using tabs to denote blockswhat is a token event listener?Sun, 07 Dec 2008 04:32:16 Z2008-12-07T04:32:16Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#ff3ccce1-ffe4-42f8-a3ea-58951b17c264http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#ff3ccce1-ffe4-42f8-a3ea-58951b17c264Martin Dvorak -1-http://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20Dvorak%20-1-MGrammar: using tabs to denote blocksHi vbbala,<br/>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.<br/>Thanks, Martin<hr class="sig">-md-Tue, 23 Jun 2009 10:11:05 Z2009-06-23T10:11:05Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#f3f1cc9c-c750-4464-80d9-93eeba2dd8d5http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#f3f1cc9c-c750-4464-80d9-93eeba2dd8d5justncase80http://social.msdn.microsoft.com/Profile/en-US/?user=justncase80MGrammar: using tabs to denote blocksI don't think it's improved much on this front. There is a new &quot;nest&quot; 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. Tue, 23 Jun 2009 14:55:45 Z2009-06-23T14:55:45Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#cf82bf29-81eb-4e87-9c81-aba51b2bc185http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/4a58694d-6eb2-44fd-9d37-824a3ab92bc1#cf82bf29-81eb-4e87-9c81-aba51b2bc185Martin Dvorak -1-http://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20Dvorak%20-1-MGrammar: using tabs to denote blocksThanks 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.<hr class="sig">-md-Wed, 24 Jun 2009 10:45:48 Z2009-06-24T10:45:48Z