【发布时间】:2016-08-25 13:13:32
【问题描述】:
我正在创建一种简单的后缀编程语言。语法如下:
2 3 add 将两个整数 2 和 3 加在一起。 "hello, world!" puts 将字符串 "hello, world!" 放入 STDOUT。
可以使用的新功能的定义如下:
"fourth_pow"
"This function raises the argument on the top of the stack to the fourth power."
[
dup dup dup mul mul mul
]
def
空格和换行符在语言语法中并不重要。这意味着上面的定义也可以写成"fourth_pow" "..." [ dup dup dup mul mul mul] def(当然,这不太可读)。
我现在想突出显示这种语言的语法,这样在上面的定义语句中,新定义的函数名和def 关键字就会突出显示。
来自.tmLanguage 文件(YAML 格式)的 sn-p 是:
definition:
name: "entity.other.function.jux-beta_syntax"
begin: ("([a-zA-Z_][\w]*[?!]?)")
end: (def)
beginCaptures:
'1': {name: "entity.name.function.jux-beta_syntax"}
contentName: "support.constant.jux-beta_syntax"
patterns:
- include: '#comment'
- include: '#quotation_start'
- include: '#quotation_end'
- include: '#string'
- include: '#identifier'
- include: '#integer'
(查看整个文件here)
这“有效”,但这意味着当我在文件末尾开始一个新字符串时,它会被突出显示,就好像它是一个函数定义一样。这是因为 #definition 规则的“开始”部分匹配。但我想要发生的事情是,只有在比赛可以结束时才给它上色。
有没有办法使用 tmLanguage 格式做到这一点?
【问题讨论】:
标签: syntax-highlighting tmlanguage