非固定字符长度后的 Textmate 回顾
Text Mate lookbehind after nonfixed character length
我正在为 Visual Studio 代码不支持的编程语言开发语法高亮显示。突出显示效果很好,但我在突出显示以下代码时遇到问题:
pool[] Test1 t1;
pool[1] Test2 t2;
pool[10] Test3 t3;
我使用以下方法突出显示 "pool" 一词:
"storages": {
"patterns": [{
"name": "storage.type.ceu",
"match": "\bpool\b"
}]
},
它正在运行,但我还想突出显示 Test1、Test2 和 Test3 这几个词。
我唯一的想法就是用消极的眼光看后面,像这样:
(?<=pool\[\d*\]\s+)([A-Z])\w+
我用这个想法创建了一个在线 link:https://regexr.com/4793u
但是 oniguruma(TextMate 使用的正则表达式 - Ruby)不允许使用环视。来自 de doc:
(?=subexp) look-ahead
(?!subexp) negative look-ahead
(?<=subexp) look-behind
(?<!subexp) negative look-behind
Subexp of look-behind must be fixed-width.
But top-level alternatives can be of various lengths.
ex. (?<=a|bc) is OK. (?<=aaa(?:b|cd)) is not allowed.
In negative look-behind, capturing group isn't allowed,
but non-capturing group (?:) is allowed.
有谁知道突出显示此语法的任何替代方法?
您可以使用捕获组。在这里,我捕获了 3 个组,但只为第二个分配了一个范围。
"storages": {
"patterns": [{
"match": "^(\w+\[\d*\])\s+(\w+)\s+(\w+);$",
"captures": {
"2": {
"name": "storage.type.ceu"
}
}
}]
},
我正在为 Visual Studio 代码不支持的编程语言开发语法高亮显示。突出显示效果很好,但我在突出显示以下代码时遇到问题:
pool[] Test1 t1;
pool[1] Test2 t2;
pool[10] Test3 t3;
我使用以下方法突出显示 "pool" 一词:
"storages": {
"patterns": [{
"name": "storage.type.ceu",
"match": "\bpool\b"
}]
},
它正在运行,但我还想突出显示 Test1、Test2 和 Test3 这几个词。
我唯一的想法就是用消极的眼光看后面,像这样:
(?<=pool\[\d*\]\s+)([A-Z])\w+
我用这个想法创建了一个在线 link:https://regexr.com/4793u
但是 oniguruma(TextMate 使用的正则表达式 - Ruby)不允许使用环视。来自 de doc:
(?=subexp) look-ahead
(?!subexp) negative look-ahead
(?<=subexp) look-behind
(?<!subexp) negative look-behind
Subexp of look-behind must be fixed-width.
But top-level alternatives can be of various lengths.
ex. (?<=a|bc) is OK. (?<=aaa(?:b|cd)) is not allowed.
In negative look-behind, capturing group isn't allowed,
but non-capturing group (?:) is allowed.
有谁知道突出显示此语法的任何替代方法?
您可以使用捕获组。在这里,我捕获了 3 个组,但只为第二个分配了一个范围。
"storages": {
"patterns": [{
"match": "^(\w+\[\d*\])\s+(\w+)\s+(\w+);$",
"captures": {
"2": {
"name": "storage.type.ceu"
}
}
}]
},