如何嵌入内联C++另一种语言定义中的语法?

发布于 2025-01-19 23:05:43 字数 623 浏览 6 评论 0原文

我有一个 Sublime Text 3 的自定义 Perl 语法文件,我想添加对嵌入式 C++ 代码的突出显示支持。

在 Perl 代码中,内联 C++ 代码始终以 __CPP__ 开头,并以 __END__ 结束。

我正在使用“嵌入/匹配/转义”方法,但 C++ 代码的语法高亮不会改变(使用 ctrl-alt-shift-p 获取范围,它仍然显示为 source.perl)。

这是我在语法文件中使用的规则:

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

请有人帮助我找出我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2025-01-26 23:05:43

解决了将 include 放在 prototype 部分而不是 main 中的问题:

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

Solved putting the include in prototype section instead of main :

   contexts:
       main:
           ...
       prototype:
         - include: inline-cpp
       inline-cpp:
         - match: '__CPP__'
           embed: scope:source.c++
           embed_scope: source.c++.embedded
           escape: '__XXX__'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文