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