codekingpro/portable-devtools
115k
1" Vim syntax file2" Language: Forth3" Maintainer: Johan Kotlinski <kotlinski@gmail.com>4" Previous Maintainer: Christian V. J. Brüssow <cvjb@cvjb.de>5" Last Change: 2023 Aug 136" Filenames: *.f,*.fs,*.ft,*.fth,*.4th7" URL: https://github.com/jkotlinski/forth.vim8 9" Supports the Forth-2012 Standard.10"11" Removed words from the earlier Forth-79, Forth-83 and Forth-94 standards are12" also included.13"14" These have been organised according to the version in which they were15" initially included and the version in which they were removed (obsolescent16" status is ignored). Words with "experimental" or "uncontrolled" status are17" not included unless they were later standardised.18 19" quit when a syntax file was already loaded20if exists("b:current_syntax")21 finish22endif23 24let s:cpo_save = &cpo25set cpo&vim26 27" Synchronization method28exe "syn sync minlines=" .. get(g:, "forth_minlines", 50)29 30syn case ignore31 32" Characters allowed in keywords33" I don't know if 128-255 are allowed in ANS-FORTH34syn iskeyword 33-126,128-25535 36" Space errors {{{137" when wanted, highlight trailing white space38if exists("forth_space_errors")39 if !exists("forth_no_trail_space_error")40 syn match forthSpaceError display excludenl "\s\+$"41 endif42 if !exists("forth_no_tab_space_error")43 syn match forthSpaceError display " \+\t"me=e-144 endif45endif46 47" Core words {{{148 49" basic mathematical and logical operators {{{250syn keyword forthOperators * */ */MOD + - / /MOD 0< 0= 1+ 1- 2* 2/ < = > ABS51syn keyword forthOperators AND FM/MOD INVERT LSHIFT M* MAX MIN MOD NEGATE OR52syn keyword forthOperators RSHIFT SM/REM U< UM* UM/MOD XOR53 " extension words54syn keyword forthOperators 0<> 0> <> U> WITHIN55 " Forth-7956syn keyword forthOperators U* U/ U/MOD57 " Forth-79, Forth-8358syn keyword forthOperators NOT59 " Forth-8360syn keyword forthOperators 2+ 2-61 62" non-standard basic mathematical and logical operators63syn keyword forthOperators 0<= 0>= 8* <= >= ?DNEGATE ?NEGATE U<= U>= UNDER+64 65" various words that take an input and do something with it {{{266syn keyword forthFunction . U.67 " extension words68syn keyword forthFunction .R U.R69 70" stack manipulations {{{271syn keyword forthStack 2DROP 2DUP 2OVER 2SWAP >R ?DUP DROP DUP OVER R> R@ ROT72syn keyword forthStack SWAP73 " extension words74syn keyword forthStack NIP PICK ROLL TUCK75syn keyword forthRStack 2>R 2R> 2R@76 77" non-standard stack manipulations78syn keyword forthStack -ROT 3DROP 3DUP 4-ROT 4DROP 4DUP 4ROT 4SWAP 4TUCK79syn keyword forthStack 5DROP 5DUP 8DROP 8DUP 8SWAP80syn keyword forthRStack 4>R 4R> 4R@ 4RDROP RDROP81 82" stack pointer manipulations {{{283syn keyword forthSP DEPTH84 85" non-standard stack pointer manipulations86syn keyword forthSP FP! FP@ LP! LP@ RP! RP@ SP! SP@87 88" address operations {{{289syn keyword forthMemory ! +! 2! 2@ @ C! C@90syn keyword forthAdrArith ALIGN ALIGNED ALLOT CELL+ CELLS CHAR+ CHARS91syn keyword forthMemBlks FILL MOVE92 " extension words93syn keyword forthMemBlks ERASE UNUSED94 95" non-standard address operations96syn keyword forthAdrArith ADDRESS-UNIT-BITS CELL CFALIGN CFALIGNED FLOAT97syn keyword forthAdrArith MAXALIGN MAXALIGNED98 99" conditionals {{{2100syn keyword forthCond ELSE IF THEN101 " extension words102syn keyword forthCond CASE ENDCASE ENDOF OF103 104" non-standard conditionals105syn keyword forthCond ?DUP-0=-IF ?DUP-IF ENDIF106 107" iterations {{{2108syn keyword forthLoop +LOOP BEGIN DO EXIT I J LEAVE LOOP RECURSE REPEAT UNLOOP109syn keyword forthLoop UNTIL WHILE110 " extension words111syn keyword forthLoop ?DO AGAIN112 113" non-standard iterations114syn keyword forthLoop +DO -DO -LOOP ?LEAVE DONE FOR K NEXT U+DO U-DO115 116" new words {{{2117syn match forthColonDef "\<:\s*[^ \t]\+\>"118syn keyword forthEndOfColonDef ;119syn keyword forthDefine ' , C, CONSTANT CREATE DOES> EXECUTE IMMEDIATE LITERAL120syn keyword forthDefine POSTPONE STATE VARIABLE ]121syn match forthDefine "\<\[']\>"122syn match forthDefine "\<\[\>"123 " extension words124syn keyword forthColonDef :NONAME125syn keyword forthDefine BUFFER: COMPILE, DEFER IS MARKER TO VALUE126syn match forthDefine "\<\[COMPILE]\>"127 " Forth-79, Forth-83128syn keyword forthDefine COMPILE129 130" non-standard new words131syn match forthClassDef "\<:CLASS\s*[^ \t]\+\>"132syn keyword forthEndOfClassDef ;CLASS133syn match forthObjectDef "\<:OBJECT\s*[^ \t]\+\>"134syn keyword forthEndOfObjectDef ;OBJECT135syn match forthColonDef "\<:M\s*[^ \t]\+\>"136syn keyword forthEndOfColonDef ;M137syn keyword forthDefine 2, <BUILDS <COMPILATION <INTERPRETATION C; COMP'138syn keyword forthDefine COMPILATION> COMPILE-ONLY CREATE-INTERPRET/COMPILE139syn keyword forthDefine CVARIABLE F, FIND-NAME INTERPRET INTERPRETATION>140syn keyword forthDefine LASTXT NAME>COMP NAME>INT NAME?INT POSTPONE, RESTRICT141syn keyword forthDefine USER142syn match forthDefine "\<\[COMP']\>"143 144" basic character operations {{{2145syn keyword forthCharOps BL COUNT CR EMIT FIND KEY SPACE SPACES TYPE WORD146" recognize 'char (' or '[CHAR] (' correctly, so it doesn't147" highlight everything after the paren as a comment till a closing ')'148syn match forthCharOps '\<CHAR\s\S\s'149syn match forthCharOps '\<\[CHAR]\s\S\s'150 " Forth-83, Forth-94151syn keyword forthCharOps EXPECT #TIB TIB152 153" non-standard basic character operations154syn keyword forthCharOps (.)155 156" char-number conversion {{{2157syn keyword forthConversion # #> #S <# >NUMBER HOLD S>D SIGN158 " extension words159syn keyword forthConversion HOLDS160 " Forth-79, Forth-83, Forth-93161syn keyword forthConversion CONVERT162 163" non-standard char-number conversion164syn keyword forthConversion #>> (NUMBER) (NUMBER?) <<# DIGIT DPL HLD NUMBER165 166" interpreter, wordbook, compiler {{{2167syn keyword forthForth >BODY >IN ACCEPT ENVIRONMENT? EVALUATE HERE QUIT SOURCE168 " extension words169syn keyword forthForth ACTION-OF DEFER! DEFER@ PAD PARSE PARSE-NAME REFILL170syn keyword forthForth RESTORE-INPUT SAVE-INPUT SOURCE-ID171 " Forth-79172syn keyword forthForth 79-STANDARD173 " Forth-83174syn keyword forthForth <MARK <RESOLVE >MARK >RESOLVE ?BRANCH BRANCH FORTH-83175 " Forth-79, Forth-83, Forth-94176syn keyword forthForth QUERY177 " Forth-83, Forth-94178syn keyword forthForth SPAN179 180" non-standard interpreter, wordbook, compiler181syn keyword forthForth ) >LINK >NEXT >VIEW ASSERT( ASSERT0( ASSERT1( ASSERT2(182syn keyword forthForth ASSERT3( BODY> CFA COLD L>NAME LINK> N>LINK NAME> VIEW183syn keyword forthForth VIEW>184 185" booleans {{{2186 " extension words187syn match forthBoolean "\<\%(TRUE\|FALSE\)\>"188 189" numbers {{{2190syn keyword forthMath BASE DECIMAL191 " extension words192syn keyword forthMath HEX193syn match forthInteger '\<-\=\d\+\.\=\>'194syn match forthInteger '\<#-\=\d\+\.\=\>'195syn match forthInteger '\<\$-\=\x\+\.\=\>'196syn match forthInteger '\<%-\=[01]\+\.\=\>'197 198" characters {{{2199syn match forthCharacter "'\k'"200 201" strings {{{2202 203" Words that end with " are assumed to start string parsing.204" This includes standard words: S" ."205syn region forthString matchgroup=forthString start=+\<\S\+"\s+ end=+"+ end=+$+ contains=@Spell206 " extension words207syn region forthString matchgroup=forthString start=+\<C"\s+ end=+"+ end=+$+ contains=@Spell208" Matches S\"209syn region forthString matchgroup=forthString start=+\<S\\"\s+ end=+"+ end=+$+ contains=@Spell,forthEscape210 211syn match forthEscape +\C\\[abeflmnqrtvz"\\]+ contained212syn match forthEscape "\C\\x\x\x" contained213 214" comments {{{2215 216syn keyword forthTodo contained TODO FIXME XXX217 218" Some special, non-FORTH keywords219syn match forthTodo contained "\<\%(TODO\|FIXME\|XXX\)\%(\>\|:\@=\)"220 221" XXX If you find this overkill you can remove it. This has to come after the222" highlighting for numbers and booleans otherwise it has no effect.223syn region forthComment start='\<\%(0\|FALSE\)\s\+\[IF]' end='\<\[ENDIF]' end='\<\[THEN]' contains=forthTodo224 225if get(g:, "forth_no_comment_fold", 0)226 syn region forthComment start='\<(\>' end=')' contains=@Spell,forthTodo,forthSpaceError227 " extension words228 syn match forthComment '\<\\\>.*$' contains=@Spell,forthTodo,forthSpaceError229else230 syn region forthComment start='\<(\>' end=')' contains=@Spell,forthTodo,forthSpaceError fold231 " extension words232 syn match forthComment '\<\\\>.*$' contains=@Spell,forthTodo,forthSpaceError233 syn region forthMultilineComment start="^\s*\\\>" end="\n\%(\s*\\\>\)\@!" contains=forthComment transparent fold234endif235 236 " extension words237syn region forthComment start='\<\.(\>' end=')' end='$' contains=@Spell,forthTodo,forthSpaceError238 239" ABORT {{{2240syn keyword forthForth ABORT241syn region forthForth start=+\<ABORT"\s+ end=+"\>+ end=+$+242 243" The optional Block word set {{{1244" Handled as Core words - REFILL245syn keyword forthBlocks BLK BLOCK BUFFER FLUSH LOAD SAVE-BUFFERS UPDATE246 " extension words247syn keyword forthBlocks EMPTY-BUFFERS LIST SCR THRU248 249" Non-standard Block words250syn keyword forthBlocks +LOAD +THRU --> BLOCK-INCLUDED BLOCK-OFFSET251syn keyword forthBlocks BLOCK-POSITION EMPTY-BUFFER GET-BLOCK-FID OPEN-BLOCKS252syn keyword forthBlocks SAVE-BUFFER UPDATED? USE253 254" The optional Double-Number word set {{{1255syn keyword forthConversion D>S256syn keyword forthDefine 2CONSTANT 2LITERAL 2VARIABLE257syn keyword forthFunction D. D.R258syn keyword forthOperators D+ D- D0= D2* D2/ D= DABS DMAX DMIN DNEGATE259syn keyword forthOperators D0< D< M+ M*/260 " extension words261syn keyword forthDefine 2VALUE262syn keyword forthOperators DU<263syn keyword forthStack 2ROT264 265" Non-standard Double-Number words266syn keyword forthOperators D0<= D0<> D0> D0>= D<= D<> D> D>= DU<= DU> DU>=267syn keyword forthStack 2-ROT 2NIP 2RDROP 2TUCK268 269" The optional Exception word set {{{1270" Handled as Core words - ABORT ABORT"271syn keyword forthCond CATCH THROW272 273" The optional Facility word set {{{1274syn keyword forthCharOps AT-XY KEY? PAGE275 " extension words276syn keyword forthCharOps EKEY EKEY>CHAR EKEY>FKEY EKEY? EMIT? K-ALT-MASK277syn keyword forthCharOps K-CTRL-MASK K-DELETE K-DOWN K-END K-F1 K-F10 K-F11278syn keyword forthCharOps K-F12 K-F2 K-F3 K-F4 K-F5 K-F6 K-F7 K-F8 K-F9 K-HOME279syn keyword forthCharOps K-INSERT K-LEFT K-NEXT K-PRIOR K-RIGHT K-SHIFT-MASK280syn keyword forthCharOps K-UP281syn keyword forthDefine +FIELD BEGIN-STRUCTURE CFIELD: END-STRUCTURE FIELD:282syn keyword forthForth MS TIME&DATE283 284" The optional File-Access word set {{{1285" Handled as Core words - REFILL SOURCE-ID S\" S" (286syn keyword forthFileMode BIN R/O R/W W/O287syn keyword forthFileWords CLOSE-FILE CREATE-FILE DELETE-FILE FILE-POSITION288syn keyword forthFileWords FILE-SIZE INCLUDE-FILE INCLUDED OPEN-FILE READ-FILE289syn keyword forthFileWords READ-LINE REPOSITION-FILE RESIZE-FILE WRITE-FILE290syn keyword forthFileWords WRITE-LINE291 " extension words292syn keyword forthFileWords FILE-STATUS FLUSH-FILE RENAME-FILE REQUIRED293syn match forthInclude '\<INCLUDE\s\+\k\+'294syn match forthInclude '\<REQUIRE\s\+\k\+'295 296" Non-standard File-Access words297syn keyword forthFileWords EMIT-FILE KEY-FILE KEY?-FILE SLURP-FID SLURP-FILE298syn keyword forthFileWords STDERR STDIN STDOUT299syn match forthInclude '^FLOAD\s\+'300syn match forthInclude '^NEEDS\s\+'301 302" The optional Floating-Point word set {{{1303 304" numbers305syn match forthFloat '\<[+-]\=\d\+\.\=\d*[DdEe][+-]\=\d*\>'306 307syn keyword forthConversion >FLOAT D>F F>D308syn keyword forthAdrArith FALIGN FALIGNED FLOAT+ FLOATS309syn keyword forthDefine FCONSTANT FLITERAL FVARIABLE310syn keyword forthFStack FDROP FDUP FOVER FROT FSWAP311syn keyword forthFunction REPRESENT312syn keyword forthMemory F! F@313syn keyword forthOperators F* F+ F- F/ F0< F0= F< FLOOR FMAX FMIN FNEGATE314syn keyword forthOperators FROUND315syn keyword forthSP FDEPTH316 " extension words317syn keyword forthConversion F>S S>F318syn keyword forthAdrArith DFALIGN DFALIGNED DFLOAT+ DFLOATS SFALIGN319syn keyword forthAdrArith SFALIGNED SFLOAT+ SFLOATS320syn keyword forthDefine DFFIELD: FFIELD: FVALUE SFFIELD:321syn keyword forthFunction F. FE. FS. PRECISION SET-PRECISION322syn keyword forthMemory DF! DF@ SF! SF@323syn keyword forthOperators F** FABS FACOS FACOSH FALOG FASIN FASINH FATAN324syn keyword forthOperators FATAN2 FATANH FCOS FCOSH FEXP FEXPM1 FLN FLNP1325syn keyword forthOperators FLOG FSIN FSINCOS FSINH FSQRT FTAN FTANH FTRUNC F~326 327" Non-standard Floating-Point words328syn keyword forthOperators 1/F F2* F2/ F~ABS F~REL329syn keyword forthFStack FNIP FTUCK330 331" The optional Locals word set {{{1332syn keyword forthForth (LOCAL)333 " extension words334syn region forthLocals start="\<{:\>" end="\<:}\>"335syn region forthLocals start="\<LOCALS|\>" end="\<|\>"336 337" Non-standard Locals words338syn region forthLocals start="\<{\>" end="\<}\>"339 340" The optional Memory-Allocation word set {{{1341syn keyword forthMemory ALLOCATE FREE RESIZE342 343" The optional Programming-Tools wordset {{{1344syn keyword forthDebug .S ? DUMP SEE WORDS345 " extension words346syn keyword forthAssembler ;CODE ASSEMBLER CODE END-CODE347syn keyword forthCond AHEAD CS-PICK CS-ROLL348syn keyword forthDefine NAME>COMPILE NAME>INTERPRET NAME>STRING SYNONYM349syn keyword forthDefine TRAVERSE-WORDLIST350syn match forthDefine "\<\[DEFINED]\>"351syn match forthDefine "\<\[ELSE]\>"352syn match forthDefine "\<\[IF]\>"353syn match forthDefine "\<\[THEN]\>"354syn match forthDefine "\<\[UNDEFINED]\>"355syn keyword forthForth BYE FORGET356syn keyword forthStack N>R NR>357syn keyword forthVocs EDITOR358 359" Non-standard Programming-Tools words360syn keyword forthAssembler FLUSH-ICACHE361syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE362syn match forthDebug "\<\~\~\>"363syn match forthDefine "\<\[+LOOP]\>"364syn match forthDefine "\<\[?DO]\>"365syn match forthDefine "\<\[AGAIN]\>"366syn match forthDefine "\<\[BEGIN]\>"367syn match forthDefine "\<\[DO]\>"368syn match forthDefine "\<\[ENDIF]\>"369syn match forthDefine "\<\[IFDEF]\>"370syn match forthDefine "\<\[IFUNDEF]\>"371syn match forthDefine "\<\[LOOP]\>"372syn match forthDefine "\<\[NEXT]\>"373syn match forthDefine "\<\[REPEAT]\>"374syn match forthDefine "\<\[UNTIL]\>"375syn match forthDefine "\<\[WHILE]\>"376 377" The optional Search-Order word set {{{1378" Handled as Core words - FIND379syn keyword forthVocs DEFINITIONS FORTH-WORDLIST GET-CURRENT GET-ORDER380syn keyword forthVocs SEARCH-WORDLIST SET-CURRENT SET-ORDER WORDLIST381 " extension words382syn keyword forthVocs ALSO FORTH ONLY ORDER PREVIOUS383 " Forth-79, Forth-83384syn keyword forthVocs CONTEXT CURRENT VOCABULARY385 386" Non-standard Search-Order words387syn keyword forthVocs #VOCS ROOT SEAL VOCS388 389" The optional String word set {{{1390syn keyword forthFunction -TRAILING /STRING BLANK CMOVE CMOVE> COMPARE SEARCH391syn keyword forthFunction SLITERAL392 " extension words393syn keyword forthFunction REPLACES SUBSTITUTE UNESCAPE394 395" The optional Extended-Character word set {{{1396" Handled as Core words - [CHAR] CHAR and PARSE397syn keyword forthAdrArith XCHAR+398syn keyword forthCharOps X-SIZE XC-SIZE XEMIT XKEY XKEY?399syn keyword forthDefine XC,400syn keyword forthMemory XC!+ XC!+? XC@+401 " extension words402syn keyword forthAdrArith XCHAR- +X/STRING X\\STRING-403syn keyword forthCharOps EKEY>XCHAR X-WIDTH XC-WIDTH404syn keyword forthConversion XHOLD405syn keyword forthString -TRAILING-GARBAGE406 407" Define the default highlighting {{{1408hi def link forthBoolean Boolean409hi def link forthCharacter Character410hi def link forthTodo Todo411hi def link forthOperators Operator412hi def link forthMath Number413hi def link forthInteger Number414hi def link forthFloat Float415hi def link forthStack Special416hi def link forthRstack Special417hi def link forthFStack Special418hi def link forthSP Special419hi def link forthMemory Function420hi def link forthAdrArith Function421hi def link forthMemBlks Function422hi def link forthCond Conditional423hi def link forthLoop Repeat424hi def link forthColonDef Define425hi def link forthEndOfColonDef Define426hi def link forthDefine Define427hi def link forthDebug Debug428hi def link forthAssembler Include429hi def link forthCharOps Character430hi def link forthConversion String431hi def link forthForth Statement432hi def link forthVocs Statement433hi def link forthEscape Special434hi def link forthString String435hi def link forthComment Comment436hi def link forthClassDef Define437hi def link forthEndOfClassDef Define438hi def link forthObjectDef Define439hi def link forthEndOfObjectDef Define440hi def link forthInclude Include441hi def link forthLocals Type " nothing else uses type and locals must stand out442hi def link forthFileMode Function443hi def link forthFunction Function444hi def link forthFileWords Statement445hi def link forthBlocks Statement446hi def link forthSpaceError Error447"}}}448 449let b:current_syntax = "forth"450 451let &cpo = s:cpo_save452unlet s:cpo_save453 454" vim:ts=8:sw=4:nocindent:smartindent:fdm=marker:tw=78455 456 