Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio code TextMate语法——规则的优先级_Visual Studio Code_Syntax Highlighting_Textmate_Tmlanguage - Fatal编程技术网

Visual studio code TextMate语法——规则的优先级

Visual studio code TextMate语法——规则的优先级,visual-studio-code,syntax-highlighting,textmate,tmlanguage,Visual Studio Code,Syntax Highlighting,Textmate,Tmlanguage,我正在尝试修改CSharp语言的语法高亮显示,因此我将获得C#string中SQL的语法高亮显示。TextMate支持嵌入式语言,因此这似乎是可能的 我建立在上面,我希望能够在类似字符串之前启用带有特殊注释的嵌入式SQL string query = /*SQL*/ $@"SELECT something FROM ..." 多亏了TextMate和我提出了这个JSON规则 "repository": { "embeded-sql": { "contentName":

我正在尝试修改CSharp语言的语法高亮显示,因此我将获得C#string中SQL的语法高亮显示。TextMate支持嵌入式语言,因此这似乎是可能的

我建立在上面,我希望能够在类似字符串之前启用带有特殊注释的嵌入式SQL

string query = /*SQL*/ $@"SELECT something FROM ..."
多亏了TextMate和我提出了这个JSON规则

"repository": {
    "embeded-sql": {
        "contentName": "source.sql",            
        "begin": "/\\*\\s*SQL\\s*\\*/\\s*\\$?@?\"",
        "end": "\";",
        "patterns": [
            {
                "include": "source.sql"
            }
        ]
    },
    ...
}
多亏了VSCode,我能够测试,这条规则才有效

但我有一个问题,我无法解决

我的语法规则仅在禁用csharp规则的Significant部分时有效,如果我禁用所有
#声明
#脚本顶层
,则嵌入式SQL工作:

否则,我的规则将被csharp规则覆盖,如

  • 标点符号.definition.comment.cs
  • string.quoted.double.cs
  • comment.block
  • 等等

问题是,我的规则适用于多个语言元素,而csharp定义在针对这些元素时获胜

元素的标记依据是什么?如何编写我的规则,以便它能够在其他语言规则之前赢得并标记该语法?有计算规则权重的算法吗


解决方案 如果您不能在csharp中劫持注释语法,那么让我们使用SQL中的注释。我通过
--SQL
注释启用了一条规则,并将其应用于逐字记录字符串。现在它可以工作了,但是样式有时会与字符串混合。需要一些额外的改进,但看起来很有希望

证明有效的规则是这样的

    "embeded-sql": {
        "contentName": "source.sql",
        "begin": "--\\s*SQL",
        "end": "(?:\\b|^)(?=\"\\s*;)",
        "patterns": [
            {
                "include": "source.sql"
            }
        ]
    },

现在我想。

模式列表中的规则是按顺序匹配的

您的规则看起来像是注释的专门化,因此您可以将其放在
comment.block.cs

    "comment": {
        "patterns": [
            {
                "contentName": "source.sql",
                "begin": "(/\\*\\s*SQL\\s*\\*/)\\s*\\$?@?\"",
                "beginCaptures": {
                    "1": {
                        "patterns": [
                            {
                                "include": "#comment"
                            }
                        ]
                    }
                },
                "end": "\";",
                "patterns": [
                    {
                        "include": "source.sql"
                    }
                ]
            },
            {
                "name": "comment.block.cs",
                "begin": "/\\*",
                "beginCaptures": {
                    "0": {
                        "name": "punctuation.definition.comment.cs"
                    }
                },
                "end": "\\*/",
                "endCaptures": {
                    "0": {
                        "name": "punctuation.definition.comment.cs"
                    }
                }
            },
            ...
快照是在
my
语言上完成的,该语言只是
c
json加上
sql
嵌入的一个副本