" Vim syntax file
" Language:	Fortran
" Maintainer:	Mario Eusebio <bio@dq.fct.unl.pt>
" Last change:	1997 April 28

" Remove any old syntax stuff hanging around
syntax clear

syntax case ignore

syntax keyword fortranStatement		return continue 
syntax keyword fortranLabel		go to goto 
syntax keyword fortranConditional	if else elseif 
syntax keyword fortranConditional	endif then 
syntax keyword fortranRepeat		do 

syntax keyword fortranTodo contained	TODO

" This is valid with Gnu Fortran
"syntax match   fortranSpecial contained "\\[0-9][0-9][0-9]\|\\."
"syntax region  fortranString	start=+"+  skip=+\\\\\|\\"+  end=+"+  contains fortranSpecial
"syntax region  fortranString	start=+'+  skip=+\\\\\|\\"+  end=+'+  contains fortranSpecial

syntax region  fortranString		start=+"+  end=+"+
syntax region  fortranString		start=+'+  end=+'+
syntax region  fortranFormatString	start=+'(+  end=+)'+

"syntax match  fortranIdentifier	"\<[a-zA-Z_][a-zA-Z0-9_]*\>"

"syntax match  fortranDelimiter	"[()]"

" Standard Fortran 77 accepts any character other than blank
" in the 6th column to mark a continuation line.
"syntax match  fortranContinueError	"^\ \ \ \ \ [`~@#%^&()\-_=[{\]};:'",<.>/?].*$"

syntax match  fortranNoLabelNumber	"^[0-9][0-9][0-9][0-9][0-9][^ \t].*$"
syntax match  fortranNoLabelNumber	"^\ [0-9][0-9][0-9][0-9][^ \t].*$"
syntax match  fortranNoLabelNumber	"^\ \ [0-9][0-9][0-9][^ \t].*$"
syntax match  fortranNoLabelNumber	"^\ \ \ [0-9][0-9][^ \t].*$"
syntax match  fortranNoLabelNumber	"^\ \ \ \ [0-9][^ \t].*$"

syntax match  fortranLabelNumber	"^[0-9]\=[0-9]\=[0-9]\=[0-9]\=[0-9]\>"
syntax match  fortranLabelNumber	"^\ [0-9]\=[0-9]\=[0-9]\=[0-9]\>"
syntax match  fortranLabelNumber	"^\ \ [0-9]\=[0-9]\=[0-9]\>"
syntax match  fortranLabelNumber	"^\ \ \ [0-9]\=[0-9]\>"
syntax match  fortranLabelNumber	"^\ \ \ \ [0-9]\>"

" I don't like fortranPoint* form of numbers
syntax match  fortranDoubleNumber	"-\=\<[0-9]\+\.[0-9]\+[Dd]-\=[0-9]\+\>"
"syntax match  fortranPointDoubleNumber	"-\=\<[0-9]\+\.[Dd]-\=[0-9]\+\>"
"syntax match  fortranPointDoubleNumber	"-\=\.[0-9]\+[Dd]-\=[0-9]\+\>"
syntax match  fortranRealNumber		"-\=\<[0-9]\+\.[0-9]\+[eE]-\=[0-9]\+\>"
"syntax match  fortranPointRealNumber	"-\=\<[0-9]\+\.[eE]-\=[0-9]\+\>"
"syntax match  fortranPointRealNumber	"-\=\.[0-9]\+[eE]-\=[0-9]\+\>"
syntax match  fortranRealNumber		"-\=\<[0-9]\+\.[0-9]\+\>"
"syntax match  fortranPointRealNumber	"-\=\<[0-9]\+\."
"syntax match  fortranPointRealNumber	"-\=\.[0-9]\+\>"
syntax match  fortranNumber		"-\=\<[0-9]\+\>"

syntax match  fortranComment		"^[cC*].*$" contains fortranTodo
syntax match  fortranComment		"!.*$" contains fortranTodo

"syntax match fortranppPreCondit	"^#define\>"
"syntax match fortranppPreCondit	"^#include\>"

" any character other than a c in the first column
" would be an error
" does not work with keywords 
syntax match  fortranCommentError	"^[^\ ^0-9^\t].*$"
syntax match  fortranCommentError	"^\ [^\ ^0-9^\t].*$"
syntax match  fortranCommentError	"^\ \ [^\ ^0-9^\t].*$"
syntax match  fortranCommentError	"^\ \ \ [^\ ^0-9^\t].*$"
syntax match  fortranCommentError	"^\ \ \ \ [^\ ^0-9^\t].*$"

"syntax match  fortranCommentError	"^[^!]\{73\}.*$"

syntax match  fortranContinueLine	"^\ \ \ \ \ [^\t^\ ]"

" If you don't like initial tabs in fortran
"syntax match fortranShowIniTab "^\t.*$"
" If you don't like tabs at all
"syntax match fortranShowTab "\t"

syntax match fortranOperator		"\.and\."
syntax match fortranOperator		"\.eq\."
syntax match fortranOperator		"\.eqv\."
syntax match fortranOperator		"\.ge\."
syntax match fortranOperator		"\.gt\."
syntax match fortranOperator		"\.le\."
syntax match fortranOperator		"\.lt\."
syntax match fortranOperator		"\.ne\."
syntax match fortranOperator		"\.neqv\."
syntax match fortranOperator		"\.not\."
syntax match fortranOperator		"\.or\."

syntax match fortranLogicalConstant	"\.true\."
syntax match fortranLogicalConstant	"\.false\."

syntax keyword fortranType		implicit
syntax keyword fortranType		integer real real*8
syntax keyword fortranType		double precision complex 
syntax keyword fortranType		character logical

syntax keyword fortranStructure		parameter 
syntax keyword fortranStructure		common equivalence dimension 
syntax keyword fortranStructure		external intrinsic save


syntax keyword fortranUnitHeader	program subroutine function
syntax keyword fortranUnitHeader	data end call

syntax keyword fortranReadWrite		read write print inquire
syntax keyword fortranReadWrite		open close rewind backspace

syntax keyword fortranFormat		format unit fmt status file
syntax keyword fortranFormat		err form access iostat rec
syntax keyword fortranFormat		recl blank

syntax keyword fortranStopPause		stop pause 
syntax keyword fortranImplicit		abs acos aint atan asin cos 
syntax keyword fortranImplicit		cosh aimag anint atan2 
syntax keyword fortranImplicit		char cmplx conjg dble 
syntax keyword fortranImplicit		dim dprod exp ichar index 
syntax keyword fortranImplicit		int len lge lgt lle llt 
syntax keyword fortranImplicit		log log10 max min mod nint
syntax keyword fortranImplicit		sin sinh sign sqrt tan tanh

syntax keyword fortranSpecific		iabs dabs cabs dacos dint
syntax keyword fortranSpecific		dnint dasin datan datan2
syntax keyword fortranSpecific		dcos ccos dcosh idim ddim dexp
syntax keyword fortranSpecific		cexp dlog clog dlog10 dmod
syntax keyword fortranSpecific		idnint isign dsign dsin csin
syntax keyword fortranSpecific		dsinh dsqrt csqrt dtan dtanh

" This syntax highlighting file support Fortran 77 by default 
"syntax keyword fortranExtended  allocate assign block case contains
"syntax keyword fortranExtended  cycle deallocate default elsewhere
"syntax keyword fortranExtended  enddo endfile endwhile entry
"syntax keyword fortranExtended  equivalence exit interface module
"syntax keyword fortranExtended  nullify only operator procedure
"syntax keyword fortranExtended  recursive select use where while
"syntax keyword fortranExtended  allocatable in include inout intent
"syntax keyword fortranExtended  kind namelist none optional out
"syntax keyword fortranExtended  pointer private public result
"syntax keyword fortranExtended  sequence target type achar adjustl
"syntax keyword fortranExtended  adjustr all allocated any bit_size
"syntax keyword fortranExtended  break btest carg ceiling conjg
"syntax keyword fortranExtended  count cshift date_and_time digits
"syntax keyword fortranExtended  dim dot_product dvchk eoshift
"syntax keyword fortranExtended  epsilon error exponent floor
"syntax keyword fortranExtended  flush fraction getcl huge iachar
"syntax keyword fortranExtended  iand ibclr ibits ibset ichar ieor
"syntax keyword fortranExtended  intrup invalop ior iostat_msg ishft
"syntax keyword fortranExtended  ishftc lbound len_trim matmul
"syntax keyword fortranExtended  maxexponent maxloc maxval merge
"syntax keyword fortranExtended  minexponent minloc minval modulo
"syntax keyword fortranExtended  mvbits nbreak ndperr ndpexc nearest
"syntax keyword fortranExtended  nint not offset ovefl pack precfill
"syntax keyword fortranExtended  present product prompt radix
"syntax keyword fortranExtended  random_number random_seed range
"syntax keyword fortranExtended  repeat reshape rrspacing scale
"syntax keyword fortranExtended  scan segment selected_int_kind
"syntax keyword fortranExtended  selected_real_kind set_exponent
"syntax keyword fortranExtended  shape signsize spacing spread sum
"syntax keyword fortranExtended  system system_clock timer tiny
"syntax keyword fortranExtended  transfer transpose trim ubound
"syntax keyword fortranExtended  undfl unpack val verify action
"syntax keyword fortranExtended  blank blocksize carriagecontrol
"syntax keyword fortranExtended  direct exist form formatted from
"syntax keyword fortranExtended  location name named nextrec number
"syntax keyword fortranExtended  opened recl recordtype sequential
"syntax keyword fortranExtended  stat unformatted

if !exists("did_fortran_syntax_inits")
  let did_fortran_syntax_inits = 1
  " The default methods for highlighting.  Can be overridden later

  highlight link fortranConditional	Conditional
  highlight link fortranRepeat		Repeat
  highlight link fortranStatement	Statement
  highlight link fortranStructure	fortranType
  highlight link fortranType		Type
  highlight link fortranContinueLine	Todo
  highlight link fortranLabel		Special
  highlight link fortranLabelNumber	Special
  highlight link fortranDoubleNumber	fortranNumber
  highlight link fortranRealNumber	Float
  highlight link fortranNumber		Number
  highlight link fortranNoLabelNumber	Error
  highlight link fortranCommentError	Error
  highlight link fortranFormatString	fortranString
  highlight link fortranString		String
  highlight link fortranOperator	Operator
  highlight link fortranLogicalConstant	Constant
  highlight link fortranComment		Comment
  highlight link fortranTodo		Todo
  highlight link fortranSpecific	fortranImplicit
  highlight link fortranStopPause	fortranImplicit
  highlight link fortranFormat		fortranImplicit
  highlight link fortranReadWrite	fortranImplicit
  highlight link fortranImplicit	Identifier
  highlight link fortranUnitHeader	preCondit

  " optional highlighting
  "highlight link fortranExtended		fortranImplicit
  "highlight link fortranppPreCondit		PreCondit
  "highlight link fortranContinueError		Error
  "highlight link fortranSpecial		Special
  "highlight link fortranPointRealNumber	fortranNumber
  "highlight link fortranPointDoubleNumber	fortranNumber
  "highlight link fortranShowIniTab		Error
  "highlight link fortranShowTab		Error
  "highlight link fortranDelimiter		Identifier

  "highlight link fortranIdentifier	Identifier
endif
