" Vim syntax file
" Language: Fortran 2008 (and earlier versions: 2003, 95, 90, and 77)
" Version: 0.93
" Last Change: 2012 Jan. 18
" Maintainer: Ajit J. Thakkar (ajit AT unb.ca);
" Usage: For instructions, 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,
" Andrew Griffiths, Joe Krahn, and Hendrik Merx.
if exists("b:current_syntax")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
" Choose fortran_dialect using the priority:
" source file directive > buffer-local value > global value > default
" try using 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 = "f08"
elseif !exists("b:fortran_dialect")
if exists("g:fortran_dialect") && g:fortran_dialect =~# '\'
" try global variable
let b:fortran_dialect = g:fortran_dialect
else " nothing found, so use default
let b:fortran_dialect = "f08"
endif
endif
unlet! b:fortran_retype
" make sure buffer-local value is not invalid
if b:fortran_dialect !~# '\'
let b:fortran_dialect = "f08"
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 == "F"
" F requires free source form
let b:fortran_fixed_source = 0
elseif 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
else
" Modern fortran still allows 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
if exists("fortran_more_precise")
syn match fortranConstructName "\(\"
syn match fortranType "\"
syn match fortranType "\"
syn match fortranType "\"
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 fortranKeyword return stop
syn keyword fortranConditional else then
syn match fortranConditional "\"
syn match fortranConditionalOb "\"
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,@spell
syn match fortranParenError ")"
syn match fortranOperator "\.\s*n\=eqv\s*\."
syn match fortranOperator "\.\s*\(and\|or\|not\)\s*\."
syn match fortranOperator "\(+\|-\|/\|\*\)"
syn match fortranTypeOb "\"
syn match fortranIntrinsic "\"
"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*\)\=\>"
" 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 exists("fortran_more_precise")
" Numbers as targets
syn match fortranTarget display "\(\"
syn match fortranTarget display "\(\"
syn match fortranTarget display "\(\"
endif
syn keyword fortranTypeR external
syn keyword fortranIOR format
syn match fortranKeywordR "\"
syn match fortranKeyword "^\s*\d\+\s\+continue\>"
syn match fortranKeyword "\"
syn match fortranKeywordDel "\"
syn keyword fortranType 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 fortranKeyword allocate deallocate nullify cycle exit
syn match fortranConditional "\