英文:
What TextMate scope is used for "normal code/text" in VS Code?
问题
我正在尝试为一种语言创建TextMate语法,该语言中的任何字符串都可以包含插值代码部分。因此,在任何字符串中,位于<%
和%>
之间的内容都被视为“正常”代码,它可以再次包含字符串。
我想要将这个语法用于VS Code扩展。
我的多行字符串由<<
->>
括起来。
我认为在任意深度处理这种情况可能不太可能,所以我希望它能在简单的情况下工作,嵌套的深度最多为某个深度。
以下是以下代码的模式会是什么样子的?
<<
这是一些字符串
<%这是正常代码
<<
这是更多<%正常代码%>字符串<%更多代码%>
>>%>
当然还有更多字符串
>>
我尝试使用以下myLanguage.tmGrammar.yaml
:
name: myLanguage
scopeName: source.myLanguage
patterns:
- begin: <<
end: ">>"
name: string.quoted.double
patterns:
- begin: <%
end: "%>"
include: source.myLanguage
- begin: <%
end: "%>"
name: variable # <--- "default code"的名称是什么?
patterns:
- begin: <<
end: ">>"
include: source.myLanguage
它基本上有效,但我需要使用“正常”代码而不是keyword
突出显示。
英文:
I'm trying to create a TextMate grammar for a language that can have interpolated code sections in any string. So everything between <%
and %>
inside any string is "normal" code, which can have strings again.
I want to use the grammar for a VS Code extension.
My multi-line strings are enclosed by <<
->>
.
I think it is not possible to handle this case for arbitrary depth, so I would be happy to get it to work for simple cases with nesting up to some depth.
What would the patterns look like for the following code?
<<
This is some string
<%This is normal code
<<
This is more <%Normal code%>string <%More code%>
>>%>
And of course more string
>>
I tried to use the following myLanguage.tmGrammar.yaml
:
name: myLanguage
scopeName: source.myLanguage
patterns:
- begin: <<
end: ">>"
name: string.quoted.double
patterns:
- begin: <%
end: "%>"
include: source.myLanguage
- begin: <%
end: "%>"
name: variable # <--- What is the name for "default code"?
patterns:
- begin: <<
end: ">>"
include: source.myLanguage
It mostly works, but I need to use "normal" code instead of keyword
highlighting.
答案1
得分: 0
我遵循了建议,并查看了JavaScript的TestMate语法,并为我的语言调整了反引号字符串。
以下是生成的语法:
name: myLanguage
scopeName: source.myLanguage
patterns:
- include: '#strings'
repository:
strings:
begin: '<<'
end: '>>'
name: string.quoted.double
patterns:
- include: '#interpolation'
interpolation:
begin: '<%'
end: '%>'
contentName: source.myLanguage
name: meta.embedded
patterns:
- include: $self
正常代码部分被突出显示为普通文本。
在<%
-%>
块内的“正常代码”部分上,我能够进行更多的突出显示。
英文:
I followed the advice and looked at the TestMate grammar of JavaScript and adapted the backtick strings for my language.
Here is the resulting grammar:
name: myLanguage
scopeName: source.myLanguage
patterns:
- include: '#strings'
repository:
strings:
begin: '<<'
end: '>>'
name: string.quoted.double
patterns:
- include: '#interpolation'
interpolation:
begin: '<%'
end: '%>'
contentName: source.myLanguage
name: meta.embedded
patterns:
- include: $self
The normal code part is highlighted as normal text.
Expanding on this I was able to do more highlighting within the "normal code" sections inside <%
-&>
-blocks.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论