Include php syntax highlighting in another grammar?


Hello everyone,

I am trying to support both HTML and PHP highlighting in my package. Here is what my grammars.cson file looks like.

# Global Patterns
'patterns': [
    'include': 'text.html.basic'
    'include': 'text.html.php'
    'include': '#components'

The html works correctly when I include it, but not the PHP one. That appears to be the correct scope to when I log it in Atom.

Any ideas?


It might be something to do with all of the HTML patterns being run first and not leaving anything for the PHP patterns. Patterns in an Atom grammar are greedy and remove content from the pool when they match it, so patterns that come first get priority. language-php includes text.html.basic already, so you should be able to include them both by just including PHP.

Your custom stuff should come first for the same reason. If there’s any overlap, patterns at the top win out.