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