相關(guān)文檔
創(chuàng)建語法定義
文件格式有
.YAML-tmLanguage,.JSON-tmLanguage,.tmLanguage
{
"name": "",
"scopeName":"",
"fileTypes": [],
"uuid":"",
"patterns":[]
}
name創(chuàng)建語法定義的編程語言的名稱scopeName語法定義的范圍,程序語言用source.<lang_name>,標記或者其他用text.<lang_name>fileTypes這是一個文件擴展名的列表。當打開這些類型的文件時,會自動激活它們的語法定義。uuid語法定義的唯一標識符patterns匹配模式的內(nèi)容,是數(shù)組對象
關(guān)于匹配模式
1. Matches
{
"match": "",
"name": "",
"comment":"",
}
match正則匹配name任何匹配的使用的scope的名字,naming_conventionscomment可選的 關(guān)于匹配的注釋
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可選的 就像使用簡單的捕獲一樣,這將為整個匹配設(shè)置以下范圍名稱,包括begin和end標記。實際上,這將為此規(guī)則中定義的beginCaptures,endCapture和patterns創(chuàng)建嵌套的范圍contentName可選的 與name不同,這僅將范圍名稱應(yīng)用于所包含的文本begin開始的標記的正則匹配end結(jié)束的標記的正則匹配beginCaptures可選的 開始的標記的正則匹配的捕獲的索引項,和簡單的匹配工作一樣endCaptures可選的 結(jié)束的標記的正則匹配的捕獲的索引項,和簡單的匹配工作一樣patterns可選的 與begin-end里的內(nèi)容匹配的模式數(shù)組
測試語法定義(使用vscode)
執(zhí)行vscode的_workbench.captureSyntaxTokens命令
前提是安裝了當前語法定義的插件
const {
commands,
Uri
} = require('vscode');
commands.executeCommand('_workbench.captureSyntaxTokens',Uri.file(/*文件路徑*/)).then(data=>{
//data : 結(jié)果數(shù)據(jù)
})