(I just asked this to irc so sorry for the duplicate)
I'm looking for guidance on how to change the javascript grammar so it'll syntax highlight both, e.g., "if (...)" and "if(...)". Currently, only the former works, and I believe this is for most control statements, e.g., if, for, while, etc.
In java, for example, both work, and I tried to compare the grammars to make my own edits, but found them too complicated and different, and anything I tried didn't work.
Any guidance would be appreciated.
Thanks- Robert
Hi Robert,
The issue, it seems to me is that the grammar for functions picks up `if()` but the grammar for control structures picks up `if ()`. I did take a whack at your request directly but didn't achieve the goal. An easy solution might be to highlight the function version in your theme to be the same as the control structure.
The way I gathered this information was to use "Show scope" ( in a JS file with the cursor on the `if`s, this was showing "keyword.control.js" for `if ()`, but 'punctuation.definition.function-call.begin.js' for `if()`.
Maybe, short of an answer, this helps you figure out the issue? Or inspire someone else on the group to help get you an actual answer.
I'd love to see a "Newbs guide to TM Language Grammars" (or maybe could point one out). There's a lot of information out there, but it'd be nice to gather in to one place, and format it in a "zero to hero" format. I feel like StackOverflow agrees: https://stackoverflow.com/search?q=textmate+grammar (and it'd be nice to reduce the number of TextMate tags on VSCode issues, lol).
Hope that helps, Graham
On 31 Jul 2019, at 20:14, Robert J. Carr wrote:
(I just asked this to irc so sorry for the duplicate)
I'm looking for guidance on how to change the javascript grammar so it'll syntax highlight both, e.g., "if (...)" and "if(...)". Currently, only the former works, and I believe this is for most control statements, e.g., if, for, while, etc.
In java, for example, both work, and I tried to compare the grammars to make my own edits, but found them too complicated and different, and anything I tried didn't work.
Any guidance would be appreciated.
Thanks- Robert
textmate mailing list textmate@lists.macromates.com https://lists.macromates.com/listinfo/textmate
On 1 Aug 2019, at 19:58, Graham Heath wrote:
The way I gathered this information was to use "Show scope" ( in a JS file with the cursor on the `if`s, this was showing "keyword.control.js" for `if ()`, but 'punctuation.definition.function-call.begin.js' for `if()`.
Maybe, short of an answer, this helps you figure out the issue? Or inspire someone else on the group to help get you an actual answer.
This seems to be a precedence problem.
Line 287 of the grammar has this (includes the rule to match function calls):
{ include = '#function-call'; },
Then line 305-307 has this rule (to match `if` and other keywords):
{ name = 'keyword.control.js'; match = '(?<!.|$)\b(async|await|break|case|catch|continue|default|do|else|export|finally|for|if|return|switch|throw|try|while|with)\b(?!$)'; },
The problem is that the rule to match function calls comes first in the grammar, so when the construct is matched by that line, it never reaches the keyword rule.
The fix is to move the `keyword.control.js` rule up before the function call rule.
But the grammar is pretty complex, I didn’t check if there would be any side effects from this.
Hi Allan-
Sorry for the late reply, but changing the order did seem to fix the problem, but like you said I don't know what the side effects will be. I'll keep the original grammar as a backup in case something goes wrong, but thanks for taking the time to look into this.
Robert
On Thu, Aug 1, 2019 at 12:03 PM Allan Odgaard mailinglist@textmate.org wrote:
On 1 Aug 2019, at 19:58, Graham Heath wrote:
The way I gathered this information was to use "Show scope" ( in a JS file with the cursor on the `if`s, this was showing "keyword.control.js" for `if ()`, but 'punctuation.definition.function-call.begin.js' for `if()`.
Maybe, short of an answer, this helps you figure out the issue? Or inspire someone else on the group to help get you an actual answer.
This seems to be a precedence problem.
Line 287 of the grammar has this (includes the rule to match function calls):
{ include = '#function-call'; },
Then line 305-307 has this rule (to match if and other keywords):
{ name = 'keyword.control.js'; match = '(?<!.|$)\b(async|await|break|case|catch|continue|default|do|else|export|finally|for|if|return|switch|throw|try|while|with)\b(?!$)'; },
The problem is that the rule to match function calls comes first in the grammar, so when the construct is matched by that line, it never reaches the keyword rule.
The fix is to move the keyword.control.js rule up before the function call rule.
But the grammar is pretty complex, I didn’t check if there would be any side effects from this.
textmate mailing list textmate@lists.macromates.com https://lists.macromates.com/listinfo/textmate