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