语法定义高亮
2017-02-15 本文已影响177人
Jetsly
相关文档
创建语法定义
文件格式有
.YAML-tmLanguage
,.JSON-tmLanguage
,.tmLanguage
{
"name": "",
"scopeName":"",
"fileTypes": [],
"uuid":"",
"patterns":[]
}
name
创建语法定义的编程语言的名称scopeName
语法定义的范围,程序语言用source.<lang_name>
,标记或者其他用text.<lang_name>
fileTypes
这是一个文件扩展名的列表。当打开这些类型的文件时,会自动激活它们的语法定义。uuid
语法定义的唯一标识符patterns
匹配模式的内容,是数组对象
关于匹配模式
1. Matches
{
"match": "",
"name": "",
"comment":"",
}
match
正则匹配name
任何匹配的使用的scope
的名字,naming_conventionscomment
可选的 关于匹配的注释
2. Fine Tuning Matches
{
"match": "",
"name": "",
"comment":"",
"captures": {
"1": { "name": ""}
}
}
captures
正则匹配的捕获的索引项
3. Begin-End Rules
{
"name": "",
"contentName": "",
"comment":"",
"begin": "",
"beginCaptures": {
"1": { "name": ""}
},
"end": "",
"endCaptures": {
"1": { "name": ""}
},
"patterns":[
{
"include":"$self"
}
]
}
name
可选的 就像使用简单的捕获一样,这将为整个匹配设置以下范围名称,包括begin和end标记。实际上,这将为此规则中定义的beginCaptures,endCapture和patterns创建嵌套的范围contentName
可选的 与name不同,这仅将范围名称应用于所包含的文本begin
开始的标记的正则匹配end
结束的标记的正则匹配beginCaptures
可选的 开始的标记的正则匹配的捕获的索引项,和简单的匹配工作一样endCaptures
可选的 结束的标记的正则匹配的捕获的索引项,和简单的匹配工作一样patterns
可选的 与begin-end里的内容匹配的模式数组
测试语法定义(使用vscode)
执行vscode
的_workbench.captureSyntaxTokens
命令
前提是安装了当前语法定义的插件
const {
commands,
Uri
} = require('vscode');
commands.executeCommand('_workbench.captureSyntaxTokens',Uri.file(/*文件路径*/)).then(data=>{
//data : 结果数据
})