" Vim syntax file
" Language   : FORTH
" Maintainer : Charley Shattuck
" Last change: 2006-14-10

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
	syntax clear
elseif exists("b:current_syntax")
	finish
endif

" Synchronization method
" syn sync ccomment maxlines=500
syntax sync fromstart

syntax case ignore

" Characters allowed in keywords
if version >= 600
	setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
else
	set iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
endif

syntax keyword c18Compiler =pc /pc =a =b >stk >rtn org hex decimal here base ! @ \| node contained
syntax keyword c18Compiler 'north 'south 'east 'west 'rdlu 'rd-- '-dl- '--lu 'r--u contained
syntax keyword c18Compiler 'rdl- '-dlu 'r-lu 'rd-u 'r--- '-d-- '--l- '---u 'r-l- '-d-u contained
" syntax keyword c18Compiler {node node} contained

syntax keyword forthControl begin again if else then until while repeat contained
syntax keyword forthControl -if -while -until for next unext zif jump call -; contained

syntax keyword c18Compiler [1-9]+ contained
syn match forthInteger	"\<\%([\-0-9]\d*\%(_\d\+\)*\)\>" contained
syn match forthInteger	"\<$\x\+\%(_\x\+\)*\>" display

syntax region forthOutside start='^.*' end='%$' contains=forthComment,forthColon,forthWord,forthMacro,forthInteger,c18Compiler,forthControl

syntax region forthComment start=/\<(\>/ end=/)/ contained
syntax region forthComment start=/\<{\>/ end=/}/ contained
syntax region forthComment start=/\<0 \[if\]\>/ end=/\[then\]/ contained
syntax region forthComment start=/\<\[ 0 \] \[if\]\>/ end=/\[then\]/ contained
syntax match forthComment '\\\s.*$' contained
syntax match forthComment '\\$' contained

" syntax match forthColon '\<:\S*\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '^:\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<equ\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<fwd\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<+fwd\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<create\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<variable\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<constant\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthColon '\<declare\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained

syntax region forthMacro start=/^:t / skipempty end=/\S*/ nextgroup=forthMacroWord contained
syntax region forthMacro start=/^: / skipempty end=/\S*/ nextgroup=forthMacroWord contained

syntax region forthMacroWord start=/\s/ end=/h;\|;/ contained contains=forthComment,forthInteger,c18Compiler,forthControl
syntax region forthMacroWord start=/^/ end=/h;\|;/ contained contains=forthComment,forthInteger,c18Compiler,forthControl

syntax region forthWord start=/^\]/ end=/\[/ contained contains=forthComment,forthColon,forthInterpreted,forthChar,c18Compiler,forthInteger,forthControl

syntax region forthWord start=/\s\]/ end=/\[/ contained contains=forthComment,forthColon,forthInterpreted,forthChar,c18Compiler,forthInteger,forthControl
syntax region forthWord start=/machine/ end=/\[/ contained contains=forthComment,forthColon,forthInterpreted,forthChar,c18Compiler,forthInteger,forthControl
syntax region forthWord start=/{node/ end=/node}/ contained contains=forthComment,forthColon,forthInterpreted,forthChar,c18Compiler,forthInteger,forthControl

syntax region forthInterpreted start=/\[/ end=/\]/ contained contains=forthComment
syntax match forthChar '\<char\S*\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained
syntax match forthChar '\<include\S*\>\s*[^ \t]\+\>' nextgroup=forthWord skipwhite contained

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
" if version >= 508 || !exists("did_forth_syn_inits")
"	if version < 508
"		let did_forth_syn_inits = 1
"		command -nargs=+ HiLink hi link <args>
"	else
"		command -nargs=+ HiLink hi def link <args>
"	endif

highlight forthOutside ctermfg=Yellow guifg=Yellow
highlight forthWord ctermfg=Green guifg=Green
highlight forthColon ctermfg=Red guifg=Red
" highlight forthComment ctermfg=Blue guifg=DarkBlue
highlight forthComment ctermfg=LightGrey guifg=LightGrey
" highlight forthOutsideComment ctermfg=Blue guifg=DarkBlue
highlight forthInterpreted ctermfg=Yellow guifg=Yellow
highlight forthChar ctermfg=Yellow guifg=Yellow
highlight forthMacro ctermfg=Red guifg=Red
" highlight forthMacroWord ctermfg=Cyan guifg=Cyan
highlight forthMacroWord ctermfg=Green guifg=Green
highlight c18Compiler ctermfg=Yellow guifg=Yellow
highlight forthInteger ctermfg=Yellow guifg=Yellow
highlight forthControl ctermfg=Cyan guifg=Cyan

" The default methods for highlighting. Can be overriden later.
" Chosen more for default colors than for meaning.
"	HiLink forthOutsideComment forthComment
"	delcommand HiLink
" endif

let b:current_syntax = "forth"

" vim:ts=4:sw=4:nocindent:smartindent:
