blob: a777e144810526670ef0c3d3c8d2fd1b0867526a [file] [log] [blame]
Bram Moolenaarf10911e2022-01-29 22:20:48 +00001" Vim syntax file
2" Language: QB64
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Last Change: 2022 Jan 21
5
6" Prelude {{{1
7if exists("b:current_syntax")
8 finish
9endif
10
11let s:cpo_save = &cpo
12set cpo&vim
13
14" syn iskeyword set after sourcing of basic.vim
15
16syn case ignore
17
18let s:prefix = search('\c^\s*$NOPREFIX\>', 'n') ? '_\=' : '_'
19
20" Statements {{{1
21
22let s:statements =<< trim EOL " {{{2
23 acceptfiledrop
24 allowfullscreen
25 assert
26 console
27 consolecursor
28 consolefont
29 consoletitle
30 continue
31 copypalette
32 define
33 delay
34 depthbuffer
35 displayorder
36 dontblend
37 echo
38 exit\s\+\%(select\|case\)
39 finishdrop
40 freefont
41 freeimage
42 icon
43 keyclear
44 limit
45 maptriangle
46 memcopy
47 memfill
48 memfree
49 memput
50 mousehide
51 mousemove
52 mouseshow
53 printimage
54 printstring
55 putimage
56 screenclick
57 screenhide
58 screenmove
59 screenprint
60 screenshow
61 setalpha
62 sndbal
63 sndclose
64 sndlimit
65 sndloop
66 sndpause
67 sndplay
68 sndplaycopy
69 sndplayfile
70 sndraw
71 sndrawdone
72 sndsetpos
73 sndstop
74 sndvol
75 title
76EOL
77" }}}
78
79for s in s:statements
80 exe 'syn match qb64Statement "\<' .. s:prefix .. s .. '\>" contained contains=qb64Underscore'
81endfor
82
83" Functions {{{1
84
85let s:functions =<< trim EOL " {{{2
86 acos
87 acosh
88 alpha
89 alpha32
90 arccot
91 arccsc
92 arcsec
93 asin
94 asinh
95 atan2
96 atanh
97 axis
98 backgroundcolor
99 blue
100 blue32
101 button
102 buttonchange
103 ceil
104 cinp
105 commandcount
106 connected
107 connectionaddress
108 connectionaddress$
109 consoleinput
110 copyimage
111 cot
112 coth
113 cosh
114 csc
115 csch
116 cv
117 cwd$
118 d2g
119 d2r
120 defaultcolor
121 deflate$
122 desktopheight
123 desktopwidth
124 device$
125 deviceinput
126 devices
127 dir$
128 direxists
129 droppedfile
130 droppedfile$
131 errorline
132 errormessage$
133 exit
134 fileexists
135 fontheight
136 fontwidth
137 freetimer
138 g2d
139 g2r
140 green
141 green32
142 height
143 hypot
144 inclerrorfile$
145 inclerrorline
146 inflate$
147 instrrev
148 keyhit
149 keydown
150 lastaxis
151 lastbutton
152 lastwheel
153 loadfont
154 loadimage
155 mem
156 memelement
157 memexists
158 memimage
159 memnew
160 memsound
161 mk$
162 mousebutton
163 mouseinput
164 mousemovementx
165 mousemovementy
166 mousepipeopen
167 mousewheel
168 mousex
169 mousey
170 newimage
171 offset
172 openclient
173 os$
174 pi
175 pixelsize
176 printwidth
177 r2d
178 r2g
179 red
180 red32
181 readbit
182 resetbit
183 resizeheight
184 resizewidth
185 rgb
186 rgb32
187 rgba
188 rgba32
189 round
190 sec
191 sech
192 screenexists
193 screenimage
194 screenx
195 screeny
196 setbit
197 shellhide
198 shl
199 shr
200 sinh
201 sndcopy
202 sndgetpos
203 sndlen
204 sndopen
205 sndopenraw
206 sndpaused
207 sndplaying
208 sndrate
209 sndrawlen
210 startdir$
211 strcmp
212 stricmp
213 tanh
214 title$
215 togglebit
216 totaldroppedfiles
217 trim$
218 wheel
219 width
220 windowhandle
221 windowhasfocus
222EOL
223" }}}
224
225for f in s:functions
226 exe 'syn match qb64Function "\<' .. s:prefix .. f .. '\>" contains=qb64Underscore'
227endfor
228
229" Functions and statements (same name) {{{1
230
231let s:common =<< trim EOL " {{{2
232 autodisplay
233 blend
234 blink
235 capslock
236 clearcolor
237 clipboard$
238 clipboardimage
239 controlchr
240 dest
241 display
242 font
243 fullscreen
244 mapunicode
245 memget
246 numlock
247 palettecolor
248 printmode
249 resize
250 screenicon
251 scrolllock
252 source
253EOL
254" }}}
255
256for c in s:common
257 exe 'syn match qb64Statement "\<' .. s:prefix .. c .. '\>" contains=qb64Underscore contained'
258 exe 'syn match qb64Function "\<' .. s:prefix .. c .. '\>" contains=qb64Underscore'
259endfor
260
261" Keywords {{{1
262
263" Non-prefixed keywords {{{2
264" TIMER FREE
265" _DEPTH_BUFFER LOCK
266syn keyword qb64Keyword free lock
267
268let s:keywords =<< trim EOL " {{{2
269 all
270 anticlockwise
271 behind
272 clear
273 clip
274 console
275 dontwait
276 explicit
277 explicitarray
278 fillbackground
279 hardware
280 hardware1
281 hide
282 keepbackground
283 middle
284 none
285 off
286 only
287 onlybackground
288 ontop
289 openconnection
290 openhost
291 preserve
292 seamless
293 smooth
294 smoothshrunk
295 smoothstretched
296 software
297 squarepixels
298 stretch
299 toggle
300EOL
301" }}}
302
303for k in s:keywords
304 exe 'syn match qb64Keyword "\<' .. s:prefix .. k .. '\>" contains=qb64Underscore'
305endfor
306
307syn match qb64Underscore "\<_" contained conceal transparent
308
309" Source QuickBASIC syntax {{{1
310runtime! syntax/basic.vim
311
312" add after the BASIC syntax file is sourced so cluster already exists
313syn cluster basicStatements add=qb64Statement,qb64Metacommand,qb64IfMetacommand
314syn cluster basicLineIdentifier add=qb64LineLabel
315syn cluster qb64NotTop contains=@basicNotTop,qb64Metavariable
316
317syn iskeyword @,48-57,.,_,!,#,$,%,&,`
318
319" Unsupported QuickBASIC features {{{1
320" TODO: add linux only missing features
321syn keyword qb64Unsupported alias any byval calls cdecl erdev erdev$ fileattr
322syn keyword qb64Unsupported fre ioctl ioctl$ pen play setmem signal uevent
323syn keyword qb64Unsupported tron troff
324syn match qb64Unsupported "\<declare\%(\s\+\%(sub\|function\)\>\)\@="
325syn match qb64Unsupported "\<\%(date\|time\)$\ze\s*=" " statements only
326syn match qb64Unsupported "\<def\zs\s\+FN"
327syn match qb64Unsupported "\<\%(exit\|end\)\s\+def\>"
328syn match qb64Unsupported "\<width\s\+lprint\>"
329
330" Types {{{1
331syn keyword qb64Type _BIT _BYTE _FLOAT _INTEGER64 _MEM _OFFSET _UNSIGNED
332
333" Type suffixes {{{1
334if exists("basic_type_suffixes")
335 " TODO: handle leading word boundary and __+ prefix
336 syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\~\=`\%(\d\+\)\="
337 syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\~\=\%(%\|%%\|&\|&&\|%&\)"
338 syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\%(!\|##\|#\)"
339 syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=$\%(\d\+\)\="
340endif
341
342" Numbers {{{1
343
344" Integers
345syn match qb64Number "-\=&b[01]\+&\>\="
346
347syn match qb64Number "-\=\<[01]\~\=`\>"
348syn match qb64Number "-\=\<\d\+`\d\+\>"
349
350syn match qb64Number "-\=\<\d\+\%(%%\|&&\|%&\)\>"
351syn match qb64Number "\<\d\+\~\%(%%\|&&\|%&\)\>"
352
353syn match qb64Number "-\=\<&b[01]\+\%(%%\|&&\|%&\)\>"
354syn match qb64Number "\<&b[01]\+\~\%(%%\|&&\|%&\)\>"
355
356syn match qb64Number "-\=\<&o\=\o\+\%(%%\|&&\|%&\)\>"
357syn match qb64Number "\<&o\=\o\+\~\%(%%\|&&\|%&\)\>"
358
359syn match qb64Number "-\=\<&h\x\+\%(%%\|&&\|%&\)\>"
360syn match qb64Number "\<&h\x\+\~\%(%%\|&&\|%&\)\>"
361
362" Floats
363syn match qb64Float "-\=\<\d\+\.\=\d*##\>"
364syn match qb64Float "-\=\<\.\d\+##\>"
365
366" Line numbers and labels {{{1
367syn match qb64LineLabel "\%(_\{2,}\)\=\a[[:alnum:]._]*[[:alnum:]]\ze\s*:" nextgroup=@basicStatements skipwhite contained
368
369" Metacommands {{{1
370syn match qb64Metacommand contained "$NOPREFIX\>"
371syn match qb64Metacommand contained "$ASSERTS\%(:CONSOLE\)\=\>"
372syn match qb64Metacommand contained "$CHECKING:\%(ON\|OFF\)\>"
373syn match qb64Metacommand contained "$COLOR:\%(0\|32\)\>"
374syn match qb64Metacommand contained "$CONSOLE\%(:ONLY\)\=\>"
375syn match qb64Metacommand contained "$EXEICON\s*:\s*'[^']\+'"
376syn match qb64Metacommand contained "$ERROR\>"
377syn match qb64Metacommand contained "$LET\>"
378syn match qb64Metacommand contained "$RESIZE:\%(ON\|OFF\|STRETCH\|SMOOTH\)\>"
379syn match qb64Metacommand contained "$SCREEN\%(HIDE\|SHOW\)\>"
380syn match qb64Metacommand contained "$VERSIONINFO\s*:.*"
381syn match qb64Metacommand contained "$VIRTUALKEYBOARD:\%(ON\|OFF\)\>"
382
383syn region qb64IfMetacommand contained matchgroup=qb64Metacommand start="$\%(IF\|ELSEIF\)\>" end="\<THEN\>" oneline transparent contains=qb64Metavariable
384syn match qb64Metacommand contained "$\%(ELSE\|END\s*IF\)\>"
385
386syn keyword qb64Metavariable contained defined undefined
387syn keyword qb64Metavariable contained windows win linux mac maxosx
388syn keyword qb64Metavariable contained 32bit 64bit version
389
390" Default Highlighting {{{1
391hi def link qb64Float basicFloat
392hi def link qb64Function Function
393hi def link qb64Keyword Keyword
394hi def link qb64LineLabel basicLineLabel
395hi def link qb64Metacommand PreProc
396hi def link qb64Metavariable Identifier
397hi def link qb64Number basicNumber
398hi def link qb64Statement Statement
399hi def link qb64TypeSuffix basicTypeSuffix
400hi def link qb64Type Type
401hi def link qb64Unsupported Error
402
403" Postscript {{{1
404let b:current_syntax = "qb64"
405
406let &cpo = s:cpo_save
407unlet s:cpo_save
408
409" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: