如何启用双语语言语法,以使用TextMateGrammar

问题描述 投票:0回答:1
我们正在研究双语语言的Vscode语言扩展。假设 - 基本语言是一种。 并使用文本伴侣试图启用两种语言的语法突出显示。

file.a

<start of file> // some code with syntax highlighting of language A // following statement is language A syntax which start with <Block> keyword Block parameters; // following is the snippet which start with <Block> keyword and end with <@endBlock> Block parameters; // some code with syntax highlighting of secondary language B @endblock; // some code with syntax highlighting of language A <end of file>

thlowing是TM语法,可以匹配以“块”开头的代码段,并以“ @endblock”结尾。
"patterns": [
        {
          "name" : "meta.block,
          "begin": “(?i)(block)\\W.*$",
          "end": "(?i)^\\s*(@endblock)\\W”,
        }

现在的问题是 - 文本媒体与“ block”语句的启动模式匹配,但是请继续检查“ @endblock”,如果它(@endblock)不可用,则Textmate继续检查相同直到文件结束,因此,由于这种语言 - 语言的语言,就像语言B.

Scenario-1
<Block>
.
. This should not be secondary language B syntax highlighting 
.
<Block>
.
.  This is correct secondary language B syntax highlighting 
.
<@endblock>

Scenario -2

<Block> . . following code should not be secondary language B syntax highlighting, it must be primary language A. . . . . <end of file>
我们不能阻止文本成员既匹配开始又结束,然后才能突出特定的语法,否则忽略?
还是还有其他方法可以解决这个问题?
    

aaddly这是不可能的
textmate是自上而下的解析器
按线解析行

例如。您无法查看多行以查看是否存在某物是否存在

找到最好的方法是在找到
vscode-extensions syntax-highlighting textmate
1个回答
0
投票
时停止语言b。

"end": "(?i)^\\s*(@endblock)\\b|(?=block\\b.*$)”

(我认为您想要
\\b
word-boundary而不是

\\W

非字符)

or

如果您能够在
Block
之后添加评论,则指出下一节应该是语言b

Block // Language B
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.