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
|
" Vim syntax file
" Language: BASIC (QuickBASIC 4.5)
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Allan Kelly <allan@fruitloaf.co.uk>
" Contributors: Thilo Six
" Last Change: 2022 Jun 22
" First version based on Micro$soft QBASIC circa 1989, as documented in
" 'Learn BASIC Now' by Halvorson&Rygmyr. Microsoft Press 1989.
"
" Second version attempts to match Microsoft QuickBASIC 4.5 while keeping FreeBASIC
" (-lang qb) and QB64 (excluding extensions) in mind. -- DJK
" Prelude {{{1
if exists("b:current_syntax")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
syn iskeyword @,48-57,.,!,#,%,&,$
syn case ignore
" Whitespace Errors {{{1
if exists("basic_space_errors")
if !exists("basic_no_trail_space_error")
syn match basicSpaceError display excludenl "\s\+$"
endif
if !exists("basic_no_tab_space_error")
syn match basicSpaceError display " \+\t"me=e-1
endif
endif
" Comment Errors {{{1
if !exists("basic_no_comment_errors")
syn match basicCommentError "\<REM\>.*"
endif
" Not Top Cluster {{{1
syn cluster basicNotTop contains=@basicLineIdentifier,basicDataString,basicDataSeparator,basicTodo
" Statements {{{1
syn cluster basicStatements contains=basicStatement,basicDataStatement,basicMetaRemStatement,basicPutStatement,basicRemStatement
let s:statements =<< trim EOL " {{{2
beep
bload
bsave
call
calls
case
chain
chdir
circle
clear
close
cls
color
com
common
const
declare
def
def\s\+seg
defdbl
defint
deflng
defsng
defstr
dim
do
draw
elseif
end
end\s\+\%(def\|function\|if\|select\|sub\|type\)
environ
erase
error
exit\s\+\%(def\|do\|for\|function\|sub\)
field
files
for
function
get
gosub
goto
if
input
ioctl
key
kill
let
line
line\s\+input
locate
lock
loop
lprint
lset
mkdir
name
next
on
on\s\+error
on\s\+uevent
open
open\s\+com
option
out
paint
palette
palette\s\+using
pcopy
pen
pmap
poke
preset
print
pset
randomize
read
redim
reset
restore
resume
return
rmdir
rset
run
select\s\+case
shared
shell
sleep
sound
static
stop
strig
sub
swap
system
troff
tron
type
uevent
unlock
using
view
view\s\+print
wait
wend
while
width
window
write
EOL
" }}}
for s in s:statements
exe 'syn match basicStatement "\<' .. s .. '\>" contained'
endfor
syn match basicStatement "\<\%(then\|else\)\>" nextgroup=@basicStatements skipwhite
" DATA Statement
syn match basicDataSeparator "," contained
syn region basicDataStatement matchgroup=basicStatement start="\<data\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicDataSeparator,basicDataString,basicNumber,basicFloat,basicString
if !exists("basic_no_data_fold")
syn region basicMultilineData start="^\s*\<data\>.*\n\%(^\s*\<data\>\)\@=" end="^\s*\<data\>.*\n\%(^\s*\<data\>\)\@!" contains=basicDataStatement transparent fold keepend
endif
" PUT File I/O and Graphics statements - needs special handling for graphics
" action verbs
syn match basicPutAction "\<\%(pset\|preset\|and\|or\|xor\)\>" contained
syn region basicPutStatement matchgroup=basicStatement start="\<put\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicKeyword,basicPutAction,basicFilenumber
" Keywords {{{1
let s:keywords =<< trim EOL " {{{2
absolute
access
alias
append
as
base
binary
byval
cdecl
com
def
do
for
function
gosub
goto
input
int86old
int86xold
interrupt
interruptx
is
key
len
list
local
lock
lprint
next
off
on
output
pen
play
random
read
resume
screen
seg
shared
signal
static
step
stop
strig
sub
timer
to
until
using
while
write
EOL
" }}}
for k in s:keywords
exe 'syn match basicKeyword "\<' .. k .. '\>"'
endfor
" Functions {{{1
syn keyword basicFunction abs asc atn cdbl chr$ cint clng command$ cos csng
syn keyword basicFunction csrlin cvd cvdmbf cvi cvl cvs cvsmbf environ$ eof
syn keyword basicFunction erdev erdev$ erl err exp fileattr fix fre freefile
syn keyword basicFunction hex$ inkey$ inp input$ instr int ioctl$ left$ lbound
syn keyword basicFunction lcase$ len loc lof log lpos ltrim$ mkd$ mkdmbf$ mki$
syn keyword basicFunction mkl$ mks$ mksmbf$ oct$ peek pen point pos right$ rnd
syn keyword basicFunction rtrim$ sadd setmem sgn sin space$ spc sqr stick str$
syn keyword basicFunction strig string$ tab tan ubound ucase$ val valptr
syn keyword basicFunction valseg varptr varptr$ varseg
" Functions and statements (same name) {{{1
syn match basicStatement "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>" contained
syn match basicFunction "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>"
" Types {{{1
syn keyword basicType integer long single double string any
" Strings {{{1
" Unquoted DATA strings - anything except [:,] and leading or trailing whitespace
" Needs lower priority than numbers
syn match basicDataString "[^[:space:],:]\+\%(\s\+[^[:space:],:]\+\)*" contained
syn region basicString start=+"+ end=+"+ oneline
" Booleans {{{1
if exists("basic_booleans")
syn keyword basicBoolean true false
endif
" Numbers {{{1
" Integers
syn match basicNumber "-\=&o\=\o\+[%&]\=\>"
syn match basicNumber "-\=&h\x\+[%&]\=\>"
syn match basicNumber "-\=\<\d\+[%&]\=\>"
" Floats
syn match basicFloat "-\=\<\d\+\.\=\d*\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
syn match basicFloat "-\=\<\.\d\+\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
" Statement anchors {{{1
syn match basicLineStart "^" nextgroup=@basicStatements,@basicLineIdentifier skipwhite
syn match basicStatementSeparator ":" nextgroup=@basicStatements skipwhite
" Line numbers and labels {{{1
" QuickBASIC limits these to 65,529 and 40 chars respectively
syn match basicLineNumber "\d\+" nextgroup=@basicStatements skipwhite contained
syn match basicLineLabel "\a[[:alnum:]]*\ze\s*:" nextgroup=@basicStatements skipwhite contained
syn cluster basicLineIdentifier contains=basicLineNumber,basicLineLabel
" Line Continuation {{{1
syn match basicLineContinuation "\s*\zs_\ze\s*$"
" Type suffixes {{{1
if exists("basic_type_suffixes")
syn match basicTypeSuffix "\a[[:alnum:].]*\zs[$%&!#]"
endif
" File numbers {{{1
syn match basicFilenumber "#\d\+"
syn match basicFilenumber "#\a[[:alnum:].]*[%&!#]\="
" Operators {{{1
if exists("basic_operators")
syn match basicArithmeticOperator "[-+*/\\^]"
syn match basicRelationalOperator "<>\|<=\|>=\|[><=]"
endif
syn match basicLogicalOperator "\<\%(not\|and\|or\|xor\|eqv\|imp\)\>"
syn match basicArithmeticOperator "\<mod\>"
" Metacommands {{{1
" Note: No trailing word boundaries. Text may be freely mixed however there
" must be only leading whitespace prior to the first metacommand
syn match basicMetacommand "$INCLUDE\s*:\s*'[^']\+'" contained containedin=@basicMetaComments
syn match basicMetacommand "$\%(DYNAMIC\|STATIC\)" contained containedin=@basicMetaComments
" Comments {{{1
syn keyword basicTodo TODO FIXME XXX NOTE contained
syn region basicRemStatement matchgroup=basicStatement start="REM\>" end="$" contains=basicTodo,@Spell contained
syn region basicComment start="'" end="$" contains=basicTodo,@Spell
if !exists("basic_no_comment_fold")
syn region basicMultilineComment start="^\s*'.*\n\%(\s*'\)\@=" end="^\s*'.*\n\%(\s*'\)\@!" contains=@basicComments transparent fold keepend
endif
" Metacommands
syn region basicMetaRemStatement matchgroup=basicStatement start="REM\>\s*\$\@=" end="$" contains=basicTodo contained
syn region basicMetaComment start="'\s*\$\@=" end="$" contains=basicTodo
syn cluster basicMetaComments contains=basicMetaComment,basicMetaRemStatement
syn cluster basicComments contains=basicComment,basicMetaComment
"syn sync ccomment basicComment
" Default Highlighting {{{1
hi def link basicArithmeticOperator basicOperator
hi def link basicBoolean Boolean
hi def link basicComment Comment
hi def link basicCommentError Error
hi def link basicDataString basicString
hi def link basicFilenumber basicTypeSuffix " TODO: better group
hi def link basicFloat Float
hi def link basicFunction Function
hi def link basicKeyword Keyword
hi def link basicLineIdentifier LineNr
hi def link basicLineContinuation Special
hi def link basicLineLabel basicLineIdentifier
hi def link basicLineNumber basicLineIdentifier
hi def link basicLogicalOperator basicOperator
hi def link basicMetacommand SpecialComment
hi def link basicMetaComment Comment
hi def link basicMetaRemStatement Comment
hi def link basicNumber Number
hi def link basicOperator Operator
hi def link basicPutAction Keyword
hi def link basicRelationalOperator basicOperator
hi def link basicRemStatement Comment
hi def link basicSpaceError Error
hi def link basicStatementSeparator Special
hi def link basicStatement Statement
hi def link basicString String
hi def link basicTodo Todo
hi def link basicType Type
hi def link basicTypeSuffix Special
if exists("basic_legacy_syntax_groups")
hi def link basicTypeSpecifier Type
hi def link basicTypeSuffix basicTypeSpecifier
endif
" Postscript {{{1
let b:current_syntax = "basic"
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
|