TMLanguage,捕获有什么作用?
我正在为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“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.