home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / dos / syntax / forth.vim < prev    next >
Encoding:
Text File  |  2012-05-31  |  13.5 KB  |  348 lines

  1. " Vim syntax file
  2. " Language:    FORTH
  3. " Maintainer:  Christian V. J. Brⁿssow <cvjb@cvjb.de>
  4. " Last Change: So 27 Mai 2012 15:56:28 CEST
  5. " Filenames:   *.fs,*.ft
  6. " URL:           http://www.cvjb.de/comp/vim/forth.vim
  7.  
  8. " $Id: forth.vim,v 1.14 2012/05/27 15:57:22 bruessow Exp $
  9.  
  10. " The list of keywords is incomplete, compared with the official ANS
  11. " wordlist. If you use this language, please improve it, and send me
  12. " the patches.
  13. "
  14. " Before sending me patches, please download the newest version of this file
  15. " from http://www.cvjb.de/comp/vim/forth.vim or http://www.vim.org/ (search
  16. " for forth.vim).
  17.  
  18. " Many Thanks to...
  19. "
  20. " 2012-05-13:
  21. " Dominique PellΘ <dominique dot pelle at gmail dot com> for sending the
  22. " patch to allow spellchecking of strings, comments, ...
  23. " 2012-01-07:
  24. " Thilo Six <T.Six at gmx dot de> send a patch for cpoptions.
  25. " See the discussion at http://thread.gmane.org/gmane.editors.vim.devel/32151
  26. "
  27. " 2009-06-28:
  28. " Josh Grams send a patch to allow the parenthesis comments at the
  29. " beginning of a line. That patch also fixed a typo in one of the
  30. " comments.
  31. "
  32. " 2008-02-09:
  33. " Shawn K. Quinn <sjquinn at speakeasy dot net> send a big patch with
  34. " new words commonly used in Forth programs or defined by GNU Forth.
  35. "
  36. " 2007-07-11:
  37. " Benjamin Krill <ben at codiert dot org> send me a patch
  38. " to highlight space errors.
  39. " You can toggle this feature on through setting the
  40. " flag forth_space_errors in you vimrc. If you have switched it on,
  41. " you can turn off highlighting of trailing spaces in comments by
  42. " setting forth_no_trail_space_error in your vimrc. If you do not want
  43. " the highlighting of a tabulator following a space in comments, you
  44. " can turn this off by setting forth_no_tab_space_error.
  45. "
  46. " 2006-05-25:
  47. " Bill McCarthy <WJMc@...> and Ilya Sher <ilya-vim@...>
  48. " Who found a bug in the ccomment line in 2004!!!
  49. " I'm really very sorry, that it has taken two years to fix that
  50. " in the official version of this file. Shame on me.
  51. " I think my face will be red the next ten years...
  52. "
  53. " 2006-05-21:
  54. " Thomas E. Vaughan <tevaugha at ball dot com> send me a patch
  55. " for the parenthesis comment word, so words with a trailing
  56. " parenthesis will not start the highlighting for such comments.
  57. "
  58. " 2003-05-10:
  59. " Andrew Gaul <andrew at gaul.org> send me a patch for
  60. " forthOperators.
  61. "
  62. " 2003-04-03:
  63. " Ron Aaron <ron at ronware dot org> made updates for an
  64. " improved Win32Forth support.
  65. "
  66. " 2002-04-22:
  67. " Charles Shattuck <charley at forth dot org> helped me to settle up with the
  68. " binary and hex number highlighting.
  69. "
  70. " 2002-04-20:
  71. " Charles Shattuck <charley at forth dot org> send me some code for correctly
  72. " highlighting char and [char] followed by an opening paren. He also added
  73. " some words for operators, conditionals, and definitions; and added the
  74. " highlighting for s" and c".
  75. "
  76. " 2000-03-28:
  77. " John Providenza <john at probo dot com> made improvements for the
  78. " highlighting of strings, and added the code for highlighting hex numbers.
  79. "
  80.  
  81.  
  82. " For version 5.x: Clear all syntax items
  83. " For version 6.x: Quit when a syntax file was already loaded
  84. if version < 600
  85.     syntax clear
  86. elseif exists("b:current_syntax")
  87.     finish
  88. endif
  89.  
  90. let s:cpo_save = &cpo
  91. set cpo&vim
  92.  
  93. " Synchronization method
  94. syn sync ccomment
  95. syn sync maxlines=200
  96.  
  97. " I use gforth, so I set this to case ignore
  98. syn case ignore
  99.  
  100. " Some special, non-FORTH keywords
  101. syn keyword forthTodo contained TODO FIXME XXX
  102. syn match forthTodo contained 'Copyright\(\s([Cc])\)\=\(\s[0-9]\{2,4}\)\='
  103.  
  104. " Characters allowed in keywords
  105. " I don't know if 128-255 are allowed in ANS-FORTH
  106. if version >= 600
  107.     setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
  108. else
  109.     set iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
  110. endif
  111.  
  112. " when wanted, highlight trailing white space
  113. if exists("forth_space_errors")
  114.     if !exists("forth_no_trail_space_error")
  115.         syn match forthSpaceError display excludenl "\s\+$"
  116.     endif
  117.     if !exists("forth_no_tab_space_error")
  118.         syn match forthSpaceError display " \+\t"me=e-1
  119.     endif
  120. endif
  121.  
  122. " Keywords
  123.  
  124. " basic mathematical and logical operators
  125. syn keyword forthOperators + - * / MOD /MOD NEGATE ABS MIN MAX
  126. syn keyword forthOperators AND OR XOR NOT LSHIFT RSHIFT INVERT 2* 2/ 1+
  127. syn keyword forthOperators 1- 2+ 2- 8* UNDER+
  128. syn keyword forthOperators M+ */ */MOD M* UM* M*/ UM/MOD FM/MOD SM/REM
  129. syn keyword forthOperators D+ D- DNEGATE DABS DMIN DMAX D2* D2/
  130. syn keyword forthOperators F+ F- F* F/ FNEGATE FABS FMAX FMIN FLOOR FROUND
  131. syn keyword forthOperators F** FSQRT FEXP FEXPM1 FLN FLNP1 FLOG FALOG FSIN
  132. syn keyword forthOperators FCOS FSINCOS FTAN FASIN FACOS FATAN FATAN2 FSINH
  133. syn keyword forthOperators FCOSH FTANH FASINH FACOSH FATANH F2* F2/ 1/F
  134. syn keyword forthOperators F~REL F~ABS F~
  135. syn keyword forthOperators 0< 0<= 0<> 0= 0> 0>= < <= <> = > >= U< U<=
  136. syn keyword forthOperators U> U>= D0< D0<= D0<> D0= D0> D0>= D< D<= D<>
  137. syn keyword forthOperators D= D> D>= DU< DU<= DU> DU>= WITHIN ?NEGATE
  138. syn keyword forthOperators ?DNEGATE
  139.  
  140. " stack manipulations
  141. syn keyword forthStack DROP NIP DUP OVER TUCK SWAP ROT -ROT ?DUP PICK ROLL
  142. syn keyword forthStack 2DROP 2NIP 2DUP 2OVER 2TUCK 2SWAP 2ROT 2-ROT
  143. syn keyword forthStack 3DUP 4DUP 5DUP 3DROP 4DROP 5DROP 8DROP 4SWAP 4ROT
  144. syn keyword forthStack 4-ROT 4TUCK 8SWAP 8DUP
  145. syn keyword forthRStack >R R> R@ RDROP 2>R 2R> 2R@ 2RDROP
  146. syn keyword forthRstack 4>R 4R> 4R@ 4RDROP
  147. syn keyword forthFStack FDROP FNIP FDUP FOVER FTUCK FSWAP FROT
  148.  
  149. " stack pointer manipulations
  150. syn keyword forthSP SP@ SP! FP@ FP! RP@ RP! LP@ LP!
  151.  
  152. " address operations
  153. syn keyword forthMemory @ ! +! C@ C! 2@ 2! F@ F! SF@ SF! DF@ DF!
  154. syn keyword forthAdrArith CHARS CHAR+ CELLS CELL+ CELL ALIGN ALIGNED FLOATS
  155. syn keyword forthAdrArith FLOAT+ FLOAT FALIGN FALIGNED SFLOATS SFLOAT+
  156. syn keyword forthAdrArith SFALIGN SFALIGNED DFLOATS DFLOAT+ DFALIGN DFALIGNED
  157. syn keyword forthAdrArith MAXALIGN MAXALIGNED CFALIGN CFALIGNED
  158. syn keyword forthAdrArith ADDRESS-UNIT-BITS ALLOT ALLOCATE HERE
  159. syn keyword forthMemBlks MOVE ERASE CMOVE CMOVE> FILL BLANK
  160.  
  161. " conditionals
  162. syn keyword forthCond IF ELSE ENDIF THEN CASE OF ENDOF ENDCASE ?DUP-IF
  163. syn keyword forthCond ?DUP-0=-IF AHEAD CS-PICK CS-ROLL CATCH THROW WITHIN
  164.  
  165. " iterations
  166. syn keyword forthLoop BEGIN WHILE REPEAT UNTIL AGAIN
  167. syn keyword forthLoop ?DO LOOP I J K +DO U+DO -DO U-DO DO +LOOP -LOOP
  168. syn keyword forthLoop UNLOOP LEAVE ?LEAVE EXIT DONE FOR NEXT
  169.  
  170. " new words
  171. syn match forthClassDef '\<:class\s*[^ \t]\+\>'
  172. syn match forthObjectDef '\<:object\s*[^ \t]\+\>'
  173. syn match forthColonDef '\<:m\?\s*[^ \t]\+\>'
  174. syn keyword forthEndOfColonDef ; ;M ;m
  175. syn keyword forthEndOfClassDef ;class
  176. syn keyword forthEndOfObjectDef ;object
  177. syn keyword forthDefine CONSTANT 2CONSTANT FCONSTANT VARIABLE 2VARIABLE
  178. syn keyword forthDefine FVARIABLE CREATE USER VALUE TO DEFER IS DOES> IMMEDIATE
  179. syn keyword forthDefine COMPILE-ONLY COMPILE RESTRICT INTERPRET POSTPONE EXECUTE
  180. syn keyword forthDefine LITERAL CREATE-INTERPRET/COMPILE INTERPRETATION>
  181. syn keyword forthDefine <INTERPRETATION COMPILATION> <COMPILATION ] LASTXT
  182. syn keyword forthDefine COMP' POSTPONE, FIND-NAME NAME>INT NAME?INT NAME>COMP
  183. syn keyword forthDefine NAME>STRING STATE C; CVARIABLE
  184. syn keyword forthDefine , 2, F, C,
  185. syn match forthDefine "\[IFDEF]"
  186. syn match forthDefine "\[IFUNDEF]"
  187. syn match forthDefine "\[THEN]"
  188. syn match forthDefine "\[ENDIF]"
  189. syn match forthDefine "\[ELSE]"
  190. syn match forthDefine "\[?DO]"
  191. syn match forthDefine "\[DO]"
  192. syn match forthDefine "\[LOOP]"
  193. syn match forthDefine "\[+LOOP]"
  194. syn match forthDefine "\[NEXT]"
  195. syn match forthDefine "\[BEGIN]"
  196. syn match forthDefine "\[UNTIL]"
  197. syn match forthDefine "\[AGAIN]"
  198. syn match forthDefine "\[WHILE]"
  199. syn match forthDefine "\[REPEAT]"
  200. syn match forthDefine "\[COMP']"
  201. syn match forthDefine "'"
  202. syn match forthDefine '\<\[\>'
  203. syn match forthDefine "\[']"
  204. syn match forthDefine '\[COMPILE]'
  205.  
  206. " debugging
  207. syn keyword forthDebug PRINTDEBUGDATA PRINTDEBUGLINE
  208. syn match forthDebug "\<\~\~\>"
  209.  
  210. " Assembler
  211. syn keyword forthAssembler ASSEMBLER CODE END-CODE ;CODE FLUSH-ICACHE C,
  212.  
  213. " basic character operations
  214. syn keyword forthCharOps (.) CHAR EXPECT FIND WORD TYPE -TRAILING EMIT KEY
  215. syn keyword forthCharOps KEY? TIB CR
  216. " recognize 'char (' or '[char] (' correctly, so it doesn't
  217. " highlight everything after the paren as a comment till a closing ')'
  218. syn match forthCharOps '\<char\s\S\s'
  219. syn match forthCharOps '\<\[char\]\s\S\s'
  220. syn region forthCharOps start=+."\s+ skip=+\\"+ end=+"+
  221.  
  222. " char-number conversion
  223. syn keyword forthConversion <<# <# # #> #>> #S (NUMBER) (NUMBER?) CONVERT D>F
  224. syn keyword forthConversion D>S DIGIT DPL F>D HLD HOLD NUMBER S>D SIGN >NUMBER
  225. syn keyword forthConversion F>S S>F
  226.  
  227. " interpreter, wordbook, compiler
  228. syn keyword forthForth (LOCAL) BYE COLD ABORT >BODY >NEXT >LINK CFA >VIEW HERE
  229. syn keyword forthForth PAD WORDS VIEW VIEW> N>LINK NAME> LINK> L>NAME FORGET
  230. syn keyword forthForth BODY> ASSERT( ASSERT0( ASSERT1( ASSERT2( ASSERT3( )
  231. syn region forthForth start=+ABORT"\s+ skip=+\\"+ end=+"+
  232.  
  233. " vocabularies
  234. syn keyword forthVocs ONLY FORTH ALSO ROOT SEAL VOCS ORDER CONTEXT #VOCS
  235. syn keyword forthVocs VOCABULARY DEFINITIONS
  236.  
  237. " File keywords
  238. syn keyword forthFileMode R/O R/W W/O BIN
  239. syn keyword forthFileWords OPEN-FILE CREATE-FILE CLOSE-FILE DELETE-FILE
  240. syn keyword forthFileWords RENAME-FILE READ-FILE READ-LINE KEY-FILE
  241. syn keyword forthFileWords KEY?-FILE WRITE-FILE WRITE-LINE EMIT-FILE
  242. syn keyword forthFileWords FLUSH-FILE FILE-STATUS FILE-POSITION
  243. syn keyword forthFileWords REPOSITION-FILE FILE-SIZE RESIZE-FILE
  244. syn keyword forthFileWords SLURP-FILE SLURP-FID STDIN STDOUT STDERR
  245. syn keyword forthBlocks OPEN-BLOCKS USE LOAD --> BLOCK-OFFSET
  246. syn keyword forthBlocks GET-BLOCK-FID BLOCK-POSITION LIST SCR BLOCK
  247. syn keyword forthBlocks BUFER EMPTY-BUFFERS EMPTY-BUFFER UPDATE UPDATED?
  248. syn keyword forthBlocks SAVE-BUFFERS SAVE-BUFFER FLUSH THRU +LOAD +THRU
  249. syn keyword forthBlocks BLOCK-INCLUDED
  250.  
  251. " numbers
  252. syn keyword forthMath DECIMAL HEX BASE
  253. syn match forthInteger '\<-\=[0-9.]*[0-9.]\+\>'
  254. syn match forthInteger '\<&-\=[0-9.]*[0-9.]\+\>'
  255. " recognize hex and binary numbers, the '$' and '%' notation is for gforth
  256. syn match forthInteger '\<\$\x*\x\+\>' " *1* --- dont't mess
  257. syn match forthInteger '\<\x*\d\x*\>'  " *2* --- this order!
  258. syn match forthInteger '\<%[0-1]*[0-1]\+\>'
  259. syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe]\d\+\>'
  260. syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe][-+]\d\+\>'
  261.  
  262. " XXX If you find this overkill you can remove it. This has to come after the
  263. " highlighting for numbers otherwise it has no effect.
  264. syn region forthComment start='0 \[if\]' end='\[endif\]' end='\[then\]' contains=forthTodo
  265.  
  266. " Strings
  267. syn region forthString start=+\.*\"+ end=+"+ end=+$+ contains=@Spell
  268. " XXX
  269. syn region forthString start=+s\"+ end=+"+ end=+$+ contains=@Spell
  270. syn region forthString start=+c\"+ end=+"+ end=+$+ contains=@Spell
  271.  
  272. " Comments
  273. syn match forthComment '\\\s.*$' contains=@Spell,forthTodo,forthSpaceError
  274. syn region forthComment start='\\S\s' end='.*' contains=@Spell,forthTodo,forthSpaceError
  275. syn match forthComment '\.(\s[^)]*)' contains=@Spell,forthTodo,forthSpaceError
  276. syn region forthComment start='\(^\|\s\)\zs(\s' skip='\\)' end=')' contains=@Spell,forthTodo,forthSpaceError
  277. syn region forthComment start='/\*' end='\*/' contains=@Spell,forthTodo,forthSpaceError
  278.  
  279. " Include files
  280. syn match forthInclude '^INCLUDE\s\+\k\+'
  281. syn match forthInclude '^require\s\+\k\+'
  282. syn match forthInclude '^fload\s\+'
  283. syn match forthInclude '^needs\s\+'
  284.  
  285. " Locals definitions
  286. syn region forthLocals start='{\s' start='{$' end='\s}' end='^}'
  287. syn match forthLocals '{ }' " otherwise, at least two spaces between
  288. syn region forthDeprecated start='locals|' end='|'
  289.  
  290. " Define the default highlighting.
  291. " For version 5.7 and earlier: only when not done already
  292. " For version 5.8 and later: only when an item doesn't have highlighting yet
  293. if version >= 508 || !exists("did_forth_syn_inits")
  294.     if version < 508
  295.     let did_forth_syn_inits = 1
  296.     command -nargs=+ HiLink hi link <args>
  297.     else
  298.     command -nargs=+ HiLink hi def link <args>
  299.     endif
  300.  
  301.     " The default methods for highlighting. Can be overridden later.
  302.     HiLink forthTodo Todo
  303.     HiLink forthOperators Operator
  304.     HiLink forthMath Number
  305.     HiLink forthInteger Number
  306.     HiLink forthFloat Float
  307.     HiLink forthStack Special
  308.     HiLink forthRstack Special
  309.     HiLink forthFStack Special
  310.     HiLink forthSP Special
  311.     HiLink forthMemory Function
  312.     HiLink forthAdrArith Function
  313.     HiLink forthMemBlks Function
  314.     HiLink forthCond Conditional
  315.     HiLink forthLoop Repeat
  316.     HiLink forthColonDef Define
  317.     HiLink forthEndOfColonDef Define
  318.     HiLink forthDefine Define
  319.     HiLink forthDebug Debug
  320.     HiLink forthAssembler Include
  321.     HiLink forthCharOps Character
  322.     HiLink forthConversion String
  323.     HiLink forthForth Statement
  324.     HiLink forthVocs Statement
  325.     HiLink forthString String
  326.     HiLink forthComment Comment
  327.     HiLink forthClassDef Define
  328.     HiLink forthEndOfClassDef Define
  329.     HiLink forthObjectDef Define
  330.     HiLink forthEndOfObjectDef Define
  331.     HiLink forthInclude Include
  332.     HiLink forthLocals Type " nothing else uses type and locals must stand out
  333.     HiLink forthDeprecated Error " if you must, change to Type
  334.     HiLink forthFileMode Function
  335.     HiLink forthFileWords Statement
  336.     HiLink forthBlocks Statement
  337.     HiLink forthSpaceError Error
  338.  
  339.     delcommand HiLink
  340. endif
  341.  
  342. let b:current_syntax = "forth"
  343.  
  344. let &cpo = s:cpo_save
  345. unlet s:cpo_save
  346. " vim:ts=8:sw=4:nocindent:smartindent:
  347.