1" Vim syntax file
2" Language:	Fortran 2008 (and older: Fortran 2003, 95, 90, and 77)
3" Version:	(v104) 2021 April 06
4" Maintainer:	Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
5" Usage:	For instructions, do :help fortran-syntax from Vim
6" Credits:
7"  Version 0.1 for Fortran 95 was created in April 2000 by Ajit Thakkar from an
8"  older Fortran 77 syntax file by Mario Eusebio and Preben Guldberg.
9"  Since then, useful suggestions and contributions have been made, in order, by:
10"  Andrej Panjkov, Bram Moolenaar, Thomas Olsen, Michael Sternberg, Christian Reile,
11"  Walter Dieudonne, Alexander Wagner, Roman Bertle, Charles Rendleman,
12"  Andrew Griffiths, Joe Krahn, Hendrik Merx, Matt Thompson, Jan Hermann,
13"  Stefano Zaghi, Vishnu V. Krishnan, Judicael Grasset, Takuma Yoshida,
14"  Eisuke Kawashima, Andre Chalella, and Fritz Reese.
15
16if exists("b:current_syntax")
17  finish
18endif
19
20let s:cpo_save = &cpo
21set cpo&vim
22
23" Choose fortran_dialect using the priority:
24" source file directive > buffer-local value > global value > file extension
25" first try using directive in first three lines of file
26let b:fortran_retype = getline(1)." ".getline(2)." ".getline(3)
27if b:fortran_retype =~? '\<fortran_dialect\s*=\s*F\>'
28  let b:fortran_dialect = "F"
29elseif b:fortran_retype =~? '\<fortran_dialect\s*=\s*f08\>'
30  let b:fortran_dialect = "f08"
31elseif !exists("b:fortran_dialect")
32  if exists("g:fortran_dialect") && g:fortran_dialect =~# '\<F\|f08\>'
33    " try global variable
34    let b:fortran_dialect = g:fortran_dialect
35  else         " nothing found, so use default
36    let b:fortran_dialect = "f08"
37  endif
38endif
39unlet! b:fortran_retype
40" make sure buffer-local value is not invalid
41if b:fortran_dialect !~# '\<F\|f08\>'
42  let b:fortran_dialect = "f08"
43endif
44
45" Choose between fixed and free source form if this hasn't been done yet
46if !exists("b:fortran_fixed_source")
47  if b:fortran_dialect == "F"
48    " F requires free source form
49    let b:fortran_fixed_source = 0
50  elseif exists("fortran_free_source")
51    " User guarantees free source form for all fortran files
52    let b:fortran_fixed_source = 0
53  elseif exists("fortran_fixed_source")
54    " User guarantees fixed source form for all fortran files
55    let b:fortran_fixed_source = 1
56  elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$'
57    " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
58    let b:fortran_fixed_source = 0
59  elseif expand("%:e") =~? '^\%(f\|f77\|for\)$'
60    " Fixed-form file extension defaults
61    let b:fortran_fixed_source = 1
62  else
63    " Modern fortran still allows both free and fixed source form.
64    " Assume fixed source form unless signs of free source form
65    " are detected in the first five columns of the first s:lmax lines.
66    " Detection becomes more accurate and time-consuming if more lines
67    " are checked. Increase the limit below if you keep lots of comments at
68    " the very top of each file and you have a fast computer.
69    let s:lmax = 500
70    if ( s:lmax > line("$") )
71      let s:lmax = line("$")
72    endif
73    let b:fortran_fixed_source = 1
74    let s:ln=1
75    while s:ln <= s:lmax
76      let s:test = strpart(getline(s:ln),0,5)
77      if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
78        let b:fortran_fixed_source = 0
79        break
80      endif
81      let s:ln = s:ln + 1
82    endwhile
83    unlet! s:lmax s:ln s:test
84  endif
85endif
86
87syn case ignore
88
89if b:fortran_fixed_source == 1
90  syn match fortranConstructName	"^\s\{6,}\zs\a\w*\ze\s*:"
91else
92  syn match fortranConstructName	"^\s*\zs\a\w*\ze\s*:"
93endif
94if exists("fortran_more_precise")
95  syn match fortranConstructName "\(\<end\s*do\s\+\)\@11<=\a\w*"
96  syn match fortranConstructName "\(\<end\s*if\s\+\)\@11<=\a\w*"
97  syn match fortranConstructName "\(\<end\s*select\s\+\)\@15<=\a\w*"
98endif
99
100syn match fortranUnitHeader	"\<end\>"
101syn match fortranType		"\<character\>"
102syn match fortranType		"\<complex\>"
103syn match fortranType		"\<integer\>"
104syn match fortranType		"\<real\>"
105syn match fortranType		"\<logical\>"
106syn keyword fortranType		intrinsic
107syn match fortranType		"\<implicit\>"
108syn keyword fortranStructure	dimension
109syn keyword fortranStorageClass	parameter save
110syn match fortranUnitHeader	"\<subroutine\>"
111syn keyword fortranCall		call
112syn match fortranUnitHeader	"\<function\>"
113syn match fortranUnitHeader	"\<program\>"
114syn match fortranUnitHeader	"\<block\>"
115syn keyword fortranKeyword	return stop
116syn keyword fortranConditional	else then
117syn match fortranConditional	"\<if\>"
118syn match fortranConditionalOb	"\<if\s*(.*)\s*\d\+\s*,\s*\d\+\s*,\s*\d\+\s*$"
119syn match fortranRepeat		"\<do\>"
120
121syn keyword fortranTodo		contained todo fixme
122
123"Catch errors caused by too many right parentheses
124syn region fortranParen transparent start="(" end=")" contains=ALLBUT,fortranParenError,@fortranCommentGroup,cIncluded,@spell
125syn match  fortranParenError   ")"
126
127syn match fortranOperator	"\.\s*n\=eqv\s*\."
128syn match fortranOperator	"\.\s*\(and\|or\|not\)\s*\."
129syn match fortranOperator	"\(+\|-\|/\|\*\)"
130syn match fortranTypeOb		"\<character\s*\*"
131
132syn match fortranBoolean	"\.\s*\(true\|false\)\s*\."
133
134syn keyword fortranReadWrite	backspace close endfile inquire open print read rewind write
135
136"If tabs are allowed then the left margin checks do not work
137if exists("fortran_have_tabs")
138  syn match fortranTab		"\t"  transparent
139else
140  syn match fortranTab		"\t"
141endif
142
143syn keyword fortranIO		access blank direct exist file fmt form formatted iostat name named nextrec number opened rec recl sequential status unformatted unit
144
145syn keyword fortranIntrinsicR		alog alog10 amax0 amax1 amin0 amin1 amod cabs ccos cexp clog csin csqrt dabs dacos dasin datan datan2 dcos dcosh ddim dexp dint dlog dlog10 dmax1 dmin1 dmod dnint dsign dsin dsinh dsqrt dtan dtanh float iabs idim idint idnint ifix isign max0 max1 min0 min1 sngl
146
147" Intrinsics provided by some vendors
148syn keyword fortranExtraIntrinsic	algama cdabs cdcos cdexp cdlog cdsin cdsqrt cqabs cqcos cqexp cqlog cqsin cqsqrt dcmplx dconjg derf derfc dfloat dgamma dimag dlgama iqint qabs qacos qasin qatan qatan2 qcmplx qconjg qcos qcosh qdim qerf qerfc qexp qgamma qimag qlgama qlog qlog10 qmax1 qmin1 qmod qnint qsign qsin qsinh qsqrt qtan qtanh
149
150syn keyword fortranIntrinsic	abs acos aimag aint anint asin atan atan2 char cmplx conjg cos cosh exp ichar index int log log10 max min nint sign sin sinh sqrt tan tanh
151syn match fortranIntrinsic	"\<len\s*[(,]"me=s+3
152syn match fortranIntrinsic	"\<real\s*("me=s+4
153syn match fortranIntrinsic	"\<logical\s*("me=s+7
154syn match fortranType           "\<implicit\s\+real\>"
155syn match fortranType           "\<implicit\s\+logical\>"
156
157"Numbers of various sorts
158" Integers
159syn match fortranNumber	display "\<\d\+\(_\a\w*\)\=\>"
160" floating point number, without a decimal point
161syn match fortranFloatIll	display	"\<\d\+[deq][-+]\=\d\+\(_\a\w*\)\=\>"
162" floating point number, starting with a decimal point
163syn match fortranFloatIll	display	"\.\d\+\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
164" floating point number, no digits after decimal
165syn match fortranFloatIll	display	"\<\d\+\.\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
166" floating point number, D or Q exponents
167syn match fortranFloatIll	display	"\<\d\+\.\d\+\([dq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
168" floating point number
169syn match fortranFloat	display	"\<\d\+\.\d\+\(e[-+]\=\d\+\)\=\(_\a\w*\)\=\>"
170" binary number
171syn match fortranBinary	display	"b["'][01]\+["']"
172" octal number
173syn match fortranOctal	display	"o["'][0-7]\+["']"
174" hexadecimal number
175syn match fortranHex	display	"z["'][0-9A-F]\+["']"
176" Numbers in formats
177syn match fortranFormatSpec	display	"\d*f\d\+\.\d\+"
178syn match fortranFormatSpec	display	"\d*e[sn]\=\d\+\.\d\+\(e\d+\>\)\="
179syn match fortranFormatSpec	display	"\d*\(d\|q\|g\)\d\+\.\d\+\(e\d+\)\="
180syn match fortranFormatSpec	display	"\d\+x\>"
181" The next match cannot be used because it would pick up identifiers as well
182" syn match fortranFormatSpec	display	"\<\(a\|i\)\d\+"
183
184" Numbers as labels
185syn match fortranLabelNumber	display	"^\d\{1,5}\s"me=e-1
186syn match fortranLabelNumber	display	"^ \d\{1,4}\s"ms=s+1,me=e-1
187syn match fortranLabelNumber	display	"^  \d\{1,3}\s"ms=s+2,me=e-1
188syn match fortranLabelNumber	display	"^   \d\d\=\s"ms=s+3,me=e-1
189syn match fortranLabelNumber	display	"^    \d\s"ms=s+4,me=e-1
190
191if exists("fortran_more_precise")
192  " Numbers as targets
193  syn match fortranTarget	display	"\(\<if\s*(.\+)\s*\)\@<=\(\d\+\s*,\s*\)\{2}\d\+\>"
194  syn match fortranTarget	display	"\(\<do\s\+\)\@11<=\d\+\>"
195  syn match fortranTarget	display	"\(\<go\s*to\s*(\=\)\@11<=\(\d\+\s*,\s*\)*\d\+\>"
196endif
197
198syn keyword fortranTypeR	external
199syn keyword fortranIOR		format
200syn match fortranKeywordR	"\<continue\>"
201syn match fortranKeyword	"^\s*\d\+\s\+continue\>"
202syn match fortranKeyword  	"\<go\s*to\>"
203syn match fortranKeywordDel  	"\<go\s*to\ze\s\+.*,\s*(.*$"
204syn match fortranKeywordOb  	"\<go\s*to\ze\s*(\d\+.*$"
205syn region fortranStringR	start=+'+ end=+'+ contains=fortranContinueMark,fortranLeftMargin,fortranSerialNumber
206syn keyword fortranIntrinsicR	dim lge lgt lle llt mod
207syn keyword fortranKeywordDel	assign pause
208
209syn match fortranType           "\<type\>"
210syn keyword fortranType	        none
211
212syn keyword fortranStructure	private public intent optional
213syn keyword fortranStructure	pointer target allocatable
214syn keyword fortranStorageClass	in out
215syn match fortranStorageClass	"\<kind\s*="me=s+4
216syn match fortranStorageClass	"\<len\s*="me=s+3
217
218syn match fortranUnitHeader	"\<module\>"
219syn match fortranUnitHeader	"\<submodule\>"
220syn keyword fortranUnitHeader	use only contains
221syn keyword fortranUnitHeader	result operator assignment
222syn match fortranUnitHeader	"\<interface\>"
223syn keyword fortranKeyword	allocate deallocate nullify cycle exit
224syn match fortranConditional	"\<select\>"
225syn keyword fortranConditional	case default where elsewhere
226
227syn match fortranOperator	"\(\(>\|<\)=\=\|==\|/=\|=\)"
228syn match fortranOperator	"=>"
229
230syn region fortranString	start=+"+ end=+"+	contains=fortranLeftMargin,fortranContinueMark,fortranSerialNumber
231syn keyword fortranIO		pad position action delim readwrite
232syn keyword fortranIO		eor advance nml
233
234syn keyword fortranIntrinsic	adjustl adjustr all allocated any associated bit_size btest ceiling count cshift date_and_time digits dot_product eoshift epsilon exponent floor fraction huge iand ibclr ibits ibset ieor ior ishft ishftc lbound len_trim matmul maxexponent maxloc maxval merge minexponent minloc minval modulo mvbits nearest pack precision present product radix random_number random_seed range repeat reshape rrspacing
235syn keyword fortranIntrinsic	scale scan selected_int_kind selected_real_kind set_exponent shape size spacing spread sum system_clock tiny transpose trim ubound unpack verify
236syn match fortranIntrinsic		"\<not\>\(\s*\.\)\@!"me=s+3
237syn match fortranIntrinsic	"\<kind\>\s*[(,]"me=s+4
238
239syn match  fortranUnitHeader	"\<end\s*function"
240syn match  fortranUnitHeader	"\<end\s*interface"
241syn match  fortranUnitHeader	"\<end\s*module"
242syn match  fortranUnitHeader	"\<end\s*submodule"
243syn match  fortranUnitHeader	"\<end\s*program"
244syn match  fortranUnitHeader	"\<end\s*subroutine"
245syn match  fortranUnitHeader	"\<end\s*block"
246syn match  fortranRepeat	"\<end\s*do"
247syn match  fortranConditional	"\<end\s*where"
248syn match  fortranConditional	"\<select\s*case"
249syn match  fortranConditional	"\<end\s*select"
250syn match  fortranType	"\<end\s*type"
251syn match  fortranType	"\<in\s*out"
252
253syn keyword fortranType	        procedure
254syn match  fortranType	        "\<module\ze\s\+procedure\>"
255syn keyword fortranIOR		namelist
256syn keyword fortranConditionalR	while
257syn keyword fortranIntrinsicR	achar iachar transfer
258
259syn keyword fortranInclude		include
260syn keyword fortranStorageClassR	sequence
261
262syn match   fortranConditional	"\<end\s*if"
263syn match   fortranIO		contains=fortranOperator "\<e\(nd\|rr\)\s*=\s*\d\+"
264syn match   fortranConditional	"\<else\s*if"
265
266syn keyword fortranUnitHeaderOb	entry
267syn match fortranTypeR		display "double\s\+precision"
268syn match fortranTypeR		display "double\s\+complex"
269syn match fortranUnitHeaderR	display "block\s\+data"
270syn keyword fortranStorageClassR	common equivalence data
271syn keyword fortranIntrinsicR	dble dprod
272syn match   fortranOperatorR	"\.\s*[gl][et]\s*\."
273syn match   fortranOperatorR	"\.\s*\(eq\|ne\)\s*\."
274
275syn keyword fortranRepeat		forall
276syn match fortranRepeat		"\<end\s*forall"
277syn keyword fortranIntrinsic	null cpu_time
278syn match fortranType			"\<elemental\>"
279syn match fortranType			"\<pure\>"
280syn match fortranType			"\<impure\>"
281syn match fortranType           	"\<recursive\>"
282if exists("fortran_more_precise")
283  syn match fortranConstructName "\(\<end\s*forall\s\+\)\@15<=\a\w*\>"
284endif
285
286if b:fortran_dialect == "f08"
287  " F2003
288  syn keyword fortranIntrinsic        command_argument_count get_command get_command_argument get_environment_variable is_iostat_end is_iostat_eor move_alloc new_line selected_char_kind same_type_as extends_type_of
289  " ISO_C_binding
290  syn keyword fortranConstant         c_null_char c_alert c_backspace c_form_feed c_new_line c_carriage_return c_horizontal_tab c_vertical_tab
291  syn keyword fortranConstant         c_int c_short c_long c_long_long c_signed_char c_size_t c_int8_t c_int16_t c_int32_t c_int64_t c_int_least8_t c_int_least16_t c_int_least32_t c_int_least64_t c_int_fast8_t c_int_fast16_t c_int_fast32_t c_int_fast64_t c_intmax_t C_intptr_t c_float c_double c_long_double c_float_complex c_double_complex c_long_double_complex c_bool c_char c_null_ptr c_null_funptr
292  syn keyword fortranIntrinsic        iso_c_binding c_loc c_funloc c_associated  c_f_pointer c_f_procpointer
293  syn keyword fortranType             c_ptr c_funptr
294  " ISO_Fortran_env
295  syn keyword fortranConstant         iso_fortran_env character_storage_size error_unit file_storage_size input_unit iostat_end iostat_eor numeric_storage_size output_unit
296  " IEEE_arithmetic
297  syn keyword fortranIntrinsic        ieee_arithmetic ieee_support_underflow_control ieee_get_underflow_mode ieee_set_underflow_mode
298
299  syn keyword fortranReadWrite	flush wait
300  syn keyword fortranIO 	      decimal round iomsg
301  syn keyword fortranType             asynchronous nopass non_overridable pass protected volatile extends import
302  syn keyword fortranType             non_intrinsic value bind deferred generic final enumerator
303  syn match fortranType               "\<abstract\>"
304  syn match fortranType               "\<class\>"
305  syn match fortranType               "\<associate\>"
306  syn match fortranType               "\<end\s*associate"
307  syn match fortranType               "\<enum\s*,\s*bind\s*(\s*c\s*)"
308  syn match fortranType               "\<end\s*enum"
309  syn match fortranConditional	"\<select\s*type"
310  syn match fortranConditional        "\<type\s*is\>"
311  syn match fortranConditional        "\<class\s*is\>"
312  syn match fortranUnitHeader         "\<abstract\s*interface\>"
313  syn match fortranOperator           "\([\|]\)"
314
315  " F2008
316  syn keyword fortranIntrinsic        acosh asinh atanh bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn erf erfc erfc_scaled gamma log_gamma hypot norm2
317  syn keyword fortranIntrinsic        atomic_define atomic_ref execute_command_line leadz trailz storage_size merge_bits
318  syn keyword fortranIntrinsic        bge bgt ble blt dshiftl dshiftr findloc iall iany iparity image_index lcobound ucobound maskl maskr num_images parity popcnt poppar shifta shiftl shiftr this_image
319  syn keyword fortranIO               newunit
320  syn keyword fortranType             contiguous
321  syn keyword fortranRepeat           concurrent
322
323" CUDA fortran
324  syn match fortranTypeCUDA           "\<attributes\>"
325  syn keyword fortranTypeCUDA         host global device value
326  syn keyword fortranTypeCUDA         shared constant pinned texture
327  syn keyword fortranTypeCUDA         dim1 dim2 dim3 dim4
328  syn keyword fortranTypeCUDA         cudadeviceprop cuda_count_kind cuda_stream_kind
329  syn keyword fortranTypeCUDA         cudaEvent cudaFuncAttributes cudaArrayPtr
330  syn keyword fortranTypeCUDA         cudaSymbol cudaChannelFormatDesc cudaPitchedPtr
331  syn keyword fortranTypeCUDA         cudaExtent cudaMemcpy3DParms
332  syn keyword fortranTypeCUDA         cudaFuncCachePreferNone cudaFuncCachePreferShared
333  syn keyword fortranTypeCUDA         cudaFuncCachePreferL1 cudaLimitStackSize
334  syn keyword fortranTypeCUDA         cudaLimitPrintfSize cudaLimitMallocHeapSize
335  syn keyword fortranTypeCUDA         cudaSharedMemBankSizeDefault cudaSharedMemBankSizeFourByte cudaSharedMemBankSizeEightByte
336  syn keyword fortranTypeCUDA         cudaEventDefault cudaEventBlockingSync cudaEventDisableTiming
337  syn keyword fortranTypeCUDA         cudaMemcpyHostToDevice cudaMemcpyDeviceToHost
338  syn keyword fortranTypeCUDA         cudaMemcpyDeviceToDevice
339  syn keyword fortranTypeCUDA         cudaErrorNotReady cudaSuccess cudaErrorInvalidValue
340  syn keyword fortranTypeCUDA         c_devptr
341
342  syn match fortranStringCUDA         "blockidx%[xyz]"
343  syn match fortranStringCUDA         "blockdim%[xyz]"
344  syn match fortranStringCUDA         "griddim%[xyz]"
345  syn match fortranStringCUDA         "threadidx%[xyz]"
346
347  syn keyword fortranIntrinsicCUDA    warpsize syncthreads syncthreads_and syncthreads_count syncthreads_or threadfence threadfence_block threadfence_system gpu_time allthreads anythread ballot
348  syn keyword fortranIntrinsicCUDA    atomicadd atomicsub atomicmax atomicmin atomicand atomicor atomicxor atomicexch atomicinc atomicdec atomiccas sizeof __shfl __shfl_up __shfl_down __shfl_xor
349  syn keyword fortranIntrinsicCUDA    cudaChooseDevice cudaDeviceGetCacheConfig cudaDeviceGetLimit cudaDeviceGetSharedMemConfig cudaDeviceReset cudaDeviceSetCacheConfig cudaDeviceSetLimit cudaDeviceSetSharedMemConfig cudaDeviceSynchronize cudaGetDevice cudaGetDeviceCount cudaGetDeviceProperties cudaSetDevice cudaSetDeviceFlags cudaSetValidDevices
350  syn keyword fortranIntrinsicCUDA    cudaThreadExit cudaThreadSynchronize cudaGetLastError cudaGetErrorString cudaPeekAtLastError cudaStreamCreate cudaStreamDestroy cudaStreamQuery cudaStreamSynchronize cudaStreamWaitEvent cudaEventCreate cudaEventCreateWithFlags cudaEventDestroy cudaEventElapsedTime cudaEventQuery cudaEventRecord cudaEventSynchronize
351  syn keyword fortranIntrinsicCUDA    cudaFuncGetAttributes cudaFuncSetCacheConfig cudaFuncSetSharedMemConfig cudaSetDoubleForDevice cudaSetDoubleForHost cudaFree cudaFreeArray cudaFreeHost cudaGetSymbolAddress cudaGetSymbolSize
352  syn keyword fortranIntrinsicCUDA    cudaHostAlloc cudaHostGetDevicePointer cudaHostGetFlags cudaHostRegister cudaHostUnregister cudaMalloc cudaMallocArray cudaMallocHost cudaMallocPitch cudaMalloc3D cudaMalloc3DArray
353  syn keyword fortranIntrinsicCUDA    cudaMemcpy cudaMemcpyArraytoArray cudaMemcpyAsync cudaMemcpyFromArray cudaMemcpyFromSymbol cudaMemcpyFromSymbolAsync cudaMemcpyPeer cudaMemcpyPeerAsync cudaMemcpyToArray cudaMemcpyToSymbol cudaMemcpyToSymbolAsync cudaMemcpy2D cudaMemcpy2DArrayToArray cudaMemcpy2DAsync cudaMemcpy2DFromArray cudaMemcpy2DToArray cudaMemcpy3D cudaMemcpy3DAsync
354  syn keyword fortranIntrinsicCUDA    cudaMemGetInfo cudaMemset cudaMemset2D cudaMemset3D cudaDeviceCanAccessPeer cudaDeviceDisablePeerAccess cudaDeviceEnablePeerAccess cudaPointerGetAttributes cudaDriverGetVersion cudaRuntimeGetVersion
355
356  syn region none matchgroup=fortranType start="<<<" end=">>>" contains=ALLBUT,none
357endif
358
359syn cluster fortranCommentGroup contains=fortranTodo
360
361if (b:fortran_fixed_source == 1)
362  if !exists("fortran_have_tabs")
363    " Fixed format requires a textwidth of 72 for code,
364    " but some vendor extensions allow longer lines
365    if exists("fortran_extended_line_length")
366      syn match fortranSerialNumber	excludenl "^.\{133,}$"lc=132
367    elseif exists("fortran_cardimage_line_length")
368      syn match fortranSerialNumber	excludenl "^.\{81,}$"lc=80
369    else
370      syn match fortranSerialNumber	excludenl "^.\{73,}$"lc=72
371    endif
372    "Flag left margin errors
373    syn match fortranLabelError	"^.\{-,4}[^0-9 ]" contains=fortranTab
374    syn match fortranLabelError	"^.\{4}\d\S"
375  endif
376  syn match fortranComment		excludenl "^[!c*].*$" contains=@fortranCommentGroup,@spell
377  syn match fortranLeftMargin		transparent "^ \{5}"
378  syn match fortranContinueMark		display "^.\{5}\S"lc=5
379else
380  syn match fortranContinueMark		display "&"
381endif
382
383syn match fortranComment	excludenl "!.*$" contains=@fortranCommentGroup,@spell
384syn match fortranOpenMP		excludenl 		"^\s*!\$\(OMP\)\=&\=\s.*$"
385
386"cpp is often used with Fortran
387syn match	cPreProc		"^\s*#\s*\(define\|ifdef\)\>.*"
388syn match	cPreProc		"^\s*#\s*\(elif\|if\)\>.*"
389syn match	cPreProc		"^\s*#\s*\(ifndef\|undef\)\>.*"
390syn match	cPreCondit		"^\s*#\s*\(else\|endif\)\>.*"
391syn region	cIncluded	contained start=+"[^("]+ skip=+\\\\\|\\"+ end=+"+ contains=fortranLeftMargin,fortranContinueMark,fortranSerialNumber
392"syn region	cIncluded	        contained start=+"[^("]+ skip=+\\\\\|\\"+ end=+"+
393syn match	cIncluded		contained "<[^>]*>"
394syn match	cInclude		"^\s*#\s*include\>\s*["<]" contains=cIncluded
395
396"Synchronising limits assume that comment and continuation lines are not mixed
397if exists("fortran_fold") || exists("fortran_more_precise")
398  syn sync fromstart
399elseif (b:fortran_fixed_source == 0)
400  syn sync linecont "&" minlines=30
401else
402  syn sync minlines=30
403endif
404
405if exists("fortran_fold")
406
407  if (b:fortran_fixed_source == 1)
408    syn region fortranProgram transparent fold keepend start="^\s*program\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\(program\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranModule
409    syn region fortranModule transparent fold keepend start="^\s*submodule\s\+(\a\w*\s*\(:\a\w*\s*\)*)\s*\z\(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\(submodule\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram,fortranModule
410    syn region fortranModule transparent fold keepend start="^\s*module\s\+\(procedure\)\@!\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\(module\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram
411    syn region fortranFunction transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*\(\(\(real \|integer \|logical \|complex \|double \s*precision \)\s*\((\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\|type\s\+(\s*\w\+\s*) \|character \((\(\s*len\s*=\)\=\s*\d\+\s*)\|(\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\=\s*function\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|function\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule
412    syn region fortranSubroutine transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*subroutine\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|subroutine\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule
413    syn region fortranBlockData transparent fold keepend start="\<block\s*data\(\s\+\z(\a\w*\)\)\=" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|block\s*data\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock
414    syn region fortranAssociate transparent fold keepend start="^\s*\<associate\s\+" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*associate" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction
415    syn region fortranInterface transparent fold keepend extend start="^\s*\(abstract \)\=\s*interface\>" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*interface\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock
416    syn region fortranTypeDef transparent fold keepend extend start="^\s*type\s*\(,\s*\(public\|private\|abstract\)\)\=\s*::" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*type\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock,fortranInterface
417  else
418    syn region fortranProgram transparent fold keepend start="^\s*program\s\+\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\(program\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranModule
419    syn region fortranModule transparent fold keepend start="^\s*submodule\s\+(\a\w*\s*\(:\a\w*\s*\)*)\s*\z\(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\(submodule\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram,fortranModule
420    syn region fortranModule transparent fold keepend start="^\s*module\s\+\(procedure\)\@!\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\(module\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram
421    syn region fortranFunction transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*\(\(\(real \|integer \|logical \|complex \|double \s*precision \)\s*\((\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\|type\s\+(\s*\w\+\s*) \|character \((\(\s*len\s*=\)\=\s*\d\+\s*)\|(\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\=\s*function\s\+\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|function\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule
422    syn region fortranSubroutine transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*subroutine\s\+\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|subroutine\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule
423    syn region fortranBlockData transparent fold keepend start="\<block\s*data\(\s\+\z(\a\w*\)\)\=" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|block\s*data\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock
424    syn region fortranAssociate transparent fold keepend start="^\s*\<associate\s\+" skip="^\s*[!#].*$" excludenl end="\<end\s*associate" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction
425    syn region fortranInterface transparent fold keepend extend start="^\s*\(abstract \)\=\s*interface\>" skip="^\s*[!#].*$" excludenl end="\<end\s*interface\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock
426    syn region fortranTypeDef transparent fold keepend extend start="^\s*type\s*\(,\s*\(public\|private\|abstract\)\)\=\s*::" skip="^\s*[!#].*$" excludenl end="\<end\s*type\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock,fortranInterface
427  endif
428
429  if exists("fortran_fold_conditionals")
430    if (b:fortran_fixed_source == 1)
431      syn region fortran77Loop transparent fold keepend start="\<do\s\+\z(\d\+\)" end="^\s*\z1\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
432      syn region fortran90Loop transparent fold keepend extend start="\(\<end\s\+\)\@<!\<do\(\s\+\a\|\s*$\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*do\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
433      syn region fortranIfBlock transparent fold keepend extend start="\(\<e\(nd\|lse\)\s\+\)\@<!\<if\s*(.\+)\s*then\>" skip="^\([!c*]\|\s*#\).*$" end="\<end\s*if\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
434      syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\)\>" skip="^\([!c*]\|\s*#\).*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
435    else
436      syn region fortran77Loop transparent fold keepend start="\<do\s\+\z(\d\+\)" end="^\s*\z1\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
437      syn region fortran90Loop transparent fold keepend extend start="\(\<end\s\+\)\@<!\<do\(\s\+\a\|\s*$\)" skip="^\s*[!#].*$" excludenl end="\<end\s*do\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
438      syn region fortranIfBlock transparent fold keepend extend start="\(\<e\(nd\|lse\)\s\+\)\@<!\<if\s*(\(.\|&\s*\n\)\+)\(\s\|&\s*\n\)*then\>" skip="^\s*[!#].*$" end="\<end\s*if\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
439      syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\)\>" skip="^\s*[!#].*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranStructure,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData
440    endif
441  endif
442
443  if exists("fortran_fold_multilinecomments")
444    if (b:fortran_fixed_source == 1)
445      syn match fortranMultiLineComments transparent fold "\(^[!c*].*\(\n\|\%$\)\)\{4,}" contains=ALLBUT,fortranMultiCommentLines
446    else
447      syn match fortranMultiLineComments transparent fold "\(^\s*!.*\(\n\|\%$\)\)\{4,}" contains=ALLBUT,fortranMultiCommentLines
448    endif
449  endif
450endif
451
452" Define the default highlighting.
453" The default highlighting differs for each dialect.
454" Transparent groups:
455" fortranParen, fortranLeftMargin
456" fortranProgram, fortranModule, fortranSubroutine, fortranFunction,
457" fortranBlockData
458" fortran77Loop, fortran90Loop, fortranIfBlock, fortranCase
459" fortranMultiCommentLines
460hi def link fortranKeyword 	Keyword
461hi def link fortranConstructName	Identifier
462hi def link fortranConditional	Conditional
463hi def link fortranRepeat	Repeat
464hi def link fortranTodo		Todo
465hi def link fortranContinueMark	Special
466hi def link fortranString	String
467hi def link fortranNumber	Number
468hi def link fortranBinary	Number
469hi def link fortranOctal	Number
470hi def link fortranHex  	Number
471hi def link fortranOperator	Operator
472hi def link fortranBoolean	Boolean
473hi def link fortranLabelError	Error
474hi def link fortranObsolete	Todo
475hi def link fortranType		Type
476hi def link fortranStructure	Type
477hi def link fortranStorageClass	StorageClass
478hi def link fortranCall		Function
479hi def link fortranUnitHeader	fortranPreCondit
480hi def link fortranReadWrite	Keyword
481hi def link fortranIO		Keyword
482hi def link fortranIntrinsic	Function
483hi def link fortranConstant	Constant
484
485" To stop deleted & obsolescent features being highlighted as Todo items,
486" comment out the next 5 lines and uncomment the 5 lines after that
487hi def link fortranUnitHeaderOb    fortranObsolete
488hi def link fortranKeywordOb       fortranObsolete
489hi def link fortranConditionalOb   fortranObsolete
490hi def link fortranTypeOb          fortranObsolete
491hi def link fortranKeywordDel      fortranObsolete
492"hi def link fortranUnitHeaderOb    fortranUnitHeader
493"hi def link fortranKeywordOb       fortranKeyword
494"hi def link fortranConditionalOb   fortranConditional
495"hi def link fortranTypeOb          fortranType
496"hi def link fortranKeywordDel      fortranKeyword
497
498if b:fortran_dialect == "F"
499  hi! def link fortranIntrinsicR	fortranObsolete
500  hi! def link fortranUnitHeaderR	fortranObsolete
501  hi! def link fortranTypeR		fortranObsolete
502  hi! def link fortranStorageClassR	fortranObsolete
503  hi! def link fortranOperatorR 	fortranObsolete
504  hi! def link fortranInclude   	fortranObsolete
505  hi! def link fortranLabelNumber	fortranObsolete
506  hi! def link fortranTarget	        fortranObsolete
507  hi! def link fortranFloatIll	        fortranObsolete
508  hi! def link fortranIOR		fortranObsolete
509  hi! def link fortranKeywordR	        fortranObsolete
510  hi! def link fortranStringR	        fortranObsolete
511  hi! def link fortranConditionalR	fortranObsolete
512else
513  hi! def link fortranIntrinsicR	fortranIntrinsic
514  hi! def link fortranUnitHeaderR	fortranPreCondit
515  hi! def link fortranTypeR		fortranType
516  hi! def link fortranStorageClassR	fortranStorageClass
517  hi! def link fortranOperatorR	        fortranOperator
518  hi! def link fortranInclude	        Include
519  hi! def link fortranLabelNumber	Special
520  hi! def link fortranTarget	        Special
521  hi! def link fortranFloatIll	        fortranFloat
522  hi! def link fortranIOR		fortranIO
523  hi! def link fortranKeywordR	        fortranKeyword
524  hi! def link fortranStringR	        fortranString
525  hi! def link fortranConditionalR	fortranConditional
526endif
527
528" CUDA
529hi def link fortranIntrinsicCUDA        fortranIntrinsic
530hi def link fortranTypeCUDA             fortranType
531hi def link fortranStringCUDA           fortranString
532
533hi def link fortranFormatSpec	Identifier
534hi def link fortranFloat	Float
535hi def link fortranPreCondit	PreCondit
536hi def link cIncluded		fortranString
537hi def link cInclude		Include
538hi def link cPreProc		PreProc
539hi def link cPreCondit		PreCondit
540hi def link fortranOpenMP       PreProc
541hi def link fortranParenError	Error
542hi def link fortranComment	Comment
543hi def link fortranSerialNumber	Todo
544hi def link fortranTab		Error
545
546" Uncomment the next line if you use extra intrinsics provided by vendors
547"hi def link fortranExtraIntrinsic	Function
548
549let b:current_syntax = "fortran"
550
551let &cpo = s:cpo_save
552unlet s:cpo_save
553" vim: ts=8 tw=132
554