Sublime Forum

Re-use matches in sublime-syntax

#1

Over some years I’ve been contributing to a sublime-syntax and ever since found it annoying that variables aren’t highlighted within quotes. I figured out how to change this, but I was wondering if there’s a way to re-use previously defined matches (I have a feeling there is!)

This works:

contexts:
  main:
    - match: '\$\w+'
      scope: variable.nsis
    - match: '"'
      captures:
        0: punctuation.definition.string.begin.nsis

      # further down...
      push:
        - meta_scope: string.quoted.double.nsis
        - match: '"'
          captures:
            0: punctuation.definition.string.end.nsis
          pop: true
        - match: \$\\.
          scope: constant.character.escape.nsis
        - match: '\$\w+'
          scope: variable.nsis

This is stupid. I don’t want to define variable.nsis twice (or more often for different types of quotes). There has to be a way of “importing” the match at a later point.

0 Likes

#2

Take a look at the Variables section at http://www.sublimetext.com/docs/3/syntax.html

1 Like

#3

Great, thank you!

Was this possible in the old tmLanguage files?

0 Likes

#4

Nope. In fact, Will has already answered this:

1 Like