summaryrefslogtreecommitdiffstats
path: root/runtime/syntax/qb64.vim
blob: a777e144810526670ef0c3d3c8d2fd1b0867526a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
" Vim syntax file
" Language:	QB64
" Maintainer:	Doug Kearns <dougkearns@gmail.com>
" Last Change:	2022 Jan 21

" Prelude {{{1
if exists("b:current_syntax")
  finish
endif

let s:cpo_save = &cpo
set cpo&vim

" syn iskeyword set after sourcing of basic.vim

syn case ignore

let s:prefix = search('\c^\s*$NOPREFIX\>', 'n') ? '_\=' : '_'

" Statements {{{1

let s:statements =<< trim EOL " {{{2
  acceptfiledrop
  allowfullscreen
  assert
  console
  consolecursor
  consolefont
  consoletitle
  continue
  copypalette
  define
  delay
  depthbuffer
  displayorder
  dontblend
  echo
  exit\s\+\%(select\|case\)
  finishdrop
  freefont
  freeimage
  icon
  keyclear
  limit
  maptriangle
  memcopy
  memfill
  memfree
  memput
  mousehide
  mousemove
  mouseshow
  printimage
  printstring
  putimage
  screenclick
  screenhide
  screenmove
  screenprint
  screenshow
  setalpha
  sndbal
  sndclose
  sndlimit
  sndloop
  sndpause
  sndplay
  sndplaycopy
  sndplayfile
  sndraw
  sndrawdone
  sndsetpos
  sndstop
  sndvol
  title
EOL
" }}}

for s in s:statements
  exe 'syn match qb64Statement "\<' .. s:prefix .. s .. '\>" contained contains=qb64Underscore'
endfor

" Functions {{{1

let s:functions =<< trim EOL " {{{2
  acos
  acosh
  alpha
  alpha32
  arccot
  arccsc
  arcsec
  asin
  asinh
  atan2
  atanh
  axis
  backgroundcolor
  blue
  blue32
  button
  buttonchange
  ceil
  cinp
  commandcount
  connected
  connectionaddress
  connectionaddress$
  consoleinput
  copyimage
  cot
  coth
  cosh
  csc
  csch
  cv
  cwd$
  d2g
  d2r
  defaultcolor
  deflate$
  desktopheight
  desktopwidth
  device$
  deviceinput
  devices
  dir$
  direxists
  droppedfile
  droppedfile$
  errorline
  errormessage$
  exit
  fileexists
  fontheight
  fontwidth
  freetimer
  g2d
  g2r
  green
  green32
  height
  hypot
  inclerrorfile$
  inclerrorline
  inflate$
  instrrev
  keyhit
  keydown
  lastaxis
  lastbutton
  lastwheel
  loadfont
  loadimage
  mem
  memelement
  memexists
  memimage
  memnew
  memsound
  mk$
  mousebutton
  mouseinput
  mousemovementx
  mousemovementy
  mousepipeopen
  mousewheel
  mousex
  mousey
  newimage
  offset
  openclient
  os$
  pi
  pixelsize
  printwidth
  r2d
  r2g
  red
  red32
  readbit
  resetbit
  resizeheight
  resizewidth
  rgb
  rgb32
  rgba
  rgba32
  round
  sec
  sech
  screenexists
  screenimage
  screenx
  screeny
  setbit
  shellhide
  shl
  shr
  sinh
  sndcopy
  sndgetpos
  sndlen
  sndopen
  sndopenraw
  sndpaused
  sndplaying
  sndrate
  sndrawlen
  startdir$
  strcmp
  stricmp
  tanh
  title$
  togglebit
  totaldroppedfiles
  trim$
  wheel
  width
  windowhandle
  windowhasfocus
EOL
" }}}

for f in s:functions
  exe 'syn match qb64Function "\<' .. s:prefix .. f .. '\>" contains=qb64Underscore'
endfor

" Functions and statements (same name) {{{1

let s:common =<< trim EOL " {{{2
  autodisplay
  blend
  blink
  capslock
  clearcolor
  clipboard$
  clipboardimage
  controlchr
  dest
  display
  font
  fullscreen
  mapunicode
  memget
  numlock
  palettecolor
  printmode
  resize
  screenicon
  scrolllock
  source
EOL
" }}}

for c in s:common
  exe 'syn match qb64Statement "\<' .. s:prefix .. c .. '\>" contains=qb64Underscore contained'
  exe 'syn match qb64Function  "\<' .. s:prefix .. c .. '\>" contains=qb64Underscore'
endfor

" Keywords {{{1

" Non-prefixed keywords {{{2
" TIMER FREE
" _DEPTH_BUFFER LOCK
syn keyword qb64Keyword free lock

let s:keywords  =<< trim EOL " {{{2
  all
  anticlockwise
  behind
  clear
  clip
  console
  dontwait
  explicit
  explicitarray
  fillbackground
  hardware
  hardware1
  hide
  keepbackground
  middle
  none
  off
  only
  onlybackground
  ontop
  openconnection
  openhost
  preserve
  seamless
  smooth
  smoothshrunk
  smoothstretched
  software
  squarepixels
  stretch
  toggle
EOL
" }}}

for k in s:keywords
  exe 'syn match qb64Keyword "\<' .. s:prefix .. k .. '\>" contains=qb64Underscore'
endfor

syn match qb64Underscore "\<_" contained conceal transparent

" Source QuickBASIC syntax {{{1
runtime! syntax/basic.vim

" add after the BASIC syntax file is sourced so cluster already exists
syn cluster basicStatements	add=qb64Statement,qb64Metacommand,qb64IfMetacommand
syn cluster basicLineIdentifier add=qb64LineLabel
syn cluster qb64NotTop		contains=@basicNotTop,qb64Metavariable

syn iskeyword @,48-57,.,_,!,#,$,%,&,`

" Unsupported QuickBASIC features {{{1
" TODO: add linux only missing features
syn keyword qb64Unsupported alias any byval calls cdecl erdev erdev$ fileattr
syn keyword qb64Unsupported fre ioctl ioctl$ pen play setmem signal uevent
syn keyword qb64Unsupported tron troff
syn match   qb64Unsupported "\<declare\%(\s\+\%(sub\|function\)\>\)\@="
syn match   qb64Unsupported "\<\%(date\|time\)$\ze\s*=" " statements only
syn match   qb64Unsupported "\<def\zs\s\+FN"
syn match   qb64Unsupported "\<\%(exit\|end\)\s\+def\>"
syn match   qb64Unsupported "\<width\s\+lprint\>"

" Types {{{1
syn keyword qb64Type _BIT _BYTE _FLOAT _INTEGER64 _MEM _OFFSET _UNSIGNED

" Type suffixes {{{1
if exists("basic_type_suffixes")
  " TODO: handle leading word boundary and __+ prefix
  syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\~\=`\%(\d\+\)\="
  syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\~\=\%(%\|%%\|&\|&&\|%&\)"
  syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=\%(!\|##\|#\)"
  syn match qb64TypeSuffix "\%(\a[[:alnum:]._]*\)\@<=$\%(\d\+\)\="
endif

" Numbers {{{1

" Integers
syn match qb64Number "-\=&b[01]\+&\>\="

syn match qb64Number "-\=\<[01]\~\=`\>"
syn match qb64Number "-\=\<\d\+`\d\+\>"

syn match qb64Number "-\=\<\d\+\%(%%\|&&\|%&\)\>"
syn match qb64Number  "\<\d\+\~\%(%%\|&&\|%&\)\>"

syn match qb64Number "-\=\<&b[01]\+\%(%%\|&&\|%&\)\>"
syn match qb64Number  "\<&b[01]\+\~\%(%%\|&&\|%&\)\>"

syn match qb64Number "-\=\<&o\=\o\+\%(%%\|&&\|%&\)\>"
syn match qb64Number  "\<&o\=\o\+\~\%(%%\|&&\|%&\)\>"

syn match qb64Number "-\=\<&h\x\+\%(%%\|&&\|%&\)\>"
syn match qb64Number  "\<&h\x\+\~\%(%%\|&&\|%&\)\>"

" Floats
syn match qb64Float "-\=\<\d\+\.\=\d*##\>"
syn match qb64Float "-\=\<\.\d\+##\>"

" Line numbers and labels {{{1
syn match qb64LineLabel  "\%(_\{2,}\)\=\a[[:alnum:]._]*[[:alnum:]]\ze\s*:" nextgroup=@basicStatements skipwhite contained

" Metacommands {{{1
syn match qb64Metacommand contained "$NOPREFIX\>"
syn match qb64Metacommand contained "$ASSERTS\%(:CONSOLE\)\=\>"
syn match qb64Metacommand contained "$CHECKING:\%(ON\|OFF\)\>"
syn match qb64Metacommand contained "$COLOR:\%(0\|32\)\>"
syn match qb64Metacommand contained "$CONSOLE\%(:ONLY\)\=\>"
syn match qb64Metacommand contained "$EXEICON\s*:\s*'[^']\+'"
syn match qb64Metacommand contained "$ERROR\>"
syn match qb64Metacommand contained "$LET\>"
syn match qb64Metacommand contained "$RESIZE:\%(ON\|OFF\|STRETCH\|SMOOTH\)\>"
syn match qb64Metacommand contained "$SCREEN\%(HIDE\|SHOW\)\>"
syn match qb64Metacommand contained "$VERSIONINFO\s*:.*"
syn match qb64Metacommand contained "$VIRTUALKEYBOARD:\%(ON\|OFF\)\>"

syn region qb64IfMetacommand contained matchgroup=qb64Metacommand start="$\%(IF\|ELSEIF\)\>" end="\<THEN\>" oneline transparent contains=qb64Metavariable
syn match  qb64Metacommand contained "$\%(ELSE\|END\s*IF\)\>"

syn keyword qb64Metavariable contained defined undefined
syn keyword qb64Metavariable contained windows win linux mac maxosx
syn keyword qb64Metavariable contained 32bit 64bit version

" Default Highlighting {{{1
hi def link qb64Float	      basicFloat
hi def link qb64Function      Function
hi def link qb64Keyword       Keyword
hi def link qb64LineLabel     basicLineLabel
hi def link qb64Metacommand   PreProc
hi def link qb64Metavariable  Identifier
hi def link qb64Number	      basicNumber
hi def link qb64Statement     Statement
hi def link qb64TypeSuffix    basicTypeSuffix
hi def link qb64Type	      Type
hi def link qb64Unsupported   Error

" Postscript {{{1
let b:current_syntax = "qb64"

let &cpo = s:cpo_save
unlet s:cpo_save

" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: