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