1

我正在为 Visual Studio Code 的特定语言编写扩展,到目前为止,我可以为多个命令设置颜色。

我有我的mylang.tmLanguage.json其中包含(简化)以下内容:

{
    "\\$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    "name": "F-Script",
    "patterns": [
        { 
            "include": "#goto"      
        },       
        {
            "include": "#strings"
        }
    ],
    "repository": {
        "GOTO": 
        {
            "patterns": 
            [{
                "name": "support.function",
                "match": "/(?!«)[a-zA-Z0-9_.\\-«»/(/)]{1,}(?=»)\\b"
            },
            {
                "name": "support.function",
                "match":"GOTO[(]{1}(# [a-zA-Z0-9_.-]{1,}|/)[)]{1}"
            }]
        },
        "strings": {
            "name": "string.quoted.double.f-script",
            "begin": "\"|\\'",
            "end": "\"|\\'",
            "patterns": [
                {
                    "name": "constant.character.escape.f-script",
                    "match": "$"
                }
            ]
        }                                       
    },
    "scopeName": "source.f-script"
}

当我尝试测试“字符串”的颜色时,会否决命令 GOTO。

«GOTO(# THIS.COLOR.GOTO)»
"This Should be formated like a String"
"This Should be formated like a String «GOTO(# THIS.COLOR.GOTO)»"

我尝试做的是,GOTO第 3 行的颜色与第一个 goto 相同。我的问题是整行都像字符串一样着色(包括GOTO命令)。

有谁知道如何设置字符串格式为字符串并且包含的​​命令颜色不同?

4

1 回答 1

0

您可以简单地包含goto在模式中strings

"strings": {
    "name": "string.quoted.double.f-script",
    "begin": "\"|\\'",
    "end": "\"|\\'",
    "patterns": [
        {
            "name": "constant.character.escape.f-script",
            "match": "$"
        },
        {
            "include": "#goto"
        }
    ]
}

于 2018-01-15T10:54:34.920 回答