相關文檔
創(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
匹配模式的內容,是數(shù)組對象
關于匹配模式
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標記。實際上,這將為此規(guī)則中定義的beginCaptures,endCapture和patterns創(chuàng)建嵌套的范圍contentName
可選的 與name不同,這僅將范圍名稱應用于所包含的文本begin
開始的標記的正則匹配end
結束的標記的正則匹配beginCaptures
可選的 開始的標記的正則匹配的捕獲的索引項,和簡單的匹配工作一樣endCaptures
可選的 結束的標記的正則匹配的捕獲的索引項,和簡單的匹配工作一樣patterns
可選的 與begin-end里的內容匹配的模式數(shù)組
測試語法定義(使用vscode)
執(zhí)行vscode
的_workbench.captureSyntaxTokens
命令
前提是安裝了當前語法定義的插件
const {
commands,
Uri
} = require('vscode');
commands.executeCommand('_workbench.captureSyntaxTokens',Uri.file(/*文件路徑*/)).then(data=>{
//data : 結果數(shù)據(jù)
})