How to prioritize grammar injections?


#1

So I read Grammar injections and I studied the TextMate documentation on grammars and I studied how language-php does it.

I created a new language-fooxml package with the intent of syntax-highlighting CDATA sections as JavaScript. I modified grammars/fooxml.cson to look like this:

'scopeName': 'text.xml.fooxml'
'name': 'FOO XML'
'injections':
    'text.xml.fooxml':
        'patterns': [
            {
                'begin': '<!\\[CDATA\\['
                'beginCaptures':
                    '0':
                        'name': 'punctuation.definition.string.begin.xml'
                'end': ']]>'
                'endCaptures':
                    '0':
                        'name': 'punctuation.definition.string.end.xml'
                'name': 'source.js.embedded.xml'
                'contentName': 'source.js'
                'patterns': [
                    {
                        'include': 'source.js'
                    }
                ]
            }
            {
                'name': 'xyzzy'
                'match': 'xyzzy'
            }
        ]
'patterns': [
    {
        'include': 'text.xml'
    }
]

I can see it’s evaluated by typing xyzzy into my file and seeing that the scope is applied. But CDATA sections are still highlighted like they are in regular XML files.

I tried a few variants of the injections line:

  • L:text.xml.fooxml with L: prefix
  • text.xml.fooxml, L:source.js.embedded.xml

I also tried a number of variations on the actual CDATA pattern rule:

  • 'name': 'source.js' without contentName and the nested patterns

No wonder it didn’t help – I have no idea what I’m doing.


#2

Do you mind sharing what you currently have on Github? I’d like to take a look at it. My current Atom project is along similar lines, so this is relevant to my interest.