How to inject an additional pattern into a Atom or TextMate editor grammar


#1

I am building an Azure Resource Manager (ARM) template grammar for GitHub’s Atom Editor, as it turns out Atom uses the same format for it’s grammar as the TextMate editor. Azure Resource Manager templates are a superset of JSON in that they are 100% valid JSON, however within double quoted strings there can be expressions such as this:

"[concat(variables('vmName)', '01')]"

I have successfully managed to delegate certain blocks of the template to the source.json grammar when there are no interpolated expressions with include: 'source.json'. However, I would like to be able to delegate blocks of the template that include potentially any JSON structure, i.e. objects, arrays, string - in addition to ARM Expressions:

{
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[variables('vmName')]",
  "properties": {
    "hardwareProfile": {
      "vmSize": "[parameters('vmSize')]"
    },
  }
}

I have achieved this to an extent simply by duplicating all of the JSON rules and extending them to support ARM expressions interpolated in double quoted strings:

Screenshot of Syntax Highlight Grammar

It is unlikely that the JSON syntax is going to change significantly, however I would prefer to ‘outsource’ the parsing of the more complex JSON structures to the well maintained JSON grammar, so my question is this:

Is it possible to include a external TextMate or Atom Grammar whilst injecting an additional pattern to be matched and marked up within the included block?


#2

If I’m understanding what you’re asking, it is covered by this (and linked) topics:

And a great description here:


#3

I think that was exactly what I was looking for, just goes to show there is nothing new under this sky.