TMLanguage,捕获有什么作用?

发布于 2025-01-15 10:45:40 字数 324 浏览 2 评论 0原文

我正在为 vscode 开发一个 tm 语言项目,我想知道模式上的 captures 属性到底是做什么的。

我似乎无法弄清楚捕获对象的索引代表什么,并且在网上找不到任何有关它的信息。

示例

{
    "match": "(group 1)(group2)"
    "captures": {
        "0": {
             "name": "Name of first capture group? What does 0 mean here?"
         }
    }
}

I am working on a tm language project for vscode and I'm wondering what the captures property on a pattern does exactly.

I can't seem to figure out what the indexes of the captures object stand for and I can't find any information on it online.

Example:

{
    "match": "(group 1)(group2)"
    "captures": {
        "0": {
             "name": "Name of first capture group? What does 0 mean here?"
         }
    }
}

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

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

发布评论

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

评论(1

丑丑阿 2025-01-22 10:45:40

“captures”键记录在“规则键”部分 (12.3) 中:

https:// Macromates.com/manual/en/language_grammars

该名称不是第一个捕获组的名称。它只是一个字符串,指定要应用于该捕获组匹配的字符的样式名称。当我说“捕获组”时,我指的是正则表达式中匹配的左括号和右括号。

使用“captures”键是将样式名称分配给文档中的字符的相对复杂的方法。它允许您为正则表达式匹配的文本的不同部分指定不同的样式。一种更简单的方法是仅使用“名称”键,它将将该样式应用于所有匹配的文本。

The "captures" key is documented here, in the "Rule Keys" section (12.3):

https://macromates.com/manual/en/language_grammars

The name is not the name of the first capture group. It is just a string that specifies the name of the style to apply to the characters that were matched by that capture group. When I say "capture group", I am referring to a matching left paren and right paren in your regular expression.

Using the "captures" key is a relatively complex way to assign style names to characters in the document. It allows you to specify different styles to different portions of the text matched by the regular expression. A simpler way is to just use the "name" key, which will apply the style to all of the matched text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文