You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在tmLanguage中复用begin捕获组为for循环变量着色?

自定义语言循环变量着色需求及问题

我希望为自定义语言实现这样的着色效果:从?myFor中识别出循环变量,然后在for循环体内为该变量进行着色。

目前我已经写出了如下语法规则,能够通过?myFor和?endMyFor检测循环的开始与结束,但不知道该怎么把begin中的捕获组应用到循环体的剩余部分。

<key>begin</key>
<string>\s*\\?myFor\s?\((.*)\s*=.?,(.*)(<=|<|>|>=|=|==|!=).*,(.*)(\+=|=|-|-=|\*)</string>
<key>beginCaptures</key>
<dict>
    <key>1</key>
    <dict>
        <key>name</key>
        <string>support.variable.generic.a</string>
    </dict>
    <key>2</key>
    <dict>
        <key>name</key>
        <string>support.variable.generic.a</string>
    </dict>
    <key>4</key>
    <dict>
        <key>name</key>
        <string>support.variable.generic.a</string>
    </dict>
</dict>
<key>end</key>
<string>\?endMyFor</string>

内容的提问来源于stack exchange,提问作者Shashank Holla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 15:39:21