robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2fad4c0b39
master
1" Vim syntax file 2" Language: Forth 3" Maintainer: Johan Kotlinski <kotlinski@gmail.com> 4" Previous Maintainer: Christian V. J. Brüssow <cvjb@cvjb.de> 5" Last Change: 2023 Aug 13 6" Filenames: *.f,*.fs,*.ft,*.fth,*.4th 7" URL: https://github.com/jkotlinski/forth.vim 8 9" Supports the Forth-2012 Standard. 10" 11" Removed words from the earlier Forth-79, Forth-83 and Forth-94 standards are 12" also included. 13" 14" These have been organised according to the version in which they were 15" initially included and the version in which they were removed (obsolescent 16" status is ignored). Words with "experimental" or "uncontrolled" status are 17" not included unless they were later standardised. 18 19" quit when a syntax file was already loaded 20if exists ( "b:current_syntax" ) 21finish 22endif 23 24let s: cpo_save = & cpo 25set cpo & vim 26 27" Synchronization method 28exe "syn sync minlines=" .. get ( g:, "forth_minlines" , 50 ) 29 30syn case ignore 31 32" Characters allowed in keywords 33" I don't know if 128-255 are allowed in ANS-FORTH 34syn iskeyword 33-126,128-255 35 36" Space errors {{{1 37" when wanted, highlight trailing white space 38if exists ( "forth_space_errors" ) 39if ! exists ( "forth_no_trail_space_error" ) 40syn match forthSpaceError display excludenl "\s\+$ " 41endif 42if ! exists ( "forth_no_tab_space_error" ) 43syn match forthSpaceError display "\+\t "me= e-1 44endif 45endif 46 47" Core words {{{1 48 49" basic mathematical and logical operators {{{2 50syn keywordforthOperators * */ */MOD + - / /MOD 0< 0= 1+ 1- 2* 2/ < = >ABS 51syn keyword forthOperators AND FM /MOD INVERT LSHIFT M* MAX MIN MOD NEGATE OR 52syn keyword forthOperators RSHIFT SM /REM U< UM* UM/MOD XOR 53" extension words 54syn keyword forthOperators 0 <>0> <>U> WITHIN 55" Forth-79 56syn keyword forthOperators U *U/ U/MOD 57" Forth-79, Forth-83 58syn keyword forthOperators NOT 59" Forth-83 60syn keyword forthOperators 2 +2- 61 62" non-standard basic mathematical and logical operators 63syn keyword forthOperators 0 <=0>= 8* <= >= ?DNEGATE ?NEGATE U<= U>= UNDER+ 64 65" various words that take an input and do something with it {{{2 66syn keywordforthFunction .U. 67" extension words 68syn keywordforthFunction .R U.R 69 70" stack manipulations {{{2 71syn keyword forthStack 2DROP 2DUP 2OVER 2SWAP >R ?DUP DROP DUP OVER R> R@ ROT 72syn keyword forthStack SWAP 73" extension words 74syn keyword forthStack NIP PICK ROLL TUCK 75syn keyword forthRStack 2 >R 2R> 2R@ 76 77" non-standard stack manipulations 78syn keywordforthStack -ROT 3DROP 3DUP 4-ROT 4DROP 4DUP 4ROT 4SWAP 4TUCK 79syn keyword forthStack 5DROP 5DUP 8DROP 8DUP 8SWAP 80syn keyword forthRStack 4 >R 4R> 4R@ 4RDROP RDROP 81 82" stack pointer manipulations {{{2 83syn keyword forthSP DEPTH 84 85" non-standard stack pointer manipulations 86syn keyword forthSP FP !FP@ LP! LP@ RP! RP@ SP! SP@ 87 88" address operations {{{2 89syn keywordforthMemory ! +!2! 2@ @C! C@ 90syn keyword forthAdrArith ALIGN ALIGNED ALLOT CELL +CELLS CHAR+ CHARS 91syn keyword forthMemBlks FILL MOVE 92" extension words 93syn keyword forthMemBlks ERASE UNUSED 94 95" non-standard address operations 96syn keyword forthAdrArith ADDRESS -UNIT-BITS CELL CFALIGN CFALIGNED FLOAT 97syn keyword forthAdrArith MAXALIGN MAXALIGNED 98 99" conditionals {{{2 100syn keyword forthCond ELSE IF THEN 101" extension words 102syn keyword forthCond CASE ENDCASE ENDOF OF 103 104" non-standard conditionals 105syn keywordforthCond ?DUP-0=-IF ?DUP-IF ENDIF 106 107" iterations {{{2 108syn keywordforthLoop +LOOP BEGIN DO EXIT I J LEAVE LOOP RECURSE REPEAT UNLOOP 109syn keyword forthLoop UNTIL WHILE 110" extension words 111syn keywordforthLoop ?DO AGAIN 112 113" non-standard iterations 114syn keywordforthLoop +DO -DO -LOOP ?LEAVE DONE FOR K NEXT U+DO U-DO 115 116" new words {{{2 117syn match forthColonDef "\<:\s * [ ^ \t ] \+\> " 118syn keywordforthEndOfColonDef ; 119syn keywordforthDefine ' ,C, CONSTANT CREATE DOES> EXECUTE IMMEDIATE LITERAL 120syn keyword forthDefine POSTPONE STATE VARIABLE ] 121syn match forthDefine "\<\[']\> " 122syn match forthDefine "\<\[\> " 123" extension words 124syn keywordforthColonDef :NONAME 125syn keyword forthDefine BUFFER :COMPILE, DEFER IS MARKER TO VALUE 126syn match forthDefine "\<\[COMPILE]\> " 127" Forth-79, Forth-83 128syn keyword forthDefine COMPILE 129 130" non-standard new words 131syn match forthClassDef "\<:CLASS\s * [ ^ \t ] \+\> " 132syn keywordforthEndOfClassDef ;CLASS 133syn match forthObjectDef "\<:OBJECT\s * [ ^ \t ] \+\> " 134syn keywordforthEndOfObjectDef ;OBJECT 135syn match forthColonDef "\<:M\s * [ ^ \t ] \+\> " 136syn keywordforthEndOfColonDef ;M 137syn keyword forthDefine 2 , <BUILDS <COMPILATION <INTERPRETATION C; COMP' 138syn keyword forthDefine COMPILATION >COMPILE-ONLY CREATE-INTERPRET/COMPILE 139syn keyword forthDefine CVARIABLE F , FIND-NAME INTERPRET INTERPRETATION> 140syn keyword forthDefine LASTXT NAME >COMP NAME>INT NAME?INT POSTPONE, RESTRICT 141syn keyword forthDefine USER 142syn match forthDefine "\<\[COMP']\> " 143 144" basic character operations {{{2 145syn keyword forthCharOps BL COUNT CR EMIT FIND KEY SPACE SPACES TYPE WORD 146" recognize 'char (' or '[CHAR] (' correctly, so it doesn't 147" 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-94 151syn keyword forthCharOps EXPECT #TIB TIB 152 153" non-standard basic character operations 154syn keywordforthCharOps (.) 155 156" char-number conversion {{{2 157syn keywordforthConversion # #> #S <# >NUMBER HOLD S>D SIGN 158" extension words 159syn keyword forthConversion HOLDS 160" Forth-79, Forth-83, Forth-93 161syn keyword forthConversion CONVERT 162 163" non-standard char-number conversion 164syn keywordforthConversion #>> (NUMBER) (NUMBER?) <<#DIGIT DPL HLD NUMBER 165 166" interpreter, wordbook, compiler {{{2 167syn keywordforthForth >BODY >IN ACCEPT ENVIRONMENT? EVALUATE HERE QUIT SOURCE 168" extension words 169syn keyword forthForth ACTION -OF DEFER! DEFER@ PAD PARSE PARSE-NAME REFILL 170syn keyword forthForth RESTORE -INPUT SAVE-INPUT SOURCE-ID 171" Forth-79 172syn keyword forthForth 79 -STANDARD 173" Forth-83 174syn keywordforthForth <MARK <RESOLVE >MARK >RESOLVE ?BRANCH BRANCH FORTH-83 175" Forth-79, Forth-83, Forth-94 176syn keyword forthForth QUERY 177" Forth-83, Forth-94 178syn keyword forthForth SPAN 179 180" non-standard interpreter, wordbook, compiler 181syn keywordforthForth ) >LINK >NEXT >VIEW ASSERT( ASSERT0( ASSERT1( ASSERT2( 182syn keyword forthForth ASSERT3 (BODY> CFA COLD L>NAME LINK> N>LINK NAME> VIEW 183syn keyword forthForth VIEW > 184 185" booleans {{{2 186" extension words 187syn match forthBoolean "\<\%(TRUE\|FALSE\)\> " 188 189" numbers {{{2 190syn keyword forthMath BASE DECIMAL 191" extension words 192syn keyword forthMath HEX 193syn match forthInteger '\<-\=\d\+\.\=\> ' 194syn match forthInteger '\<#-\=\d\+\.\=\> ' 195syn match forthInteger '\<\$-\=\x\+\.\=\> ' 196syn match forthInteger '\<%-\= [ 01 ] \+\.\=\> ' 197 198" characters {{{2 199syn match forthCharacter "'\k' " 200 201" strings {{{2 202 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 = @Spell 206" extension words 207syn region forthString matchgroup = forthString start = +\<C"\s +end = +" +end = +$ +contains = @Spell 208" Matches S\" 209syn region forthString matchgroup = forthString start = +\<S\\"\s +end = +" +end = +$ +contains = @Spell , forthEscape 210 211syn match forthEscape +\C\\ [ abeflmnqrtvz"\\ ] +contained 212syn match forthEscape "\C\\x\x\x "contained 213 214" comments {{{2 215 216syn keyword forthTodo contained TODO FIXME XXX 217 218" Some special, non-FORTH keywords 219syn match forthTodo contained "\<\%(TODO\|FIXME\|XXX\)\%(\>\|:\@=\) " 220 221" XXX If you find this overkill you can remove it. This has to come after the 222" highlighting for numbers and booleans otherwise it has no effect. 223syn region forthComment start = '\<\%(0\|FALSE\)\s\+\[IF] 'end = '\<\[ENDIF] 'end = '\<\[THEN] 'contains = forthTodo 224 225if get ( g:, "forth_no_comment_fold" , 0 ) 226syn region forthComment start = '\<(\> 'end = ') 'contains = @Spell , forthTodo , forthSpaceError 227" extension words 228syn match forthComment '\<\\\>. * $ 'contains = @Spell , forthTodo , forthSpaceError 229else 230syn region forthComment start = '\<(\> 'end = ') 'contains = @Spell , forthTodo , forthSpaceError fold 231" extension words 232syn match forthComment '\<\\\>. * $ 'contains = @Spell , forthTodo , forthSpaceError 233syn region forthMultilineComment start = "^\s * \\\> "end = "\n\%(\s * \\\>\)\@! "contains = forthComment transparent fold 234endif 235 236" extension words 237syn region forthComment start = '\<\.(\> 'end = ') 'end = '$ 'contains = @Spell , forthTodo , forthSpaceError 238 239" ABORT {{{2 240syn keyword forthForth ABORT 241syn region forthForth start = +\<ABORT"\s +end = +"\> +end = +$ + 242 243" The optional Block word set {{{1 244" Handled as Core words - REFILL 245syn keyword forthBlocks BLK BLOCK BUFFER FLUSH LOAD SAVE -BUFFERS UPDATE 246" extension words 247syn keyword forthBlocks EMPTY -BUFFERS LIST SCR THRU 248 249" Non-standard Block words 250syn keywordforthBlocks +LOAD +THRU -->BLOCK-INCLUDED BLOCK-OFFSET 251syn keyword forthBlocks BLOCK -POSITION EMPTY-BUFFER GET-BLOCK-FID OPEN-BLOCKS 252syn keyword forthBlocks SAVE -BUFFER UPDATED? USE 253 254" The optional Double-Number word set {{{1 255syn keyword forthConversion D >S 256syn keyword forthDefine 2CONSTANT 2LITERAL 2VARIABLE 257syn keyword forthFunction D .D.R 258syn keyword forthOperators D +D- D0= D2* D2/ D= DABS DMAX DMIN DNEGATE 259syn keyword forthOperators D0 <D< M+ M*/ 260" extension words 261syn keyword forthDefine 2VALUE 262syn keyword forthOperators DU < 263syn keyword forthStack 2ROT 264 265" Non-standard Double-Number words 266syn keyword forthOperators D0 <=D0<> D0> D0>= D<= D<> D> D>= DU<= DU> DU>= 267syn keyword forthStack 2 -ROT 2NIP 2RDROP 2TUCK 268 269" The optional Exception word set {{{1 270" Handled as Core words - ABORT ABORT" 271syn keyword forthCond CATCH THROW 272 273" The optional Facility word set {{{1 274syn keyword forthCharOps AT -XY KEY? PAGE 275" extension words 276syn keyword forthCharOps EKEY EKEY >CHAR EKEY>FKEY EKEY? EMIT? K-ALT-MASK 277syn keyword forthCharOps K -CTRL-MASK K-DELETE K-DOWN K-END K-F1 K-F10 K-F11 278syn keyword forthCharOps K -F12 K-F2 K-F3 K-F4 K-F5 K-F6 K-F7 K-F8 K-F9 K-HOME 279syn keyword forthCharOps K -INSERT K-LEFT K-NEXT K-PRIOR K-RIGHT K-SHIFT-MASK 280syn keyword forthCharOps K -UP 281syn keywordforthDefine +FIELD BEGIN-STRUCTURE CFIELD: END-STRUCTURE FIELD: 282syn keyword forthForth MS TIME &DATE 283 284" The optional File-Access word set {{{1 285" Handled as Core words - REFILL SOURCE-ID S\" S" ( 286syn keyword forthFileMode BIN R /O R/W W/O 287syn keyword forthFileWords CLOSE -FILE CREATE-FILE DELETE-FILE FILE-POSITION 288syn keyword forthFileWords FILE -SIZE INCLUDE-FILE INCLUDED OPEN-FILE READ-FILE 289syn keyword forthFileWords READ -LINE REPOSITION-FILE RESIZE-FILE WRITE-FILE 290syn keyword forthFileWords WRITE -LINE 291" extension words 292syn keyword forthFileWords FILE -STATUS FLUSH-FILE RENAME-FILE REQUIRED 293syn match forthInclude '\<INCLUDE\s\+\k\+ ' 294syn match forthInclude '\<REQUIRE\s\+\k\+ ' 295 296" Non-standard File-Access words 297syn keyword forthFileWords EMIT -FILE KEY-FILE KEY?-FILE SLURP-FID SLURP-FILE 298syn keyword forthFileWords STDERR STDIN STDOUT 299syn match forthInclude '^FLOAD\s\+ ' 300syn match forthInclude '^NEEDS\s\+ ' 301 302" The optional Floating-Point word set {{{1 303 304" numbers 305syn match forthFloat '\< [ +- ] \=\d\+\.\=\d * [ DdEe ][ +- ] \=\d * \> ' 306 307syn keywordforthConversion >FLOAT D>F F>D 308syn keyword forthAdrArith FALIGN FALIGNED FLOAT +FLOATS 309syn keyword forthDefine FCONSTANT FLITERAL FVARIABLE 310syn keyword forthFStack FDROP FDUP FOVER FROT FSWAP 311syn keyword forthFunction REPRESENT 312syn keyword forthMemory F !F@ 313syn keyword forthOperators F *F+ F- F/ F0< F0= F< FLOOR FMAX FMIN FNEGATE 314syn keyword forthOperators FROUND 315syn keyword forthSP FDEPTH 316" extension words 317syn keyword forthConversion F >S S>F 318syn keyword forthAdrArith DFALIGN DFALIGNED DFLOAT +DFLOATS SFALIGN 319syn keyword forthAdrArith SFALIGNED SFLOAT +SFLOATS 320syn keyword forthDefine DFFIELD :FFIELD: FVALUE SFFIELD: 321syn keyword forthFunction F .FE. FS. PRECISION SET-PRECISION 322syn keyword forthMemory DF !DF@ SF! SF@ 323syn keyword forthOperators F **FABS FACOS FACOSH FALOG FASIN FASINH FATAN 324syn keyword forthOperators FATAN2 FATANH FCOS FCOSH FEXP FEXPM1 FLN FLNP1 325syn keyword forthOperators FLOG FSIN FSINCOS FSINH FSQRT FTAN FTANH FTRUNC F ~ 326 327" Non-standard Floating-Point words 328syn keyword forthOperators 1 /F F2* F2/ F~ABS F~REL 329syn keyword forthFStack FNIP FTUCK 330 331" The optional Locals word set {{{1 332syn keywordforthForth (LOCAL) 333" extension words 334syn region forthLocals start = "\<{:\> "end = "\<:}\> " 335syn region forthLocals start = "\<LOCALS|\> "end = "\<|\> " 336 337" Non-standard Locals words 338syn region forthLocals start = "\<{\> "end = "\<}\> " 339 340" The optional Memory-Allocation word set {{{1 341syn keyword forthMemory ALLOCATE FREE RESIZE 342 343" The optional Programming-Tools wordset {{{1 344syn keywordforthDebug .S ?DUMP SEE WORDS 345" extension words 346syn keywordforthAssembler ;CODE ASSEMBLER CODE END-CODE 347syn keyword forthCond AHEAD CS -PICK CS-ROLL 348syn keyword forthDefine NAME >COMPILE NAME>INTERPRET NAME>STRING SYNONYM 349syn keyword forthDefine TRAVERSE -WORDLIST 350syn match forthDefine "\<\[DEFINED]\> " 351syn match forthDefine "\<\[ELSE]\> " 352syn match forthDefine "\<\[IF]\> " 353syn match forthDefine "\<\[THEN]\> " 354syn match forthDefine "\<\[UNDEFINED]\> " 355syn keyword forthForth BYE FORGET 356syn keyword forthStack N >R NR> 357syn keyword forthVocs EDITOR 358 359" Non-standard Programming-Tools words 360syn keyword forthAssembler FLUSH -ICACHE 361syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE 362syn 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 {{{1 378" Handled as Core words - FIND 379syn keyword forthVocs DEFINITIONS FORTH -WORDLIST GET-CURRENT GET-ORDER 380syn keyword forthVocs SEARCH -WORDLIST SET-CURRENT SET-ORDER WORDLIST 381" extension words 382syn keyword forthVocs ALSO FORTH ONLY ORDER PREVIOUS 383" Forth-79, Forth-83 384syn keyword forthVocs CONTEXT CURRENT VOCABULARY 385 386" Non-standard Search-Order words 387syn keywordforthVocs #VOCS ROOT SEAL VOCS 388 389" The optional String word set {{{1 390syn keywordforthFunction -TRAILING /STRING BLANK CMOVE CMOVE> COMPARE SEARCH 391syn keyword forthFunction SLITERAL 392" extension words 393syn keyword forthFunction REPLACES SUBSTITUTE UNESCAPE 394 395" The optional Extended-Character word set {{{1 396" Handled as Core words - [CHAR] CHAR and PARSE 397syn 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 words 402syn keyword forthAdrArith XCHAR - +X/STRING X\\STRING- 403syn keyword forthCharOps EKEY >XCHAR X-WIDTH XC-WIDTH 404syn keyword forthConversion XHOLD 405syn keywordforthString -TRAILING-GARBAGE 406 407" Define the default highlighting {{{1 408hi def link forthBoolean Boolean 409hi def link forthCharacter Character 410hi def link forthTodo Todo 411hi def link forthOperators Operator 412hi def link forthMath Number 413hi def link forthInteger Number 414hi def link forthFloat Float 415hi def link forthStack Special 416hi def link forthRstack Special 417hi def link forthFStack Special 418hi def link forthSP Special 419hi def link forthMemory Function 420hi def link forthAdrArith Function 421hi def link forthMemBlks Function 422hi def link forthCond Conditional 423hi def link forthLoop Repeat 424hi def link forthColonDef Define 425hi def link forthEndOfColonDef Define 426hi def link forthDefine Define 427hi def link forthDebug Debug 428hi def link forthAssembler Include 429hi def link forthCharOps Character 430hi def link forthConversion String 431hi def link forthForth Statement 432hi def link forthVocs Statement 433hi def link forthEscape Special 434hi def link forthString String 435hi def link forthComment Comment 436hi def link forthClassDef Define 437hi def link forthEndOfClassDef Define 438hi def link forthObjectDef Define 439hi def link forthEndOfObjectDef Define 440hi def link forthInclude Include 441hi def link forthLocals Type " nothing else uses type and locals must stand out 442hi def link forthFileMode Function 443hi def link forthFunction Function 444hi def link forthFileWords Statement 445hi def link forthBlocks Statement 446hi def link forthSpaceError Error 447"}}} 448 449let b: current_syntax = "forth" 450 451let & cpo = s: cpo_save 452unlet s: cpo_save 453 454" vim:ts=8:sw=4:nocindent:smartindent:fdm=marker:tw=78 455