1" Vim syntax file 2" Language: FORTH 3" Maintainer: Christian V. J. Br�ssow <[email protected]> 4" Last Change: Son 22 Jun 2003 20:42:55 CEST 5" Filenames: *.fs,*.ft 6" URL: http://www.cvjb.de/comp/vim/forth.vim 7 8" $Id$ 9 10" The list of keywords is incomplete, compared with the offical ANS 11" wordlist. If you use this language, please improve it, and send me 12" the patches. 13 14" Many Thanks to... 15" 16" 2003-05-10: 17" Andrew Gaul <andrew at gaul.org> send me a patch for 18" forthOperators. 19" 20" 2003-04-03: 21" Ron Aaron <ron at ronware.org> made updates for an 22" improved Win32Forth support. 23" 24" 2002-04-22: 25" Charles Shattuck <charley at forth.org> helped me to settle up with the 26" binary and hex number highlighting. 27" 28" 2002-04-20: 29" Charles Shattuck <charley at forth.org> send me some code for correctly 30" highlighting char and [char] followed by an opening paren. He also added 31" some words for operators, conditionals, and definitions; and added the 32" highlighting for s" and c". 33" 34" 2000-03-28: 35" John Providenza <john at probo.com> made improvements for the 36" highlighting of strings, and added the code for highlighting hex numbers. 37" 38 39 40" For version 5.x: Clear all syntax items 41" For version 6.x: Quit when a syntax file was already loaded 42if version < 600 43 syntax clear 44elseif exists("b:current_syntax") 45 finish 46endif 47 48" Synchronization method 49syn sync ccomment maxlines=200 50 51" I use gforth, so I set this to case ignore 52syn case ignore 53 54" Some special, non-FORTH keywords 55syn keyword forthTodo contained TODO FIXME XXX 56syn match forthTodo contained 'Copyright\(\s([Cc])\)\=\(\s[0-9]\{2,4}\)\=' 57 58" Characters allowed in keywords 59" I don't know if 128-255 are allowed in ANS-FORHT 60if version >= 600 61 setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255 62else 63 set iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255 64endif 65 66 67" Keywords 68 69" basic mathematical and logical operators 70syn keyword forthOperators + - * / MOD /MOD NEGATE ABS MIN MAX 71syn keyword forthOperators AND OR XOR NOT INVERT 2* 2/ 1+ 1- 2+ 2- 8* 72syn keyword forthOperators M+ */ */MOD M* UM* M*/ UM/MOD FM/MOD SM/REM 73syn keyword forthOperators D+ D- DNEGATE DABS DMIN DMAX 74syn keyword forthOperators F+ F- F* F/ FNEGATE FABS FMAX FMIN FLOOR FROUND 75syn keyword forthOperators F** FSQRT FEXP FEXPM1 FLN FLNP1 FLOG FALOG FSIN 76syn keyword forthOperators FCOS FSINCOS FTAN FASIN FACOS FATAN FATAN2 FSINH 77syn keyword forthOperators FCOSH FTANH FASINH FACOSH FATANH 78syn keyword forthOperators 0< 0<= 0<> 0= 0> 0>= < <= <> = > >= 79syn keyword forthOperators ?NEGATE ?DNEGATE 80 81" stack manipulations 82syn keyword forthStack DROP NIP DUP OVER TUCK SWAP ROT -ROT ?DUP PICK ROLL 83syn keyword forthStack 2DROP 2NIP 2DUP 2OVER 2TUCK 2SWAP 2ROT 84syn keyword forthStack 3DUP 4DUP 85syn keyword forthRStack >R R> R@ RDROP 2>R 2R> 2R@ 2RDROP 86syn keyword forthFStack FDROP FNIP FDUP FOVER FTUCK FSWAP FROT 87 88" stack pointer manipulations 89syn keyword forthSP SP@ SP! FP@ FP! RP@ RP! LP@ LP! 90 91" address operations 92syn keyword forthMemory @ ! +! C@ C! 2@ 2! F@ F! SF@ SF! DF@ DF! 93syn keyword forthAdrArith CHARS CHAR+ CELLS CELL+ CELL ALIGN ALIGNED FLOATS 94syn keyword forthAdrArith FLOAT+ FLOAT FALIGN FALIGNED SFLOATS SFLOAT+ 95syn keyword forthAdrArith SFALIGN SFALIGNED DFLOATS DFLOAT+ DFALIGN DFALIGNED 96syn keyword forthAdrArith MAXALIGN MAXALIGNED CFALIGN CFALIGNED 97syn keyword forthAdrArith ADDRESS-UNIT-BITS ALLOT ALLOCATE HERE 98syn keyword forthMemBlks MOVE ERASE CMOVE CMOVE> FILL BLANK 99 100" conditionals 101syn keyword forthCond IF ELSE ENDIF THEN CASE OF ENDOF ENDCASE ?DUP-IF 102syn keyword forthCond ?DUP-0=-IF AHEAD CS-PICK CS-ROLL CATCH THROW WITHIN 103 104" iterations 105syn keyword forthLoop BEGIN WHILE REPEAT UNTIL AGAIN 106syn keyword forthLoop ?DO LOOP I J K +DO U+DO -DO U-DO DO +LOOP -LOOP 107syn keyword forthLoop UNLOOP LEAVE ?LEAVE EXIT DONE FOR NEXT 108 109" new words 110syn match forthColonDef '\<:m\?\s*[^ \t]\+\>' 111syn keyword forthEndOfColonDef ; ;M ;m 112syn keyword forthDefine CONSTANT 2CONSTANT FCONSTANT VARIABLE 2VARIABLE CREATE 113syn keyword forthDefine USER VALUE TO DEFER IS DOES> IMMEDIATE COMPILE-ONLY 114syn keyword forthDefine COMPILE RESTRICT INTERPRET POSTPONE EXECUTE LITERAL 115syn keyword forthDefine CREATE-INTERPRET/COMPILE INTERPRETATION> <INTERPRETATION 116syn keyword forthDefine COMPILATION> <COMPILATION ] LASTXT COMP' POSTPONE, 117syn keyword forthDefine FIND-NAME NAME>INT NAME?INT NAME>COMP NAME>STRING STATE 118syn keyword forthDefine C; CVARIABLE 119syn match forthDefine "\[COMP']" 120syn match forthDefine "'" 121syn match forthDefine '\<\[\>' 122syn match forthDefine "\[']" 123syn match forthDefine '\[COMPILE]' 124syn match forthClassDef '\<:class\s*[^ \t]\+\>' 125syn match forthObjectDef '\<:object\s*[^ \t]\+\>' 126syn keyword forthEndOfClassDef ';class' 127syn keyword forthEndOfObjectDef ';object' 128 129" debugging 130syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE 131syn match forthDebug "\<\~\~\>" 132 133" Assembler 134syn keyword forthAssembler ASSEMBLER CODE END-CODE ;CODE FLUSH-ICACHE C, 135 136" basic character operations 137syn keyword forthCharOps (.) CHAR EXPECT FIND WORD TYPE -TRAILING EMIT KEY 138syn keyword forthCharOps KEY? TIB CR 139" recognize 'char (' or '[char] (' correctly, so it doesn't 140" highlight everything after the paren as a comment till a closing ')' 141syn match forthCharOps '\<char\s\S\s' 142syn match forthCharOps '\<\[char\]\s\S\s' 143syn region forthCharOps start=+."\s+ skip=+\\"+ end=+"+ 144 145" char-number conversion 146syn keyword forthConversion <# # #> #S (NUMBER) (NUMBER?) CONVERT D>F D>S DIGIT 147syn keyword forthConversion DPL F>D HLD HOLD NUMBER S>D SIGN >NUMBER 148 149" interptreter, wordbook, compiler 150syn keyword forthForth (LOCAL) BYE COLD ABORT >BODY >NEXT >LINK CFA >VIEW HERE 151syn keyword forthForth PAD WORDS VIEW VIEW> N>LINK NAME> LINK> L>NAME FORGET 152syn keyword forthForth BODY> 153syn region forthForth start=+ABORT"\s+ skip=+\\"+ end=+"+ 154 155" vocabularies 156syn keyword forthVocs ONLY FORTH ALSO ROOT SEAL VOCS ORDER CONTEXT #VOCS 157syn keyword forthVocs VOCABULARY DEFINITIONS 158 159" numbers 160syn keyword forthMath DECIMAL HEX BASE 161syn match forthInteger '\<-\=[0-9.]*[0-9.]\+\>' 162" recognize hex and binary numbers, the '$' and '%' notation is for gforth 163syn match forthInteger '\<\$\x*\x\+\>' " *1* --- dont't mess 164syn match forthInteger '\<\x*\d\x*\>' " *2* --- this order! 165syn match forthInteger '\<%[0-1]*[0-1]\+\>' 166syn match forthFloat '\<-\=\d*[.]\=\d\+[Ee]\d\+\>' 167 168" Strings 169syn region forthString start=+\.*\"+ end=+"+ end=+$+ 170" XXX 171syn region forthString start=+s\"+ end=+"+ end=+$+ 172syn region forthString start=+c\"+ end=+"+ end=+$+ 173 174" Comments 175syn match forthComment '\\\s.*$' contains=forthTodo 176syn region forthComment start='\\S\s' end='.*' contains=forthTodo 177syn match forthComment '\.(\s[^)]*)' contains=forthTodo 178syn region forthComment start='(\s' skip='\\)' end=')' contains=forthTodo 179syn region forthComment start='/\*' end='\*/' contains=forthTodo 180"syn match forthComment '(\s[^\-]*\-\-[^\-]*)' contains=forthTodo 181 182" Include files 183syn match forthInclude '^INCLUDE\s\+\k\+' 184syn match forthInclude '^fload\s\+' 185syn match forthInclude '^needs\s\+' 186 187" Define the default highlighting. 188" For version 5.7 and earlier: only when not done already 189" For version 5.8 and later: only when an item doesn't have highlighting yet 190if version >= 508 || !exists("did_forth_syn_inits") 191 if version < 508 192 let did_forth_syn_inits = 1 193 command -nargs=+ HiLink hi link <args> 194 else 195 command -nargs=+ HiLink hi def link <args> 196 endif 197 198 " The default methods for highlighting. Can be overriden later. 199 HiLink forthTodo Todo 200 HiLink forthOperators Operator 201 HiLink forthMath Number 202 HiLink forthInteger Number 203 HiLink forthFloat Float 204 HiLink forthStack Special 205 HiLink forthRstack Special 206 HiLink forthFStack Special 207 HiLink forthSP Special 208 HiLink forthMemory Function 209 HiLink forthAdrArith Function 210 HiLink forthMemBlks Function 211 HiLink forthCond Conditional 212 HiLink forthLoop Repeat 213 HiLink forthColonDef Define 214 HiLink forthEndOfColonDef Define 215 HiLink forthDefine Define 216 HiLink forthDebug Debug 217 HiLink forthAssembler Include 218 HiLink forthCharOps Character 219 HiLink forthConversion String 220 HiLink forthForth Statement 221 HiLink forthVocs Statement 222 HiLink forthString String 223 HiLink forthComment Comment 224 HiLink forthClassDef Define 225 HiLink forthEndOfClassDef Define 226 HiLink forthObjectDef Define 227 HiLink forthEndOfObjectDef Define 228 HiLink forthInclude Include 229 230 delcommand HiLink 231endif 232 233let b:current_syntax = "forth" 234 235" vim:ts=8:sw=4:nocindent:smartindent: 236