Hello all, I've been cleaning up the JavaScript grammar and as I get started on this next round of cleanups, I've run into some inconsistencies in the grammar that have led to the following questions:
* When adding a language specific implementation of a grammar group, like comment.block for JavaScript, should the name of the group be comment.block (expected) or comment.block.js (What's there now)? (I can't tell if I use the name that corresponds with the root group, comment.block, or if I add the language name to the end like comment.block.js.)
* Is there a way to have certain grammar features enabled based on the existence, or lack of, a certain "enabler" in the file? (For example, JavaScript has a strict mode to mark extra words as keywords due to potential plans for supporting them as keywords in the future. That being said, if you have "use strict;" in your file, certain keywords should be scoped that wouldn't be otherwise *and* variable names with those keywords should be marked as invalid.)
* Why isn't 'null' treated as a constant like undefined/Infinity/NaN? Right now it's constant.language.null.js but I'd expect it to be constant.language.js.
These questions, while specifically about JavaScript's implementation, are really general questions about naming, feature enablement and what defines when you break away from root groups and define your own groups. Any help would be appreciated.
Hello all, One more question about inheritance. I see that the JavaScript grammar has "comment.block.html.js" as a group. While it's invalid, as you can't have XML/HTML comments in JavaScript code even for embedded script content, it does bring up this question:
* Who owns extensions to inherited grammars, the embedding grammar (HTML) or the embedded grammar (JavaScript)? (To answer this, assume that the group above is legit. I'd expect HTML to provide this extension to the JavaScript grammar but what I'm seeing is that the JavaScript grammar has to know it can be embedded by HTML and to provide the HTML extensions.)
Take care,
Jeremy
On Mon, Oct 21, 2013 at 11:27 AM, Jeremy Whitlock jcscoobyrs@gmail.comwrote:
Hello all, I've been cleaning up the JavaScript grammar and as I get started on this next round of cleanups, I've run into some inconsistencies in the grammar that have led to the following questions:
- When adding a language specific implementation of a grammar group, like
comment.block for JavaScript, should the name of the group be comment.block (expected) or comment.block.js (What's there now)? (I can't tell if I use the name that corresponds with the root group, comment.block, or if I add the language name to the end like comment.block.js.)
- Is there a way to have certain grammar features enabled based on the
existence, or lack of, a certain "enabler" in the file? (For example, JavaScript has a strict mode to mark extra words as keywords due to potential plans for supporting them as keywords in the future. That being said, if you have "use strict;" in your file, certain keywords should be scoped that wouldn't be otherwise *and* variable names with those keywords should be marked as invalid.)
- Why isn't 'null' treated as a constant like undefined/Infinity/NaN?
Right now it's constant.language.null.js but I'd expect it to be constant.language.js.
These questions, while specifically about JavaScript's implementation, are really general questions about naming, feature enablement and what defines when you break away from root groups and define your own groups. Any help would be appreciated.
-- Take care,
Jeremy Whitlock (@whitlockjc on Twitter) http://www.thoughtspark.org
On Oct 21, 2013, at 12:27 PM, Jeremy Whitlock jcscoobyrs@gmail.com wrote:
- When adding a language specific implementation of a grammar group, like comment.block for JavaScript, should the name of the group be comment.block (expected) or comment.block.js (What's there now)? (I can't tell if I use the name that corresponds with the root group, comment.block, or if I add the language name to the end like comment.block.js.)
All scopes should end with the grammar's suffix, so `comment.block.js` would be correct.
- Is there a way to have certain grammar features enabled based on the existence, or lack of, a certain "enabler" in the file? (For example, JavaScript has a strict mode to mark extra words as keywords due to potential plans for supporting them as keywords in the future. That being said, if you have "use strict;" in your file, certain keywords should be scoped that wouldn't be otherwise *and* variable names with those keywords should be marked as invalid.)
This could be done by including a begin/end rule that never ends. Match the beginning and add a meta.* scope you can target with injections. You could do a branching grammar as well, but it might lead to more duplication.
- Why isn't 'null' treated as a constant like undefined/Infinity/NaN? Right now it's constant.language.null.js but I'd expect it to be constant.language.js.
No reason it needs to be there in that case, we do provide more info in the scope sometimes just to be more specific. Can be useful in some cases to provide special coloring/etc.
One more question about inheritance. I see that the JavaScript grammar has "comment.block.html.js" as a group. While it's invalid, as you can't have XML/HTML comments in JavaScript code even for embedded script content, it does bring up this question:
- Who owns extensions to inherited grammars, the embedding grammar (HTML) or the embedded grammar (JavaScript)? (To answer this, assume that the group above is legit. I'd expect HTML to provide this extension to the JavaScript grammar but what I'm seeing is that the JavaScript grammar has to know it can be embedded by HTML and to provide the HTML extensions.)
Ideally the HTML would provide the necessary rules, this can be done with injections. It wasn't however possible without them which is why you some lingering artifacts still.