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