Question

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)

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?

Was it helpful?

Solution

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

This should work:

syn region fortranDirective start=/!$omp.\{-}/ end=/[^\&]$/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top