2

I'm trying to make a VS Code extension to highlight Pollen Markup files. Those are plain text files with embedded variables and Racket code. Variables have syntax like this (and get later spliced into the text by a preprocessor):

Some text ◊variable-name text continued

And the Racket functions can be embedded using similar syntax:

One plus two is ◊(number->string (+ 1 2)).

I have a tmLanguage file which supports the Racket syntax, and I have a tmlLanguage file which supports the Pollen syntax (text + variables + embedded functions with source.racket in them). I'd like it to correctly highlight this code as well, but couldn't think of a clean solution:

◊n plus ◊m is ◊(number->string (+ ◊n ◊m)).

In other words, Pollen syntax in Racket syntax in Pollen syntax. Is it possible to implement syntax highlighting like this only on the Pollen-side of things, without making a special source.racket file which will support embedded Pollen code?

Something like first highlighting the Racket and then going through the text again, highlighting (and overwriting current color, if present) with the Pollen rules?

Eugleo
  • 418
  • 4
  • 11

1 Answers1

0

I found out about injections, a top level clause which does exactly what I need:

"injections": {
    "L:meta.function-call.racket": {
        "patterns": [
            {
                "include": "text.pollen"
            }
        ]
    }
},

It injects a { "include": "text.pollen" } in every meta.function-call.racket scope — without me needing to edit every place where this scope is used (which is helpful, because that is on lot of places and in another file).

More info can be found in this thread in Atom's forums and in this gist describing a making-of grammar for Atom.

Eugleo
  • 418
  • 4
  • 11