【发布时间】:2019-06-01 16:55:33
【问题描述】:
所以,我正在尝试为 OCaml 的 Menhir parser-generator 构建语法。
在那种语言中,一个文件由三个部分组成,由 %% 分隔(不,它不漂亮;不幸的是,它继承自古老的 ocamlyacc。)
我正在尝试为这三个中的每一个创建一个单独的语法区域,并为无关紧要的第三个 %%:
this should be in `menhirDeclarations`
%%
this should be in `menhirRules`
%%
this should be in `menhirOcamlFooter`
%%
this should be in `menhirSeparatorError`
%%
this should still be in the same `menhirSeparatorError`
我今天一直在研究:h syn-define 文档,到目前为止,我已经定义了一个与第一个声明中的所有内容相匹配的组:
syn region menhirDeclarations start=/\%^/ end=/%%/
\ contains=@menhirComments
...但是我在扩展它以正确匹配以下部分时遇到了很多麻烦。天真的方法对我不起作用,例如:
" These break each document into the three sections of a Menhir parser definition:
syn region menhirSeparatorError start=/%%/ end=/%%/
\ contained contains=@menhirComments
syn region menhirOcamlFooter start=/%%/ end=/%%/
\ contained contains=@menhirCommentsnextgroup=menhirSeparatorError
syn region menhirRules start=/%%/ end=/%%/
\ contained contains=@menhirComments nextgroup=menhirOcamlFooter
syn region menhirDeclarations start=/\%^/ end=/%%/
\ contains=@menhirComments nextgroup=menhirRules
我怎样才能让 Vim 像这样将文件的语法高亮拆分成多个部分?
【问题讨论】:
标签: vim vim-syntax-highlighting