174d41f
" Vim syntax file
174d41f
" Language:    FORTH
174d41f
" Maintainer:  Christian V. J. Brüssow <cvjb@cvjb.de>
174d41f
" Last Change: Sa 09 Feb 2008 13:27:29 CET
174d41f
" Filenames:   *.fs,*.ft
174d41f
" URL:	       http://www.cvjb.de/comp/vim/forth.vim
174d41f
174d41f
" $Id$
174d41f
174d41f
" The list of keywords is incomplete, compared with the offical ANS
174d41f
" wordlist. If you use this language, please improve it, and send me
174d41f
" the patches.
174d41f
"
174d41f
" Before sending me patches, please download the newest version of this file
174d41f
" from http://www.cvjb.de/comp/vim/forth.vim or http://www.vim.org/ (search
174d41f
" for forth.vim).
174d41f
174d41f
" Many Thanks to...
174d41f
"
174d41f
" 2008-02-09:
174d41f
" Shawn K. Quinn <sjquinn at speakeasy dot net> send a big patch with
174d41f
" new words commonly used in Forth programs or defined by GNU Forth.
174d41f
"
174d41f
" 2007-07-11:
174d41f
" Benjamin Krill <ben at codiert dot org> send me a patch
174d41f
" to highlight space errors.
174d41f
" You can toggle this feature on through setting the
174d41f
" flag forth_space_errors in you vimrc. If you have switched it on,
174d41f
" you can turn off highlighting of trailing spaces in comments by
174d41f
" setting forth_no_trail_space_error in your vimrc. If you do not want
174d41f
" the highlighting of a tabulator following a space in comments, you
174d41f
" can turn this off by setting forth_no_tab_space_error.
174d41f
"
174d41f
" 2006-05-25:
174d41f
" Bill McCarthy <WJMc@...> and Ilya Sher <ilya-vim@...>
174d41f
" Who found a bug in the ccomment line in 2004!!!
174d41f
" I'm really very sorry, that it has taken two years to fix that
174d41f
" in the offical version of this file. Shame on me.
174d41f
" I think my face will be red the next ten years...
174d41f
"
174d41f
" 2006-05-21:
174d41f
" Thomas E. Vaughan <tevaugha at ball dot com> send me a patch
174d41f
" for the parenthesis comment word, so words with a trailing
174d41f
" parenthesis will not start the highlighting for such comments.
174d41f
" 
174d41f
" 2003-05-10:
174d41f
" Andrew Gaul <andrew at gaul.org> send me a patch for
174d41f
" forthOperators.
174d41f
"
174d41f
" 2003-04-03:
174d41f
" Ron Aaron <ron at ronware dot org> made updates for an
174d41f
" improved Win32Forth support.
174d41f
"
174d41f
" 2002-04-22:
174d41f
" Charles Shattuck <charley at forth dot org> helped me to settle up with the
174d41f
" binary and hex number highlighting.
174d41f
"
174d41f
" 2002-04-20:
174d41f
" Charles Shattuck <charley at forth dot org> send me some code for correctly
174d41f
" highlighting char and [char] followed by an opening paren. He also added
174d41f
" some words for operators, conditionals, and definitions; and added the
174d41f
" highlighting for s" and c".
174d41f
"
174d41f
" 2000-03-28:
174d41f
" John Providenza <john at probo dot com> made improvements for the
174d41f
" highlighting of strings, and added the code for highlighting hex numbers.
174d41f
"
174d41f
174d41f
174d41f
" For version 5.x: Clear all syntax items
174d41f
" For version 6.x: Quit when a syntax file was already loaded
174d41f
if version < 600
174d41f
    syntax clear
174d41f
elseif exists("b:current_syntax")
174d41f
    finish
174d41f
endif
174d41f
174d41f
" Synchronization method
174d41f
syn sync ccomment
174d41f
syn sync maxlines=200
174d41f
174d41f
" I use gforth, so I set this to case ignore
174d41f
syn case ignore
174d41f
174d41f
" Some special, non-FORTH keywords
174d41f
syn keyword forthTodo contained TODO FIXME XXX
174d41f
syn match forthTodo contained 'Copyright\(\s([Cc])\)\=\(\s[0-9]\{2,4}\)\='
174d41f
174d41f
" Characters allowed in keywords
174d41f
" I don't know if 128-255 are allowed in ANS-FORTH
174d41f
if version >= 600
174d41f
    setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
174d41f
else
174d41f
    set iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
174d41f
endif
174d41f
174d41f
" when wanted, highlight trailing white space
174d41f
if exists("forth_space_errors")
174d41f
    if !exists("forth_no_trail_space_error")
174d41f
        syn match forthSpaceError display excludenl "\s\+$"
174d41f
    endif
174d41f
    if !exists("forth_no_tab_space_error")
174d41f
        syn match forthSpaceError display " \+\t"me=e-1
174d41f
    endif
174d41f
endif
174d41f
174d41f
" Keywords
174d41f
174d41f
" basic mathematical and logical operators
174d41f
syn keyword forthOperators + - * / MOD /MOD NEGATE ABS MIN MAX
174d41f
syn keyword forthOperators AND OR XOR NOT LSHIFT RSHIFT INVERT 2* 2/ 1+
174d41f
syn keyword forthOperators 1- 2+ 2- 8* UNDER+
174d41f
syn keyword forthOperators M+ */ */MOD M* UM* M*/ UM/MOD FM/MOD SM/REM
174d41f
syn keyword forthOperators D+ D- DNEGATE DABS DMIN DMAX D2* D2/
174d41f
syn keyword forthOperators F+ F- F* F/ FNEGATE FABS FMAX FMIN FLOOR FROUND
174d41f
syn keyword forthOperators F** FSQRT FEXP FEXPM1 FLN FLNP1 FLOG FALOG FSIN
174d41f
syn keyword forthOperators FCOS FSINCOS FTAN FASIN FACOS FATAN FATAN2 FSINH
174d41f
syn keyword forthOperators FCOSH FTANH FASINH FACOSH FATANH F2* F2/ 1/F
174d41f
syn keyword forthOperators F~REL F~ABS F~
174d41f
syn keyword forthOperators 0< 0<= 0<> 0= 0> 0>= < <= <> = > >= U< U<=
174d41f
syn keyword forthOperators U> U>= D0< D0<= D0<> D0= D0> D0>= D< D<= D<>
174d41f
syn keyword forthOperators D= D> D>= DU< DU<= DU> DU>= WITHIN ?NEGATE
174d41f
syn keyword forthOperators ?DNEGATE 
174d41f
174d41f
" stack manipulations
174d41f
syn keyword forthStack DROP NIP DUP OVER TUCK SWAP ROT -ROT ?DUP PICK ROLL
174d41f
syn keyword forthStack 2DROP 2NIP 2DUP 2OVER 2TUCK 2SWAP 2ROT 2-ROT
174d41f
syn keyword forthStack 3DUP 4DUP 5DUP 3DROP 4DROP 5DROP 8DROP 4SWAP 4ROT
174d41f
syn keyword forthStack 4-ROT 4TUCK 8SWAP 8DUP
174d41f
syn keyword forthRStack >R R> R@ RDROP 2>R 2R> 2R@ 2RDROP
174d41f
syn keyword forthRstack 4>R 4R> 4R@ 4RDROP
174d41f
syn keyword forthFStack FDROP FNIP FDUP FOVER FTUCK FSWAP FROT
174d41f
174d41f
" stack pointer manipulations
174d41f
syn keyword forthSP SP@ SP! FP@ FP! RP@ RP! LP@ LP!
174d41f
174d41f
" address operations
174d41f
syn keyword forthMemory @ ! +! C@ C! 2@ 2! F@ F! SF@ SF! DF@ DF!
174d41f
syn keyword forthAdrArith CHARS CHAR+ CELLS CELL+ CELL ALIGN ALIGNED FLOATS
174d41f
syn keyword forthAdrArith FLOAT+ FLOAT FALIGN FALIGNED SFLOATS SFLOAT+
174d41f
syn keyword forthAdrArith SFALIGN SFALIGNED DFLOATS DFLOAT+ DFALIGN DFALIGNED
174d41f
syn keyword forthAdrArith MAXALIGN MAXALIGNED CFALIGN CFALIGNED
174d41f
syn keyword forthAdrArith ADDRESS-UNIT-BITS ALLOT ALLOCATE HERE
174d41f
syn keyword forthMemBlks MOVE ERASE CMOVE CMOVE> FILL BLANK
174d41f
174d41f
" conditionals
174d41f
syn keyword forthCond IF ELSE ENDIF THEN CASE OF ENDOF ENDCASE ?DUP-IF
174d41f
syn keyword forthCond ?DUP-0=-IF AHEAD CS-PICK CS-ROLL CATCH THROW WITHIN
174d41f
174d41f
" iterations
174d41f
syn keyword forthLoop BEGIN WHILE REPEAT UNTIL AGAIN
174d41f
syn keyword forthLoop ?DO LOOP I J K +DO U+DO -DO U-DO DO +LOOP -LOOP
174d41f
syn keyword forthLoop UNLOOP LEAVE ?LEAVE EXIT DONE FOR NEXT
174d41f
174d41f
" new words
174d41f
syn match forthClassDef '\<:class\s*[^ \t]\+\>'
174d41f
syn match forthObjectDef '\<:object\s*[^ \t]\+\>'
174d41f
syn match forthColonDef '\<:m\?\s*[^ \t]\+\>'
174d41f
syn keyword forthEndOfColonDef ; ;M ;m
174d41f
syn keyword forthEndOfClassDef ;class
174d41f
syn keyword forthEndOfObjectDef ;object
174d41f
syn keyword forthDefine CONSTANT 2CONSTANT FCONSTANT VARIABLE 2VARIABLE
174d41f
syn keyword forthDefine FVARIABLE CREATE USER VALUE TO DEFER IS DOES> IMMEDIATE
174d41f
syn keyword forthDefine COMPILE-ONLY COMPILE RESTRICT INTERPRET POSTPONE EXECUTE
174d41f
syn keyword forthDefine LITERAL CREATE-INTERPRET/COMPILE INTERPRETATION>
174d41f
syn keyword forthDefine <INTERPRETATION COMPILATION> 
174d41f
syn keyword forthDefine COMP' POSTPONE, FIND-NAME NAME>INT NAME?INT NAME>COMP
174d41f
syn keyword forthDefine NAME>STRING STATE C; CVARIABLE
174d41f
syn keyword forthDefine , 2, F, C, 
174d41f
syn match forthDefine "\[IFDEF]"
174d41f
syn match forthDefine "\[IFUNDEF]"
174d41f
syn match forthDefine "\[THEN]"
174d41f
syn match forthDefine "\[ENDIF]"
174d41f
syn match forthDefine "\[ELSE]"
174d41f
syn match forthDefine "\[?DO]"
174d41f
syn match forthDefine "\[DO]"
174d41f
syn match forthDefine "\[LOOP]"
174d41f
syn match forthDefine "\[+LOOP]"
174d41f
syn match forthDefine "\[NEXT]"
174d41f
syn match forthDefine "\[BEGIN]"
174d41f
syn match forthDefine "\[UNTIL]"
174d41f
syn match forthDefine "\[AGAIN]"
174d41f
syn match forthDefine "\[WHILE]"
174d41f
syn match forthDefine "\[REPEAT]"
174d41f
syn match forthDefine "\[COMP']"
174d41f
syn match forthDefine "'"
174d41f
syn match forthDefine '\<\[\>'
174d41f
syn match forthDefine "\[']"
174d41f
syn match forthDefine '\[COMPILE]'
174d41f
174d41f
" debugging
174d41f
syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE
174d41f
syn match forthDebug "\<\~\~\>"
174d41f
174d41f
" Assembler
174d41f
syn keyword forthAssembler ASSEMBLER CODE END-CODE ;CODE FLUSH-ICACHE C,
174d41f
174d41f
" basic character operations
174d41f
syn keyword forthCharOps (.) CHAR EXPECT FIND WORD TYPE -TRAILING EMIT KEY
174d41f
syn keyword forthCharOps KEY? TIB CR
174d41f
" recognize 'char (' or '[char] (' correctly, so it doesn't
174d41f
" highlight everything after the paren as a comment till a closing ')'
174d41f
syn match forthCharOps '\
174d41f
syn match forthCharOps '\<\[char\]\s\S\s'
174d41f
syn region forthCharOps start=+."\s+ skip=+\\"+ end=+"+
174d41f
174d41f
" char-number conversion
174d41f
syn keyword forthConversion <<# <# # #> #>> #S (NUMBER) (NUMBER?) CONVERT D>F 
174d41f
syn keyword forthConversion D>S DIGIT DPL F>D HLD HOLD NUMBER S>D SIGN >NUMBER
174d41f
syn keyword forthConversion F>S S>F
174d41f
174d41f
" interptreter, wordbook, compiler
174d41f
syn keyword forthForth (LOCAL) BYE COLD ABORT >BODY >NEXT >LINK CFA >VIEW HERE
174d41f
syn keyword forthForth PAD WORDS VIEW VIEW> N>LINK NAME> LINK> L>NAME FORGET
174d41f
syn keyword forthForth BODY> ASSERT( ASSERT0( ASSERT1( ASSERT2( ASSERT3( )
174d41f
syn region forthForth start=+ABORT"\s+ skip=+\\"+ end=+"+
174d41f
174d41f
" vocabularies
174d41f
syn keyword forthVocs ONLY FORTH ALSO ROOT SEAL VOCS ORDER CONTEXT #VOCS
174d41f
syn keyword forthVocs VOCABULARY DEFINITIONS
174d41f
174d41f
" File keywords
174d41f
syn keyword forthFileMode R/O R/W W/O BIN 
174d41f
syn keyword forthFileWords OPEN-FILE CREATE-FILE CLOSE-FILE DELETE-FILE
174d41f
syn keyword forthFileWords RENAME-FILE READ-FILE READ-LINE KEY-FILE
174d41f
syn keyword forthFileWords KEY?-FILE WRITE-FILE WRITE-LINE EMIT-FILE
174d41f
syn keyword forthFileWords FLUSH-FILE FILE-STATUS FILE-POSITION
174d41f
syn keyword forthFileWords REPOSITION-FILE FILE-SIZE RESIZE-FILE
174d41f
syn keyword forthFileWords SLURP-FILE SLURP-FID STDIN STDOUT STDERR
174d41f
syn keyword forthBlocks OPEN-BLOCKS USE LOAD --> BLOCK-OFFSET
174d41f
syn keyword forthBlocks GET-BLOCK-FID BLOCK-POSITION LIST SCR BLOCK
174d41f
syn keyword forthBlocks BUFER EMPTY-BUFFERS EMPTY-BUFFER UPDATE UPDATED?
174d41f
syn keyword forthBlocks SAVE-BUFFERS SAVE-BUFFER FLUSH THRU +LOAD +THRU
174d41f
syn keyword forthBlocks BLOCK-INCLUDED
174d41f
174d41f
" numbers
174d41f
syn keyword forthMath DECIMAL HEX BASE
174d41f
syn match forthInteger '\<-\=[0-9.]*[0-9.]\+\>'
174d41f
syn match forthInteger '\<&-\=[0-9.]*[0-9.]\+\>'
174d41f
" recognize hex and binary numbers, the '$' and '%' notation is for gforth
174d41f
syn match forthInteger '\<\$\x*\x\+\>' " *1* --- dont't mess
174d41f
syn match forthInteger '\<\x*\d\x*\>'  " *2* --- this order!
174d41f
syn match forthInteger '\<%[0-1]*[0-1]\+\>'
174d41f
syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe]\d\+\>'
174d41f
syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe][-+]\d\+\>'
174d41f
174d41f
" XXX If you find this overkill you can remove it. this has to come after the
174d41f
" highlighting for numbers otherwise it has no effect.
174d41f
syn region forthComment start='0 \[if\]' end='\[endif\]' end='\[then\]' contains=forthTodo
174d41f
174d41f
" Strings
174d41f
syn region forthString start=+\.*\"+ end=+"+ end=+$+
174d41f
" XXX
174d41f
syn region forthString start=+s\"+ end=+"+ end=+$+
174d41f
syn region forthString start=+c\"+ end=+"+ end=+$+
174d41f
174d41f
" Comments
174d41f
syn match forthComment '\\\s.*$' contains=forthTodo,forthSpaceError
174d41f
syn region forthComment start='\\S\s' end='.*' contains=forthTodo,forthSpaceError
174d41f
syn match forthComment '\.(\s[^)]*)' contains=forthTodo,forthSpaceError
174d41f
syn region forthComment start='\s(\s' skip='\\)' end=')' contains=forthTodo,forthSpaceError
174d41f
syn region forthComment start='/\*' end='\*/' contains=forthTodo,forthSpaceError
174d41f
174d41f
" Include files
174d41f
syn match forthInclude '^INCLUDE\s\+\k\+'
174d41f
syn match forthInclude '^require\s\+\k\+'
174d41f
syn match forthInclude '^fload\s\+'
174d41f
syn match forthInclude '^needs\s\+'
174d41f
174d41f
" Locals definitions
174d41f
syn region forthLocals start='{\s' start='{$' end='\s}' end='^}'
174d41f
syn match forthLocals '{ }' " otherwise, at least two spaces between
174d41f
syn region forthDeprecated start='locals|' end='|'
174d41f
174d41f
" Define the default highlighting.
174d41f
" For version 5.7 and earlier: only when not done already
174d41f
" For version 5.8 and later: only when an item doesn't have highlighting yet
174d41f
if version >= 508 || !exists("did_forth_syn_inits")
174d41f
    if version < 508
174d41f
	let did_forth_syn_inits = 1
174d41f
	command -nargs=+ HiLink hi link <args>
174d41f
    else
174d41f
	command -nargs=+ HiLink hi def link <args>
174d41f
    endif
174d41f
174d41f
    " The default methods for highlighting. Can be overriden later.
174d41f
    HiLink forthTodo Todo
174d41f
    HiLink forthOperators Operator
174d41f
    HiLink forthMath Number
174d41f
    HiLink forthInteger Number
174d41f
    HiLink forthFloat Float
174d41f
    HiLink forthStack Special
174d41f
    HiLink forthRstack Special
174d41f
    HiLink forthFStack Special
174d41f
    HiLink forthSP Special
174d41f
    HiLink forthMemory Function
174d41f
    HiLink forthAdrArith Function
174d41f
    HiLink forthMemBlks Function
174d41f
    HiLink forthCond Conditional
174d41f
    HiLink forthLoop Repeat
174d41f
    HiLink forthColonDef Define
174d41f
    HiLink forthEndOfColonDef Define
174d41f
    HiLink forthDefine Define
174d41f
    HiLink forthDebug Debug
174d41f
    HiLink forthAssembler Include
174d41f
    HiLink forthCharOps Character
174d41f
    HiLink forthConversion String
174d41f
    HiLink forthForth Statement
174d41f
    HiLink forthVocs Statement
174d41f
    HiLink forthString String
174d41f
    HiLink forthComment Comment
174d41f
    HiLink forthClassDef Define
174d41f
    HiLink forthEndOfClassDef Define
174d41f
    HiLink forthObjectDef Define
174d41f
    HiLink forthEndOfObjectDef Define
174d41f
    HiLink forthInclude Include
174d41f
    HiLink forthLocals Type " nothing else uses type and locals must stand out
174d41f
    HiLink forthDeprecated Error " if you must, change to Type
174d41f
    HiLink forthFileMode Function
174d41f
    HiLink forthFileWords Statement
174d41f
    HiLink forthBlocks Statement
174d41f
    HiLink forthSpaceError Error
174d41f
174d41f
    delcommand HiLink
174d41f
endif
174d41f
174d41f
let b:current_syntax = "forth"
174d41f
174d41f
" vim:ts=8:sw=4:nocindent:smartindent: