<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 21 Oct 2018, at 08:54, Allan Odgaard <<a href="mailto:mailinglist@textmate.org" class="">mailinglist@textmate.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" class="">
<div class="">
<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">On 17 Oct 2018, at 17:36, Jacob Carlborg wrote:</p>
</div>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px" class=""><p dir="auto" class="">This is exactly according to the specified grammar [3] and it seems to be working as expected. Not sure if the optional group workaround causes some performance implications.<br class="">
<br class="">
This technique seems like it could be a viable alternative to supporting variables in the TextMate grammar as has been discussed before.</p>
</blockquote></div>
<div style="white-space:normal" class=""><p dir="auto" class="">Just to be clear, you are talking about variables from the parsed language and highlighting them later in the scope, right?</p><p dir="auto" class="">So something like: <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">let foo = 42 in … something_with foo …</code> and here the latter instance of <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">foo</code> would be marked as a variable?</p></div></div></div></div></blockquote>No, I’m talking about having variables in the grammar with reusable regular expression snippets. Something like:</div><div><br class=""></div><div><div>{</div><div> patterns = (</div><div> {</div><div> name = 'meta.definition.class.d';</div><div> match = 'class $identifier’; // the “identifier” variable referenced/interpolated</div><div> }</div><div> );</div><div> repository = {</div><div> variables = {</div><div> identifier = '(\w+)';</div><div> };</div><div> };</div><div>}</div><div class=""><br class=""></div><div class="">In the above example “identifier” would be a variable that can be interpolated in other rules.</div><div class=""><br class=""></div><div class="">The above example would be one approach. Another approach to support variables is what I showed in my original post but using already existing features of regular expression.</div></div><div class=""><br class=""></div><div class=""><div>{</div><div> patterns = (</div><div> {</div><div> name = 'meta.definition.class.d';</div><div> match = ‘\g<class_declaration>’; // this is standard regular expression syntax that works today in TextMate we just need somewhere to define “class_declaration"</div><div> },</div><div> {</div><div> name = ‘meta.definition.struct.d’;</div><div> match = ’struct\s+\g<identifier>’; // reusing the “identifier” sub expression in another pattern</div><div> }</div><div> );</div><div> repository = {</div><div> defines = '(?x) // here sub expressions can be defined which can later be used in “patterns"</div><div> (?<class_declaration>class\s+\g<identifier>)</div><div> (?<identifier>\w+)</div><div> ‘;</div><div> };</div><div>}</div></div><div class=""><br class=""></div><div class="">This is all about how one can write/implement a TextMate grammar. This approach would allow to write a TextMate grammar that closely follows a “real” grammar for a programming language, like a BNF grammar. I hope this makes it a bit more clear.</div><div class=""><br class=""></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">--</div><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">/Jacob Carlborg</div>
</div>
<br class=""></body></html>