1" Vim syntax file 2" Language: FORTH 3" Current Maintainer: Johan Kotlinski <[email protected]> 4" Previous Maintainer: Christian V. J. Br�ssow <[email protected]> 5" Last Change: 2018-03-29 6" Filenames: *.fs,*.ft 7" URL: https://github.com/jkotlinski/forth.vim 8 9" quit when a syntax file was already loaded 10if exists("b:current_syntax") 11 finish 12endif 13 14let s:cpo_save = &cpo 15set cpo&vim 16 17" Synchronization method 18syn sync ccomment 19syn sync maxlines=200 20 21" I use gforth, so I set this to case ignore 22syn case ignore 23 24" Some special, non-FORTH keywords 25syn keyword forthTodo contained TODO FIXME XXX 26syn match forthTodo contained 'Copyright\(\s([Cc])\)\=\(\s[0-9]\{2,4}\)\=' 27 28" Characters allowed in keywords 29" I don't know if 128-255 are allowed in ANS-FORTH 30setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255 31 32" when wanted, highlight trailing white space 33if exists("forth_space_errors") 34 if !exists("forth_no_trail_space_error") 35 syn match forthSpaceError display excludenl "\s\+$" 36 endif 37 if !exists("forth_no_tab_space_error") 38 syn match forthSpaceError display " \+\t"me=e-1 39 endif 40endif 41 42" Keywords 43 44" basic mathematical and logical operators 45syn keyword forthOperators + - * / MOD /MOD NEGATE ABS MIN MAX 46syn keyword forthOperators AND OR XOR NOT LSHIFT RSHIFT INVERT 2* 2/ 1+ 47syn keyword forthOperators 1- 2+ 2- 8* UNDER+ 48syn keyword forthOperators M+ */ */MOD M* UM* M*/ UM/MOD FM/MOD SM/REM 49syn keyword forthOperators D+ D- DNEGATE DABS DMIN DMAX D2* D2/ 50syn keyword forthOperators F+ F- F* F/ FNEGATE FABS FMAX FMIN FLOOR FROUND 51syn keyword forthOperators F** FSQRT FEXP FEXPM1 FLN FLNP1 FLOG FALOG FSIN 52syn keyword forthOperators FCOS FSINCOS FTAN FASIN FACOS FATAN FATAN2 FSINH 53syn keyword forthOperators FCOSH FTANH FASINH FACOSH FATANH F2* F2/ 1/F 54syn keyword forthOperators F~REL F~ABS F~ 55syn keyword forthOperators 0< 0<= 0<> 0= 0> 0>= < <= <> = > >= U< U<= 56syn keyword forthOperators U> U>= D0< D0<= D0<> D0= D0> D0>= D< D<= D<> 57syn keyword forthOperators D= D> D>= DU< DU<= DU> DU>= WITHIN ?NEGATE 58syn keyword forthOperators ?DNEGATE TRUE FALSE 59 60" various words that take an input and do something with it 61syn keyword forthFunction . U. .R U.R 62 63" stack manipulations 64syn keyword forthStack DROP NIP DUP OVER TUCK SWAP ROT -ROT ?DUP PICK ROLL 65syn keyword forthStack 2DROP 2NIP 2DUP 2OVER 2TUCK 2SWAP 2ROT 2-ROT 66syn keyword forthStack 3DUP 4DUP 5DUP 3DROP 4DROP 5DROP 8DROP 4SWAP 4ROT 67syn keyword forthStack 4-ROT 4TUCK 8SWAP 8DUP 68syn keyword forthRStack >R R> R@ RDROP 2>R 2R> 2R@ 2RDROP 69syn keyword forthRstack 4>R 4R> 4R@ 4RDROP 70syn keyword forthFStack FDROP FNIP FDUP FOVER FTUCK FSWAP FROT 71 72" stack pointer manipulations 73syn keyword forthSP SP@ SP! FP@ FP! RP@ RP! LP@ LP! DEPTH 74 75" address operations 76syn keyword forthMemory @ ! +! C@ C! 2@ 2! F@ F! SF@ SF! DF@ DF! 77syn keyword forthAdrArith CHARS CHAR+ CELLS CELL+ CELL ALIGN ALIGNED FLOATS 78syn keyword forthAdrArith FLOAT+ FLOAT FALIGN FALIGNED SFLOATS SFLOAT+ 79syn keyword forthAdrArith SFALIGN SFALIGNED DFLOATS DFLOAT+ DFALIGN DFALIGNED 80syn keyword forthAdrArith MAXALIGN MAXALIGNED CFALIGN CFALIGNED 81syn keyword forthAdrArith ADDRESS-UNIT-BITS ALLOT ALLOCATE HERE 82syn keyword forthMemBlks MOVE ERASE CMOVE CMOVE> FILL BLANK UNUSED 83 84" conditionals 85syn keyword forthCond IF ELSE ENDIF THEN CASE OF ENDOF ENDCASE ?DUP-IF 86syn keyword forthCond ?DUP-0=-IF AHEAD CS-PICK CS-ROLL CATCH THROW WITHIN 87 88" iterations 89syn keyword forthLoop BEGIN WHILE REPEAT UNTIL AGAIN 90syn keyword forthLoop ?DO LOOP I J K +DO U+DO -DO U-DO DO +LOOP -LOOP 91syn keyword forthLoop UNLOOP LEAVE ?LEAVE EXIT DONE FOR NEXT RECURSE 92 93" new words 94syn match forthClassDef '\<:class\s*[^ \t]\+\>' 95syn match forthObjectDef '\<:object\s*[^ \t]\+\>' 96syn match forthColonDef '\<:m\?\s*[^ \t]\+\>' 97syn keyword forthEndOfColonDef ; ;M ;m 98syn keyword forthEndOfClassDef ;class 99syn keyword forthEndOfObjectDef ;object 100syn keyword forthDefine CONSTANT 2CONSTANT FCONSTANT VARIABLE 2VARIABLE 101syn keyword forthDefine FVARIABLE CREATE USER VALUE TO DEFER IS DOES> IMMEDIATE 102syn keyword forthDefine COMPILE-ONLY COMPILE RESTRICT INTERPRET POSTPONE EXECUTE 103syn keyword forthDefine LITERAL CREATE-INTERPRET/COMPILE INTERPRETATION> 104syn keyword forthDefine <INTERPRETATION COMPILATION> <COMPILATION ] LASTXT 105syn keyword forthDefine COMP' POSTPONE, FIND-NAME NAME>INT NAME?INT NAME>COMP 106syn keyword forthDefine NAME>STRING STATE C; CVARIABLE BUFFER: MARKER 107syn keyword forthDefine , 2, F, C, COMPILE, 108syn match forthDefine "\[IFDEF]" 109syn match forthDefine "\[IFUNDEF]" 110syn match forthDefine "\[THEN]" 111syn match forthDefine "\[ENDIF]" 112syn match forthDefine "\[ELSE]" 113syn match forthDefine "\[?DO]" 114syn match forthDefine "\[DO]" 115syn match forthDefine "\[LOOP]" 116syn match forthDefine "\[+LOOP]" 117syn match forthDefine "\[NEXT]" 118syn match forthDefine "\[BEGIN]" 119syn match forthDefine "\[UNTIL]" 120syn match forthDefine "\[AGAIN]" 121syn match forthDefine "\[WHILE]" 122syn match forthDefine "\[REPEAT]" 123syn match forthDefine "\[COMP']" 124syn match forthDefine "'" 125syn match forthDefine '\<\[\>' 126syn match forthDefine "\[']" 127syn match forthDefine '\[COMPILE]' 128syn match forthDefine '\[CHAR]' 129 130" debugging 131syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE 132syn match forthDebug "\<\~\~\>" 133 134" Assembler 135syn keyword forthAssembler ASSEMBLER CODE END-CODE ;CODE FLUSH-ICACHE C, 136 137" basic character operations 138syn keyword forthCharOps (.) CHAR EXPECT FIND WORD TYPE -TRAILING EMIT KEY 139syn keyword forthCharOps KEY? TIB CR BL COUNT SPACE SPACES 140" recognize 'char (' or '[char] (' correctly, so it doesn't 141" highlight everything after the paren as a comment till a closing ')' 142syn match forthCharOps '\<char\s\S\s' 143syn match forthCharOps '\<\[char\]\s\S\s' 144syn region forthCharOps start=+."\s+ skip=+\\"+ end=+"+ 145 146" char-number conversion 147syn keyword forthConversion <<# <# # #> #>> #S (NUMBER) (NUMBER?) CONVERT D>F 148syn keyword forthConversion D>S DIGIT DPL F>D HLD HOLD NUMBER S>D SIGN >NUMBER 149syn keyword forthConversion F>S S>F HOLDS 150 151" interpreter, wordbook, compiler 152syn keyword forthForth (LOCAL) BYE COLD ABORT >BODY >NEXT >LINK CFA >VIEW HERE 153syn keyword forthForth PAD WORDS VIEW VIEW> N>LINK NAME> LINK> L>NAME FORGET 154syn keyword forthForth BODY> ASSERT( ASSERT0( ASSERT1( ASSERT2( ASSERT3( ) 155syn keyword forthForth >IN ACCEPT ENVIRONMENT? EVALUATE QUIT SOURCE ACTION-OF 156syn keyword forthForth DEFER! DEFER@ PARSE PARSE-NAME REFILL RESTORE-INPUT 157syn keyword forthForth SAVE-INPUT SOURCE-ID 158syn region forthForth start=+ABORT"\s+ skip=+\\"+ end=+"+ 159 160" vocabularies 161syn keyword forthVocs ONLY FORTH ALSO ROOT SEAL VOCS ORDER CONTEXT #VOCS 162syn keyword forthVocs VOCABULARY DEFINITIONS 163 164" File keywords 165syn keyword forthFileMode R/O R/W W/O BIN 166syn keyword forthFileWords OPEN-FILE CREATE-FILE CLOSE-FILE DELETE-FILE 167syn keyword forthFileWords RENAME-FILE READ-FILE READ-LINE KEY-FILE 168syn keyword forthFileWords KEY?-FILE WRITE-FILE WRITE-LINE EMIT-FILE 169syn keyword forthFileWords FLUSH-FILE FILE-STATUS FILE-POSITION 170syn keyword forthFileWords REPOSITION-FILE FILE-SIZE RESIZE-FILE 171syn keyword forthFileWords SLURP-FILE SLURP-FID STDIN STDOUT STDERR 172syn keyword forthFileWords INCLUDE-FILE INCLUDED REQUIRED 173syn keyword forthBlocks OPEN-BLOCKS USE LOAD --> BLOCK-OFFSET 174syn keyword forthBlocks GET-BLOCK-FID BLOCK-POSITION LIST SCR BLOCK 175syn keyword forthBlocks BUFER EMPTY-BUFFERS EMPTY-BUFFER UPDATE UPDATED? 176syn keyword forthBlocks SAVE-BUFFERS SAVE-BUFFER FLUSH THRU +LOAD +THRU 177syn keyword forthBlocks BLOCK-INCLUDED BLK 178 179" numbers 180syn keyword forthMath DECIMAL HEX BASE 181syn match forthInteger '\<-\=[0-9]\+.\=\>' 182syn match forthInteger '\<&-\=[0-9]\+.\=\>' 183" recognize hex and binary numbers, the '$' and '%' notation is for gforth 184syn match forthInteger '\<\$\x*\x\+\>' " *1* --- dont't mess 185syn match forthInteger '\<\x*\d\x*\>' " *2* --- this order! 186syn match forthInteger '\<%[0-1]*[0-1]\+\>' 187syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe]\d\+\>' 188syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe][-+]\d\+\>' 189 190" XXX If you find this overkill you can remove it. this has to come after the 191" highlighting for numbers otherwise it has no effect. 192syn region forthComment start='0 \[if\]' end='\[endif\]' end='\[then\]' contains=forthTodo 193 194" Strings 195syn region forthString start=+\.*\"+ end=+"+ end=+$+ 196" XXX 197syn region forthString start=+s\"+ end=+"+ end=+$+ 198syn region forthString start=+s\\\"+ end=+"+ end=+$+ 199syn region forthString start=+c\"+ end=+"+ end=+$+ 200 201" Comments 202syn match forthComment '\\\s.*$' contains=forthTodo,forthSpaceError 203syn region forthComment start='\\S\s' end='.*' contains=forthTodo,forthSpaceError 204syn match forthComment '\.(\s[^)]*)' contains=forthTodo,forthSpaceError 205syn region forthComment start='\(^\|\s\)\zs(\s' skip='\\)' end=')' contains=forthTodo,forthSpaceError 206syn region forthComment start='/\*' end='\*/' contains=forthTodo,forthSpaceError 207 208" Include files 209syn match forthInclude '^INCLUDE\s\+\k\+' 210syn match forthInclude '^REQUIRE\s\+\k\+' 211syn match forthInclude '^FLOAD\s\+' 212syn match forthInclude '^NEEDS\s\+' 213 214" Locals definitions 215syn region forthLocals start='{\s' start='{$' end='\s}' end='^}' 216syn match forthLocals '{ }' " otherwise, at least two spaces between 217syn region forthDeprecated start='locals|' end='|' 218 219" Define the default highlighting. 220hi def link forthTodo Todo 221hi def link forthOperators Operator 222hi def link forthMath Number 223hi def link forthInteger Number 224hi def link forthFloat Float 225hi def link forthStack Special 226hi def link forthRstack Special 227hi def link forthFStack Special 228hi def link forthSP Special 229hi def link forthMemory Function 230hi def link forthAdrArith Function 231hi def link forthMemBlks Function 232hi def link forthCond Conditional 233hi def link forthLoop Repeat 234hi def link forthColonDef Define 235hi def link forthEndOfColonDef Define 236hi def link forthDefine Define 237hi def link forthDebug Debug 238hi def link forthAssembler Include 239hi def link forthCharOps Character 240hi def link forthConversion String 241hi def link forthForth Statement 242hi def link forthVocs Statement 243hi def link forthString String 244hi def link forthComment Comment 245hi def link forthClassDef Define 246hi def link forthEndOfClassDef Define 247hi def link forthObjectDef Define 248hi def link forthEndOfObjectDef Define 249hi def link forthInclude Include 250hi def link forthLocals Type " nothing else uses type and locals must stand out 251hi def link forthDeprecated Error " if you must, change to Type 252hi def link forthFileMode Function 253hi def link forthFunction Function 254hi def link forthFileWords Statement 255hi def link forthBlocks Statement 256hi def link forthSpaceError Error 257 258let b:current_syntax = "forth" 259 260let &cpo = s:cpo_save 261unlet s:cpo_save 262" vim:ts=8:sw=4:nocindent:smartindent: 263