" Vim syntax file
" Language: Fortran95 (and Fortran90, Fortran77, F and elf90)
" Version: 0.86
" URL: http://www.unb.ca/chem/ajit/syntax/fortran.vim
" Last Change: 2003 Mar. 12
" Maintainer: Ajit J. Thakkar (ajit AT unb.ca);
" Usage: Do :help fortran-syntax from Vim
" Credits:
" Version 0.1 was based on the fortran 77 syntax file by Mario Eusebio and
" Preben Guldberg. Useful suggestions were made by: Andrej Panjkov,
" Bram Moolenaar, Thomas Olsen, Michael Sternberg, Christian Reile,
" Walter Dieudonné, Alexander Wagner, Roman Bertle, Charles Rendleman,
" and Andrew Griffiths. For instructions on use, do :help fortran from vim
" For version 5.x: Clear all syntax items
" For version 6.x: Quit if a syntax file is already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" let b:fortran_dialect = fortran_dialect if set correctly by user
if exists("fortran_dialect")
if fortran_dialect =~ '\<\(f\(9[05]\|77\)\|elf\|F\)\>'
let b:fortran_dialect = matchstr(fortran_dialect,'\<\(f\(9[05]\|77\)\|elf\|F\)\>')
else
echohl WarningMsg | echo "Unknown value of fortran_dialect" | echohl None
let b:fortran_dialect = "unknown"
endif
else
let b:fortran_dialect = "unknown"
endif
" fortran_dialect not set or set incorrectly by user,
if b:fortran_dialect == "unknown"
" set b:fortran_dialect from directive in first three lines of file
let b:fortran_retype = getline(1)." ".getline(2)." ".getline(3)
if b:fortran_retype =~ '\'
let b:fortran_dialect = "F"
elseif b:fortran_retype =~ '\'
let b:fortran_dialect = "elf"
elseif b:fortran_retype =~ '\'
let b:fortran_dialect = "f90"
elseif b:fortran_retype =~ '\'
let b:fortran_dialect = "f95"
elseif b:fortran_retype =~ '\'
let b:fortran_dialect = "f77"
else
" no directive found, so assume f95
let b:fortran_dialect = "f95"
endif
unlet b:fortran_retype
endif
" Choose between fixed and free source form if this hasn't been done yet
if !exists("b:fortran_fixed_source")
if b:fortran_dialect == "elf" || b:fortran_dialect == "F"
" elf and F require free source form
let b:fortran_fixed_source = 0
elseif b:fortran_dialect == "f77"
" f77 requires fixed source form
let b:fortran_fixed_source = 1
elseif exists("fortran_free_source")
" User guarantees free source form for all f90 and f95 files
let b:fortran_fixed_source = 0
elseif exists("fortran_fixed_source")
" User guarantees fixed source form for all f90 and f95 files
let b:fortran_fixed_source = 1
else
" f90 and f95 allow both fixed and free source form.
" Assume fixed source form unless signs of free source form
" are detected in the first five columns of the first b: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 b:lmax = 25
if ( b:lmax > line("$") )
let b:lmax = line("$")
endif
let b:fortran_fixed_source = 1
let b:ln=1
while b:ln <= b:lmax
let b:test = strpart(getline(b:ln),0,5)
if b:test[0] !~ '[Cc*!#]' && b:test !~ '^ \+[!#]' && b:test =~ '[^ 0-9\t]'
let b:fortran_fixed_source = 0
break
endif
let b:ln = b:ln + 1
endwhile
unlet b:lmax b:ln b:test
endif
endif
syn case ignore
if b:fortran_dialect == "f77"
syn match fortranIdentifier "\<\a\(\a\|\d\)*\>" contains=fortranSerialNumber
else
syn match fortran90Identifier "\<\a\w*\>" contains=fortranSerialNumber
if version >= 600
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
if exists("fortran_more_precise")
syn match fortranConstructName "\(\"
syn keyword fortranType character complex integer
syn keyword fortranType intrinsic
syn match fortranType "\"
syn keyword fortranStructure dimension
syn keyword fortranStorageClass parameter save
syn match fortranUnitHeader "\"
syn keyword fortranCall call
syn match fortranUnitHeader "\"
syn match fortranUnitHeader "\"
syn keyword fortranStatement return stop
syn keyword fortranConditional else then
syn match fortranConditional "\"
syn match fortranRepeat "\"
syn keyword fortranTodo contained todo fixme
"Catch errors caused by too many right parentheses
syn region fortranParen transparent start="(" end=")" contains=ALLBUT,fortranParenError,@fortranCommentGroup,cIncluded
syn match fortranParenError ")"
syn match fortranOperator "\.\s*n\=eqv\s*\."
syn match fortranOperator "\.\s*\(and\|or\|not\)\s*\."
syn match fortranOperator "\(+\|-\|/\|\*\)"
syn match fortranBoolean "\.\s*\(true\|false\)\s*\."
syn keyword fortranReadWrite backspace close inquire open rewind endfile
syn keyword fortranReadWrite read write print
"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
syn keyword fortranIO unit file iostat access blank fmt form
syn keyword fortranIO recl status exist opened number named name
syn keyword fortranIO sequential direct rec
syn keyword fortranIO formatted unformatted nextrec
syn keyword fortran66Intrinsic cabs ccos cexp clog csin csqrt
syn keyword fortran66Intrinsic dacos dasin datan datan2 dcos dcosh
syn keyword fortran66Intrinsic ddim dexp dint dlog dlog10 dmod dabs
syn keyword fortran66Intrinsic dnint dsign dsin dsinh dsqrt dtan
syn keyword fortran66Intrinsic dtanh iabs idim idnint isign idint ifix
syn keyword fortran66Intrinsic amax0 amax1 dmax1 max0 max1
syn keyword fortran66Intrinsic amin0 amin1 dmin1 min0 min1
syn keyword fortran66Intrinsic amod float sngl alog alog10
" Intrinsics provided by some vendors
syn keyword fortranExtraIntrinsic cdabs cdcos cdexp cdlog cdsin cdsqrt
syn keyword fortranExtraIntrinsic cqabs cqcos cqexp cqlog cqsin cqsqrt
syn keyword fortranExtraIntrinsic qacos qasin qatan qatan2 qcos qcosh
syn keyword fortranExtraIntrinsic qdim qexp iqint qlog qlog10 qmod qabs
syn keyword fortranExtraIntrinsic qnint qsign qsin qsinh qsqrt qtan
syn keyword fortranExtraIntrinsic qtanh qmax1 qmin1
syn keyword fortranExtraIntrinsic dimag qimag dcmplx qcmplx dconjg qconjg
syn keyword fortranExtraIntrinsic gamma dgamma qgamma algama dlgama qlgama
syn keyword fortranExtraIntrinsic erf derf qerf erfc derfc qerfc
syn keyword fortranExtraIntrinsic dfloat
syn keyword fortran77Intrinsic abs acos aimag aint anint asin atan atan2
syn keyword fortran77Intrinsic cos sin tan sinh cosh tanh exp log log10
syn keyword fortran77Intrinsic sign sqrt int cmplx nint min max conjg
syn keyword fortran77Intrinsic char ichar index
syn match fortran77Intrinsic "\"
syn match fortran90Intrinsic "\"
"Numbers of various sorts
" Integers
syn match fortranNumber display "\<\d\+\(_\a\w*\)\=\>"
" floating point number, without a decimal point
syn match fortranFloatNoDec display "\<\d\+[deq][-+]\=\d\+\(_\a\w*\)\=\>"
" floating point number, starting with a decimal point
syn match fortranFloatIniDec display "\.\d\+\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
" floating point number, no digits after decimal
syn match fortranFloatEndDec display "\<\d\+\.\([deq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
" floating point number, D or Q exponents
syn match fortranFloatDExp display "\<\d\+\.\d\+\([dq][-+]\=\d\+\)\=\(_\a\w*\)\=\>"
" floating point number
syn match fortranFloat display "\<\d\+\.\d\+\(e[-+]\=\d\+\)\=\(_\a\w*\)\=\>"
" 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
if version >= 600 && exists("fortran_more_precise")
" Numbers as targets
syn match fortranTarget display "\(\"
syn match fortranTarget display "\(\"
syn match fortranTarget display "\(\"
endif
syn keyword fortranTypeEx external
syn keyword fortranIOEx format
syn keyword fortranStatementEx continue
syn match fortranStatementEx "\"
syn region fortranStringEx start=+'+ end=+'+ contains=fortranContinueMark,fortranLeftMargin,fortranSerialNumber
syn keyword fortran77IntrinsicEx dim lge lgt lle llt mod
syn keyword fortranStatementOb assign pause to
if b:fortran_dialect != "f77"
syn keyword fortranType type none
syn keyword fortranStructure private public intent optional
syn keyword fortranStructure pointer target allocatable
syn keyword fortranStorageClass in out
syn match fortranStorageClass "\"
syn keyword fortranUnitHeader use only contains
syn keyword fortranUnitHeader result operator assignment
syn match fortranUnitHeader "\"
syn match fortranUnitHeader "\"
syn keyword fortranStatement allocate deallocate nullify cycle exit
syn match fortranConditional "\