JamesRitchie / language-matlab

MATLAB/Octave language support for Atom
15 stars 9 forks source link

Add injection selectors for embedded grammar #29

Closed Aerijo closed 6 years ago

Aerijo commented 6 years ago

This grammar can automatically embed itself when the injectionSelector scope is found in another grammar.

For example, language-hyperlink uses 'text - string.regexp, string - string.regexp, comment, source.gfm' (the - sign means the following scope is not allowed; so it injects in text, but not when also in string.regexp). This allows hyperlinks to be scoped independently of the main grammar.

Likewise, this change will allow grammars such as language-gfm to automatically embed this one when something like the following occurs

```matlab
<matlab code>

In cases like this, when there is no hardcoded treatment of the language name, `language-gfm` will default to trying to include `source.embedded.<language_name>`, hence why I made the injection selector `source.embedded.matlab`.

I did this to octave too, and also moved the `scopeName` property to the top, where it is visible.
Aerijo commented 6 years ago

This approach causes a bug where the grammar is not applied. See https://github.com/gandm/language-babel/pull/482 for the alternative approach, if anyone here wants to support this being an embedded grammar.