" Vim syntax file " Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, and 77) " Version: (v107) 2023 December 17 " Maintainers: Ajit J. Thakkar ; " Joshua Hollett " Usage: For instructions, do :help fortran-syntax from Vim " Credits: " Version 0.1 for Fortran 95 was created in April 2000 by Ajit Thakkar from an " older Fortran 77 syntax file by Mario Eusebio and Preben Guldberg. " Since then, useful suggestions and contributions have been made, in order, by: " Andrej Panjkov, Bram Moolenaar, Thomas Olsen, Michael Sternberg, Christian Reile, " Walter Dieudonne, Alexander Wagner, Roman Bertle, Charles Rendleman, " Andrew Griffiths, Joe Krahn, Hendrik Merx, Matt Thompson, Jan Hermann, " Stefano Zaghi, Vishnu V. Krishnan, Judicael Grasset, Takuma Yoshida, " Eisuke Kawashima, Andre Chalella, Fritz Reese, Karl D. Hammond, " and Michele Esposito Marzino. if exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim " Choose between fixed and free source form if this hasn't been done yet if !exists("b:fortran_fixed_source") if exists("fortran_free_source") " User guarantees free source form for all fortran files let b:fortran_fixed_source = 0 elseif exists("fortran_fixed_source") " User guarantees fixed source form for all fortran files let b:fortran_fixed_source = 1 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$' " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers let b:fortran_fixed_source = 0 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$' " Fixed-form file extension defaults let b:fortran_fixed_source = 1 else " Modern fortran compilers still allow both free and fixed source form. " Assume fixed source form unless signs of free source form " are detected in the first five columns of the first s:lmax lines. " Detection becomes more accurate and time-consuming if more lines " are checked. Increase the limit below if you keep lots of comments at " the very top of each file and you have a fast computer. let s:lmax = 500 if ( s:lmax > line("$") ) let s:lmax = line("$") endif let b:fortran_fixed_source = 1 let s:ln=1 while s:ln <= s:lmax let s:test = strpart(getline(s:ln),0,5) if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t' let b:fortran_fixed_source = 0 break endif let s:ln = s:ln + 1 endwhile unlet! s:lmax s:ln s:test endif endif syn case ignore if b:fortran_fixed_source == 1 syn match fortranConstructName "^\s\{6,}\zs\a\w*\ze\s*:" else syn match fortranConstructName "^\s*\zs\a\w*\ze\s*:" endif syn match fortranConstructName "\(\" syn match fortranUnitName "\(\(end\s*\)\?\(subroutine\|function\|module\|program\|submodule\)\s\+\)\@12<=\a\w\+" syn match fortranUnitHeader "\\ze\s*(' syn match fortranIntrinsic "\" syn match fortranType "^\s*implicit\s\+none" syn match fortranType "\(class\|type\)\(of\)\?" syn match fortranType "\(end\s*\)\?\" syn match fortranType "\" syn match fortranType "\(end\s*\)\?enumeration\s\+type" syn match fortranType "\(end\s*\)\?\(\" syn match fortranTypeR display "double\s*precision" syn match fortranTypeR display "double\s\+complex" syn keyword fortranAttribute value bind deferred contiguous intrinsic non_intrinsic syn keyword fortranAttribute asynchronous nopass non_overridable pass volatile extends syn keyword fortranAttribute abstract external private public protected intent optional syn keyword fortranAttribute pointer target allocatable dimension codimension sequence parameter save syn keyword fortranUnitHeader result operator assignment syn match fortranUnitHeader "\(end\s*\)\?\(subroutine\|function\|module\|program\|submodule\)\>" syn match fortranBlock "\(end\s*\)\?\(block\|critical\|associate\)\>" syn match fortranCalled "\(call\s\+\)\@7<=\a\w*" syn match fortranRepeat "\" syn keyword fortranRepeat concurrent syn keyword fortranRepeatR while syn match fortranRepeat "\" syn keyword fortranTodo contained bug note debug todo fixme "Catch errors caused by too many right parentheses syn region fortranParen transparent start="(" end=")" contains=ALLBUT,fortranParenError,@fortranCommentGroup,cIncluded,@spell syn match fortranParenError ")" syn match fortranOperator "\.\s*n\=eqv\s*\." syn match fortranOperator "\.\s*\(and\|or\|not\)\s*\." syn match fortranOperator "\(+\|-\|/\|\*\)" syn match fortranOperator "\(\(>\|<\)=\=\|==\|/=\|=\)" syn match fortranOperator "\(%\|?\|=>\)" syn match fortranOperator "\([\|]\)" syn match fortranOperatorR "\.\s*[gl][et]\s*\." syn match fortranOperatorR "\.\s*\(eq\|ne\)\s*\." syn keyword fortranReadWrite print flush syn match fortranReadWrite '\<\(backspace\|close\|endfile\|inquire\|open\|read\|rewind\|write\)\ze\s*(' "If tabs are allowed then the left margin checks do not work if exists("fortran_have_tabs") syn match fortranTab "\t" transparent else syn match fortranTab "\t" endif "Numbers of various sorts " Integers syn match fortranNumber display "\<\d\+\(_\a\w*\)\=\>" " floating point number, without a decimal point syn match fortranFloatIll display "\<\d\+[deq][-+]\=\d\+\(_\a\w*\)\=\>" " floating point number, starting with a decimal point syn match fortranFloatIll display "\.\d\+\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>" " floating point number, no digits after decimal syn match fortranFloatIll display "\<\d\+\.\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>" " floating point number, D or Q exponents syn match fortranFloatIll display "\<\d\+\.\d\+\([dq][-+]\=\d\+\)\=\(_\a\w*\)\=\>" " floating point number syn match fortranFloat display "\<\d\+\.\d\+\(e[-+]\=\d\+\)\=\(_\a\w*\)\=\>" " binary number syn match fortranBinary display "b["'][01]\+["']" " octal number syn match fortranOctal display "o["'][0-7]\+["']" " hexadecimal number syn match fortranHex display "z["'][0-9A-F]\+["']" " Numbers in formats syn match fortranFormatSpec display "\d*f\d\+\.\d\+" syn match fortranFormatSpec display "\d*e[sn]\=\d\+\.\d\+\(e\d+\>\)\=" syn match fortranFormatSpec display "\d*\(d\|q\|g\)\d\+\.\d\+\(e\d+\)\=" syn match fortranFormatSpec display "\d\+x\>" " The next match cannot be used because it would pick up identifiers as well " syn match fortranFormatSpec display "\<\(a\|i\)\d\+" " Numbers as labels syn match fortranLabelNumber display "^\d\{1,5}\s"me=e-1 syn match fortranLabelNumber display "^ \d\{1,4}\s"ms=s+1,me=e-1 syn match fortranLabelNumber display "^ \d\{1,3}\s"ms=s+2,me=e-1 syn match fortranLabelNumber display "^ \d\d\=\s"ms=s+3,me=e-1 syn match fortranLabelNumber display "^ \d\s"ms=s+4,me=e-1 " Numbers as targets syn match fortranTarget display "\(\" syn match fortranTarget display "\(\" syn match fortranTarget display "\(\" syn match fortranBoolean "\.\s*\(true\|false\)\s*\." syn match fortranKeyword "call" syn keyword fortranKeyword use only contains syn match fortranKeyword "fail\s\+image\>" syn match fortranKeyword "\(error\s\+\)\=stop" syn match fortranKeyword "\" syn match fortranKeyword "^\s*\d\+\s\+continue\>" syn match fortranKeyword "\" syn match fortranKeywordDel "\" syn match fortranConditional "\" syn match fortranConditional "\(case\|rank\)\(\s\+default\)\?" syn match fortranConditionalDel "\" syn match fortranImageControl "\(change\|form\|end\)\s\+team\>" syn match fortranImageControl "event\s\+\(post\|wait\)" syn match fortranImageControl "\(un\)\?lock\ze\s*(" syn match fortranImageControl "notify\s\+wait\ze\s*(" syn keyword fortranUnitHeaderOb entry syn match fortranUnitHeaderOb display "block\s*data" syn keyword fortranStorageClass in out syn match fortranStorageClass "\" syn match fortranStorageClass "\\(\s\+\a\w*\s*/\)\@=" syn match fortranStorageClassOb "^\s*common\>" syn match fortranStorageClassOb "^\s*common\>\(\s*/\)\@=" syn keyword fortranStorageClassOb equivalence 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 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 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 stat_failed_image stat_unlocked_failed_image syn keyword fortranConstant int8 int16 int32 int64 real16 real32 real64 real128 character_kinds integer_kinds logical_kinds real_kinds iostat_inquire_internal_unit syn keyword fortranConstant ieee_negative_subnormal ieee_positive_subnormal " CUDA fortran if exists("fortran_CUDA") syn match fortranTypeCUDA "\" syn keyword fortranTypeCUDA host global device syn keyword fortranTypeCUDA shared constant pinned texture syn keyword fortranTypeCUDA dim1 dim2 dim3 dim4 syn keyword fortranTypeCUDA cudadeviceprop cuda_count_kind cuda_stream_kind syn keyword fortranTypeCUDA cudaEvent cudaFuncAttributes cudaArrayPtr syn keyword fortranTypeCUDA cudaSymbol cudaChannelFormatDesc cudaPitchedPtr syn keyword fortranTypeCUDA cudaExtent cudaMemcpy3DParms syn keyword fortranTypeCUDA cudaFuncCachePreferNone cudaFuncCachePreferShared syn keyword fortranTypeCUDA cudaFuncCachePreferL1 cudaLimitStackSize syn keyword fortranTypeCUDA cudaLimitPrintfSize cudaLimitMallocHeapSize syn keyword fortranTypeCUDA cudaSharedMemBankSizeDefault cudaSharedMemBankSizeFourByte cudaSharedMemBankSizeEightByte syn keyword fortranTypeCUDA cudaEventDefault cudaEventBlockingSync cudaEventDisableTiming syn keyword fortranTypeCUDA cudaMemcpyHostToDevice cudaMemcpyDeviceToHost syn keyword fortranTypeCUDA cudaMemcpyDeviceToDevice syn keyword fortranTypeCUDA cudaErrorNotReady cudaSuccess cudaErrorInvalidValue syn keyword fortranTypeCUDA c_devptr syn match fortranStringCUDA "blockidx%[xyz]" syn match fortranStringCUDA "blockdim%[xyz]" syn match fortranStringCUDA "griddim%[xyz]" syn match fortranStringCUDA "threadidx%[xyz]" syn keyword fortranIntrinsicCUDA warpsize syncthreads syncthreads_and syncthreads_count syncthreads_or threadfence threadfence_block threadfence_system gpu_time allthreads anythread ballot syn keyword fortranIntrinsicCUDA atomicadd atomicsub atomicmax atomicmin atomicand atomicor atomicxor atomicexch atomicinc atomicdec atomiccas sizeof __shfl __shfl_up __shfl_down __shfl_xor syn keyword fortranIntrinsicCUDA cudaChooseDevice cudaDeviceGetCacheConfig cudaDeviceGetLimit cudaDeviceGetSharedMemConfig cudaDeviceReset cudaDeviceSetCacheConfig cudaDeviceSetLimit cudaDeviceSetSharedMemConfig cudaDeviceSynchronize cudaGetDevice cudaGetDeviceCount cudaGetDeviceProperties cudaSetDevice cudaSetDeviceFlags cudaSetValidDevices syn keyword fortranIntrinsicCUDA cudaThreadExit cudaThreadSynchronize cudaGetLastError cudaGetErrorString cudaPeekAtLastError cudaStreamCreate cudaStreamDestroy cudaStreamQuery cudaStreamSynchronize cudaStreamWaitEvent cudaEventCreate cudaEventCreateWithFlags cudaEventDestroy cudaEventElapsedTime cudaEventQuery cudaEventRecord cudaEventSynchronize syn keyword fortranIntrinsicCUDA cudaFuncGetAttributes cudaFuncSetCacheConfig cudaFuncSetSharedMemConfig cudaSetDoubleForDevice cudaSetDoubleForHost cudaFree cudaFreeArray cudaFreeHost cudaGetSymbolAddress cudaGetSymbolSize syn keyword fortranIntrinsicCUDA cudaHostAlloc cudaHostGetDevicePointer cudaHostGetFlags cudaHostRegister cudaHostUnregister cudaMalloc cudaMallocArray cudaMallocHost cudaMallocPitch cudaMalloc3D cudaMalloc3DArray syn keyword fortranIntrinsicCUDA cudaMemcpy cudaMemcpyArraytoArray cudaMemcpyAsync cudaMemcpyFromArray cudaMemcpyFromSymbol cudaMemcpyFromSymbolAsync cudaMemcpyPeer cudaMemcpyPeerAsync cudaMemcpyToArray cudaMemcpyToSymbol cudaMemcpyToSymbolAsync cudaMemcpy2D cudaMemcpy2DArrayToArray cudaMemcpy2DAsync cudaMemcpy2DFromArray cudaMemcpy2DToArray cudaMemcpy3D cudaMemcpy3DAsync syn keyword fortranIntrinsicCUDA cudaMemGetInfo cudaMemset cudaMemset2D cudaMemset3D cudaDeviceCanAccessPeer cudaDeviceDisablePeerAccess cudaDeviceEnablePeerAccess cudaPointerGetAttributes cudaDriverGetVersion cudaRuntimeGetVersion endif syn region none matchgroup=fortranType start="<<<" end=">>>" contains=ALLBUT,none syn cluster fortranCommentGroup contains=fortranTodo if (b:fortran_fixed_source == 1) if !exists("fortran_have_tabs") if exists("fortran_extended_line_length") " Vendor extensions allow lines with a text width of 132 syn match fortranSerialNumber excludenl "^.\{133,}$"lc=132 else " Standard requires fixed format to have a text width of 72, " but all current compilers use 80 instead syn match fortranSerialNumber excludenl "^.\{81,}$"lc=80 endif "Flag left margin errors syn match fortranLabelError "^.\{-,4}[^0-9 ]" contains=fortranTab syn match fortranLabelError "^.\{4}\d\S" endif syn match fortranComment excludenl "^[!c*].*$" contains=@fortranCommentGroup,@spell syn match fortranLeftMargin transparent "^ \{5}" syn match fortranContinueMark display "^.\{5}\S"lc=5 else syn match fortranContinueMark display "&" endif syn match fortranComment excludenl "!.*$" contains=@fortranCommentGroup,@spell syn match fortranOpenMP excludenl "^\s*!\$\(OMP\)\=&\=\s.*$" syn match fortranEndStatement display ";" "cpp is often used with Fortran syn match cPreProc "^\s*#\s*\(define\|ifdef\)\>.*" syn match cPreProc "^\s*#\s*\(elif\|if\)\>.*" syn match cPreProc "^\s*#\s*\(ifndef\|undef\)\>.*" syn match cPreCondit "^\s*#\s*\(else\|endif\)\>.*" syn region cIncluded contained start=+"[^("]+ skip=+\\\\\|\\"+ end=+"+ contains=fortranLeftMargin,fortranContinueMark,fortranSerialNumber "syn region cIncluded contained start=+"[^("]+ skip=+\\\\\|\\"+ end=+"+ syn match cIncluded contained "<[^>]*>" syn match cInclude "^\s*#\s*include\>\s*["<]" contains=cIncluded "Synchronising limits assume that comment and continuation lines are not mixed if exists("fortran_fold") syn sync fromstart elseif (b:fortran_fixed_source == 0) syn sync linecont "&" minlines=30 else syn sync minlines=30 endif if exists("fortran_fold") if (b:fortran_fixed_source == 1) syn region fortranProgram transparent fold keepend start="^\s*program\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\\)\=\|$\)" contains=ALLBUT,fortranModule 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="\\)\=\|$\)" contains=ALLBUT,fortranProgram,fortranModule syn region fortranModule transparent fold keepend start="^\s*module\s\+\(procedure\)\@!\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\\)\=\|$\)" contains=ALLBUT,fortranProgram 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="\\)\=\)" contains=ALLBUT,fortranProgram,fortranModule 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="\\)\=\)" contains=ALLBUT,fortranProgram,fortranModule syn region fortranBlockData transparent fold keepend start="\