多行fortran openmp指令的Vim语法突出显示 [英] Vim syntax highlighting for multiline fortran openmp directives

查看:93
本文介绍了多行fortran openmp指令的Vim语法突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用现代的fortran进行并行编程.我正在使用vim,这确实让我很烦,因为fortran.vim语法文件似乎不处理!$ omp或!dir $之类的编译器指令.这些只是在vim中作为注释呈现,因此它们不突出.在c/c ++中,这些编译器指令是使用#pragma's完成的,因此所有内容都脱颖而出,就像预处理程序代码而不是注释代码一样.所以我想在我的fortran语法中进行类似的处理. 这是我要着色的多行指令的示例:

I'm using modern fortran for doing parallel programming. I'm using vim and it's been really annoying me that the fortran.vim syntax files don't seem to handle compiler directives like !$omp or !dir$. These just get rendered as comments in vim so they don't stand out. In c/c++ these compiler directives are done using #pragma's so everything stands out like it were preprocessor code rather than comment code. So I want similar treatment in my fortran syntax. Here's an example of a multiline directive that I want to colour:

!$omp parallel do reduction(+: sum0) reduction(+: sum1) &
     private( nn, S1, S2, Y1, Y2, rvec0, rvec1, iThreadNum)

到目前为止,我所拥有的是位于$ HOME/.vim/after/syntax中的一个新的fortran.vim文件. 我已经意识到它可以在一行的开头识别出'!$ omp'并为该行着色并为多行正确着色.我的语法文件包含以下内容:

What I have so far is a new fortran.vim file located in $HOME/.vim/after/syntax. I've got it to recognise the '!$omp' at the start of a line and to colour that line and also to colour the multilines properly. My syntax file contains this:

syn region fortranDirective start=/!$omp.*/ end=/[^\&]$/
hi def link fortranDirective PreProc

我的问题是,现在它无法处理仅一行的简单情况.即:

My problem is that it now can't handle the simple case of just a single line. I.e:

!$omp parallel do blah blah
call foobar   <-- this is coloured the same as the line above

我在语法文件中需要某种正则表达式规则,以便能够正确匹配单行和续行.有人可以帮忙吗?

I need some kind of regex rule in my syntax file to be able to correctly match both single line and continued line. Can anybody help please?

推荐答案

据我所知,问题在于您的起始正则表达式过于贪婪.

As far as I can tell, the problem is that your start regex is too greedy.

这应该有效:

syn region fortranDirective start=/!$omp.\{-}/ end=/[^\&]$/

这篇关于多行fortran openmp指令的Vim语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆