Sublime Forum

Multi syntax highliting using the "embed" approach

#1

I have a custom Perl syntax file for Sublime Text 3 and I would like to add an highlighting support for embedded C++ code.

The inline C++ code always starts with __CPP__ and ends with __END__ among the perl code.

I’m using the ‘embed/match/escape’ approach but the syntax highliting of the C++ code won’t change (getting the scope with ctrl-alt-shift-p it still appears as source.perl).

Here the rule I’m using in my syntax file:

    contexts:
       main:
         - include: inline-cpp
          ...lot of rules...
       
       inline-cpp:
         - match: '__CPP__'
           embed: scope:source.c++
           embed_scope: source.c++.embedded
           escape: '__XXX__'

Please could someone help me figure out what I’m doing wrong?

0 Likes

#2

Maybe need to put your include inside the prototype context instead of main

2 Likes

#3

Great! Thanks for your suggestion that worked like a charme!

contexts:
   main:
       ...
   prototype:
     - include: inline-cpp
   inline-cpp:
     - match: '__CPP__'
       embed: scope:source.c++
       embed_scope: source.c++.embedded
       escape: '__XXX__'
0 Likes