A
A
AleksVersus2021-04-03 18:20:18
Sublime Text
AleksVersus, 2021-04-03 18:20:18

How to correctly implement recursive syntax highlighting in Sublime Text3?

I write syntax highlighting for the QSP language (qsp.su) and for some time, despite the difficulties, I managed to find solutions to various points. However, I've recently run into difficulties that stem from my lack of understanding of how recursive highlighting works.

I have some contexts defined: for comments, tags, lines, etc. They all work great and everything lights up great. It is possible to embed subexpressions in strings, for example:
*pl "Текст <<subex+435>>"
In these nested expressions, I decided to highlight the code like everything else, i. with existing contexts, with some exceptions. Here's how I did it:

strings:
    - match: '"'
      push:
        - meta_scope: string.qsp
        - match: '""'
          scope: string.qsp
        - match: '"'
          pop: true
        - include: subexpression
        
    - match: "'"
      push:
        - meta_scope: string.qsp
        - match: "''"
          scope: string.qsp
        - match: "'"
          pop: true
        - include: subexpression

  subexpression:
    - match: '<<'
      scope: entity.name.function entity.name avs.markup
      push:
        - match: '>>'
          scope: entity.name.function entity.name avs.markup
          pop: true
        - include: subex

  subex:
    - include: operacion
    - include: sysvar
    - include: functions
    - include: strings
    - include: numeric

At first glance, everything worked quite adequately and was highlighted, until I started adding highlighting of typical syntax errors to the operacion context. There is some strange behavior here. Not all rules that work in the main code work when trying to use contexts for subexpressions. Either the order of their application is changing, or I don’t understand something at all.

Can anyone show an example of recursive highlighting for Sublime Text 3, or provide a link to something to read on the subject? I read the official ST documentation, it didn't really help me.

If you want to dig right into the highlight file, you can find it here: https://github.com/AleksVersus/JAD_for_QSP/tree/ma...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question