robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:0d878b95d8f9 (#19197)662681694b

master
9.2 KiB380 linesraw
1" Vim syntax file
2" Language:		BASIC (QuickBASIC 4.5)
3" Maintainer:		Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer:	Allan Kelly <allan@fruitloaf.co.uk>
5" Contributors:		Thilo Six
6" Last Change:		2022 Jun 22
7
8" First version based on Micro$soft QBASIC circa 1989, as documented in
9" 'Learn BASIC Now' by Halvorson&Rygmyr. Microsoft Press 1989.
10"
11" Second version attempts to match Microsoft QuickBASIC 4.5 while keeping FreeBASIC
12" (-lang qb) and QB64 (excluding extensions) in mind. -- DJK
13
14" Prelude {{{1
15if exists("b:current_syntax")
16  finish
17endif
18
19let s:cpo_save = &cpo
20set cpo&vim
21
22syn iskeyword @,48-57,.,!,#,%,&,$
23syn case      ignore
24
25" Whitespace Errors {{{1
26if exists("basic_space_errors")
27  if !exists("basic_no_trail_space_error")
28    syn match basicSpaceError display excludenl "\s\+$"
29  endif
30  if !exists("basic_no_tab_space_error")
31    syn match basicSpaceError display " \+\t"me=e-1
32  endif
33endif
34
35" Comment Errors {{{1
36if !exists("basic_no_comment_errors")
37  syn match basicCommentError "\<REM\>.*"
38endif
39
40" Not Top Cluster {{{1
41syn cluster basicNotTop contains=@basicLineIdentifier,basicDataString,basicDataSeparator,basicTodo
42
43" Statements {{{1
44
45syn cluster basicStatements contains=basicStatement,basicDataStatement,basicMetaRemStatement,basicPutStatement,basicRemStatement
46
47let s:statements =<< trim EOL " {{{2
48  beep
49  bload
50  bsave
51  call
52  calls
53  case
54  chain
55  chdir
56  circle
57  clear
58  close
59  cls
60  color
61  com
62  common
63  const
64  declare
65  def
66  def\s\+seg
67  defdbl
68  defint
69  deflng
70  defsng
71  defstr
72  dim
73  do
74  draw
75  elseif
76  end
77  end\s\+\%(def\|function\|if\|select\|sub\|type\)
78  environ
79  erase
80  error
81  exit\s\+\%(def\|do\|for\|function\|sub\)
82  field
83  files
84  for
85  function
86  get
87  gosub
88  goto
89  if
90  input
91  ioctl
92  key
93  kill
94  let
95  line
96  line\s\+input
97  locate
98  lock
99  loop
100  lprint
101  lset
102  mkdir
103  name
104  next
105  on
106  on\s\+error
107  on\s\+uevent
108  open
109  open\s\+com
110  option
111  out
112  paint
113  palette
114  palette\s\+using
115  pcopy
116  pen
117  pmap
118  poke
119  preset
120  print
121  pset
122  randomize
123  read
124  redim
125  reset
126  restore
127  resume
128  return
129  rmdir
130  rset
131  run
132  select\s\+case
133  shared
134  shell
135  sleep
136  sound
137  static
138  stop
139  strig
140  sub
141  swap
142  system
143  troff
144  tron
145  type
146  uevent
147  unlock
148  using
149  view
150  view\s\+print
151  wait
152  wend
153  while
154  width
155  window
156  write
157EOL
158" }}}
159
160for s in s:statements
161  exe 'syn match basicStatement "\<' .. s .. '\>" contained'
162endfor
163
164syn match basicStatement "\<\%(then\|else\)\>" nextgroup=@basicStatements skipwhite
165
166" DATA Statement
167syn match  basicDataSeparator "," contained
168syn region basicDataStatement matchgroup=basicStatement start="\<data\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicDataSeparator,basicDataString,basicNumber,basicFloat,basicString
169
170if !exists("basic_no_data_fold")
171  syn region basicMultilineData start="^\s*\<data\>.*\n\%(^\s*\<data\>\)\@=" end="^\s*\<data\>.*\n\%(^\s*\<data\>\)\@!" contains=basicDataStatement transparent fold keepend
172endif
173
174" PUT File I/O and Graphics statements - needs special handling for graphics
175" action verbs
176syn match  basicPutAction "\<\%(pset\|preset\|and\|or\|xor\)\>" contained
177syn region basicPutStatement matchgroup=basicStatement start="\<put\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicKeyword,basicPutAction,basicFilenumber
178
179" Keywords {{{1
180let s:keywords =<< trim EOL " {{{2
181  absolute
182  access
183  alias
184  append
185  as
186  base
187  binary
188  byval
189  cdecl
190  com
191  def
192  do
193  for
194  function
195  gosub
196  goto
197  input
198  int86old
199  int86xold
200  interrupt
201  interruptx
202  is
203  key
204  len
205  list
206  local
207  lock
208  lprint
209  next
210  off
211  on
212  output
213  pen
214  play
215  random
216  read
217  resume
218  screen
219  seg
220  shared
221  signal
222  static
223  step
224  stop
225  strig
226  sub
227  timer
228  to
229  until
230  using
231  while
232  write
233EOL
234" }}}
235
236for k in s:keywords
237  exe 'syn match basicKeyword "\<' .. k .. '\>"'
238endfor
239
240" Functions {{{1
241syn keyword basicFunction abs asc atn cdbl chr$ cint clng command$ cos csng
242syn keyword basicFunction csrlin cvd cvdmbf cvi cvl cvs cvsmbf environ$ eof
243syn keyword basicFunction erdev erdev$ erl err exp fileattr fix fre freefile
244syn keyword basicFunction hex$ inkey$ inp input$ instr int ioctl$ left$ lbound
245syn keyword basicFunction lcase$ len loc lof log lpos ltrim$ mkd$ mkdmbf$ mki$
246syn keyword basicFunction mkl$ mks$ mksmbf$ oct$ peek pen point pos right$ rnd
247syn keyword basicFunction rtrim$ sadd setmem sgn sin space$ spc sqr stick str$
248syn keyword basicFunction strig string$ tab tan ubound ucase$ val valptr
249syn keyword basicFunction valseg varptr varptr$ varseg
250
251" Functions and statements (same name) {{{1
252syn match   basicStatement "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>" contained
253syn match   basicFunction  "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>"
254
255" Types {{{1
256syn keyword basicType integer long single double string any
257
258" Strings {{{1
259
260" Unquoted DATA strings - anything except [:,] and leading or trailing whitespace
261" Needs lower priority than numbers
262syn match basicDataString "[^[:space:],:]\+\%(\s\+[^[:space:],:]\+\)*" contained
263
264syn region basicString start=+"+ end=+"+ oneline
265
266" Booleans {{{1
267if exists("basic_booleans")
268  syn keyword basicBoolean true false
269endif
270
271" Numbers {{{1
272
273" Integers
274syn match basicNumber "-\=&o\=\o\+[%&]\=\>"
275syn match basicNumber "-\=&h\x\+[%&]\=\>"
276syn match basicNumber "-\=\<\d\+[%&]\=\>"
277
278" Floats
279syn match basicFloat "-\=\<\d\+\.\=\d*\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
280syn match basicFloat      "-\=\<\.\d\+\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
281
282" Statement anchors {{{1
283syn match basicLineStart	  "^" nextgroup=@basicStatements,@basicLineIdentifier skipwhite
284syn match basicStatementSeparator ":" nextgroup=@basicStatements		      skipwhite
285
286" Line numbers and labels {{{1
287
288" QuickBASIC limits these to 65,529 and 40 chars respectively
289syn match basicLineNumber "\d\+"		  nextgroup=@basicStatements skipwhite contained
290syn match basicLineLabel  "\a[[:alnum:]]*\ze\s*:" nextgroup=@basicStatements skipwhite contained
291
292syn cluster basicLineIdentifier contains=basicLineNumber,basicLineLabel
293
294" Line Continuation {{{1
295syn match basicLineContinuation "\s*\zs_\ze\s*$"
296
297" Type suffixes {{{1
298if exists("basic_type_suffixes")
299  syn match basicTypeSuffix "\a[[:alnum:].]*\zs[$%&!#]"
300endif
301
302" File numbers {{{1
303syn match basicFilenumber "#\d\+"
304syn match basicFilenumber "#\a[[:alnum:].]*[%&!#]\="
305
306" Operators {{{1
307if exists("basic_operators")
308  syn match basicArithmeticOperator "[-+*/\\^]"
309  syn match basicRelationalOperator "<>\|<=\|>=\|[><=]"
310endif
311syn match basicLogicalOperator	  "\<\%(not\|and\|or\|xor\|eqv\|imp\)\>"
312syn match basicArithmeticOperator "\<mod\>"
313
314" Metacommands {{{1
315" Note: No trailing word boundaries.  Text may be freely mixed however there
316" must be only leading whitespace prior to the first metacommand
317syn match basicMetacommand "$INCLUDE\s*:\s*'[^']\+'" contained containedin=@basicMetaComments
318syn match basicMetacommand "$\%(DYNAMIC\|STATIC\)"   contained containedin=@basicMetaComments
319
320" Comments {{{1
321syn keyword basicTodo TODO FIXME XXX NOTE contained
322
323syn region basicRemStatement matchgroup=basicStatement start="REM\>" end="$" contains=basicTodo,@Spell contained
324syn region basicComment				       start="'"     end="$" contains=basicTodo,@Spell
325
326if !exists("basic_no_comment_fold")
327  syn region basicMultilineComment start="^\s*'.*\n\%(\s*'\)\@=" end="^\s*'.*\n\%(\s*'\)\@!" contains=@basicComments transparent fold keepend
328endif
329
330" Metacommands
331syn region  basicMetaRemStatement matchgroup=basicStatement start="REM\>\s*\$\@=" end="$" contains=basicTodo contained
332syn region  basicMetaComment				    start="'\s*\$\@="	  end="$" contains=basicTodo
333
334syn cluster basicMetaComments contains=basicMetaComment,basicMetaRemStatement
335syn cluster basicComments     contains=basicComment,basicMetaComment
336
337"syn sync ccomment basicComment
338
339" Default Highlighting {{{1
340hi def link basicArithmeticOperator basicOperator
341hi def link basicBoolean	    Boolean
342hi def link basicComment	    Comment
343hi def link basicCommentError	    Error
344hi def link basicDataString	    basicString
345hi def link basicFilenumber	    basicTypeSuffix " TODO: better group
346hi def link basicFloat		    Float
347hi def link basicFunction	    Function
348hi def link basicKeyword	    Keyword
349hi def link basicLineIdentifier	    LineNr
350hi def link basicLineContinuation   Special
351hi def link basicLineLabel	    basicLineIdentifier
352hi def link basicLineNumber	    basicLineIdentifier
353hi def link basicLogicalOperator    basicOperator
354hi def link basicMetacommand	    SpecialComment
355hi def link basicMetaComment	    Comment
356hi def link basicMetaRemStatement   Comment
357hi def link basicNumber		    Number
358hi def link basicOperator	    Operator
359hi def link basicPutAction	    Keyword
360hi def link basicRelationalOperator basicOperator
361hi def link basicRemStatement	    Comment
362hi def link basicSpaceError	    Error
363hi def link basicStatementSeparator Special
364hi def link basicStatement	    Statement
365hi def link basicString		    String
366hi def link basicTodo		    Todo
367hi def link basicType		    Type
368hi def link basicTypeSuffix	    Special
369if exists("basic_legacy_syntax_groups")
370  hi def link basicTypeSpecifier      Type
371  hi def link basicTypeSuffix	      basicTypeSpecifier
372endif
373
374" Postscript {{{1
375let b:current_syntax = "basic"
376
377let &cpo = s:cpo_save
378unlet s:cpo_save
379
380" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: