-
Notifications
You must be signed in to change notification settings - Fork 57
No way to scope a grammar capture #83
Comments
Thought about this for a while and I think I have a possible solution: adding a new key, something like It's ironic that most of the time, we complain about not having enough context when developing grammars, but in this case, we're hit by the problem of knowing too much context. |
@50Wliu
SGTM. Is my understanding correct in that this would be executed before the child grammar is run, so the child grammar can be run through just a predetermined slice?
Yeah...really unusual. 😆 |
Yeah, at least I hope so. I haven't looked at the implementation to see if it can be done reasonably though. |
I am curious if this issue isn't better specified as issues with the offending grammars. This issue can also be reproduced using a The offending grammar in this case is I can understand the replications with comments, and while they serve their purpose to showcase the issue, I think they're valid situations, because they do what they're supposed to do; the broken syntax highlighting shows that there's an error in your code, and above all, something that's easily fixable. Syntax highlighting is supposed to help you with this. The issue with the optional parameter in JavaScript embedded in Markdown is a lot worse. So is the issue with YAML. It is valid code that appears to have errors. And I might be naive, especially since there are most likely a lot more of these issues, but I think they have to be fixed in their respective grammars. |
The problem is that it isn't invalid code. <script>console.log('hi!'); //</script> is perfectly valid HTML, for example. HTML will always end the script at a closing tag, even if it would otherwise be commented by JavaScript. And for Markdown... ```js console.log('hi!'); /* ``` is also valid, because GFM always ends at the triple backticks, much like HTML. |
@50Wliu You are probably right, and now I understand your |
Status? |
No progress. Implementing this is most likely way beyond the scope of my knowledge, and the rest of the team is busy working on other initiatives, such as faster startup time and improved editor rendering. |
Making progress. It's been slow since I've had to console log my way through every step, but here's where I've gotten to so far. Note that I'll be using the following example (language-gfm + language-javascript): ```js
/*
``` <-- THIS LINE
So it looks like I might know enough now to try implementing the (Also, the reason it took me so long to get here was because I initially missed the |
So sorry to throw a wrench into this, but a fix for this should probably be extended to also cover the scenario of isolating child grammars, so their |
Description
There is no way to scope a grammar capture for specific grammar rules, leading to very odd, buggy-looking syntax highlights.
Steps to Reproduce
language-gfm
andlanguage-javascript
both fulfill this requirement in their grammars.begin
andend
capturepattern
that delegates to another language that also has a rule containing both abegin
andend
capture. (It doesn't have to delegate, though.)Create something that matches that rule. For GFM, a code block tagged with
css
would suffice, and for JS, a tagged template starting withhtml
would work.Within that block, type something that would match the
begin
half of any rule in the other language that includes both abegin
andend
. Do not include the end. For GFM or JS, just start a comment in CSS or HTML, respectively.Observe very odd syntax highlighting. It looks like a bug because it can't be contained, and repros 100% of the time.
If you followed the above repro, the code might look like this pre-syntax highlighting:
GFM -> CSS
JS -> HTML
Here's a few screenshots of other code.
language-gfm
->language-javascript
:language-javascript
->language-html
Versions
OS: Ubuntu GNOME 14.04 (although it's been repro'd in Windows by others)
Atom: v1.12.5 (been going on for quite a while)
Additional Information
Initially reported in atom/language-gfm#171, but I filed it here because it's language-agnostic.
The text was updated successfully, but these errors were encountered: