vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

basic.vim (9410B)


      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
     15 if exists("b:current_syntax")
     16   finish
     17 endif
     18 
     19 let s:cpo_save = &cpo
     20 set cpo&vim
     21 
     22 syn iskeyword @,48-57,.,!,#,%,&,$
     23 syn case      ignore
     24 
     25 " Whitespace Errors {{{1
     26 if 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
     33 endif
     34 
     35 " Comment Errors {{{1
     36 if !exists("basic_no_comment_errors")
     37   syn match basicCommentError "\<REM\>.*"
     38 endif
     39 
     40 " Not Top Cluster {{{1
     41 syn cluster basicNotTop contains=@basicLineIdentifier,basicDataString,basicDataSeparator,basicTodo
     42 
     43 " Statements {{{1
     44 
     45 syn cluster basicStatements contains=basicStatement,basicDataStatement,basicMetaRemStatement,basicPutStatement,basicRemStatement
     46 
     47 let 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
    157 EOL
    158 " }}}
    159 
    160 for s in s:statements
    161   exe 'syn match basicStatement "\<' .. s .. '\>" contained'
    162 endfor
    163 
    164 syn match basicStatement "\<\%(then\|else\)\>" nextgroup=@basicStatements skipwhite
    165 
    166 " DATA Statement
    167 syn match  basicDataSeparator "," contained
    168 syn region basicDataStatement matchgroup=basicStatement start="\<data\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicDataSeparator,basicDataString,basicNumber,basicFloat,basicString
    169 
    170 if !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
    172 endif
    173 
    174 " PUT File I/O and Graphics statements - needs special handling for graphics
    175 " action verbs
    176 syn match  basicPutAction "\<\%(pset\|preset\|and\|or\|xor\)\>" contained
    177 syn region basicPutStatement matchgroup=basicStatement start="\<put\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicKeyword,basicPutAction,basicFilenumber
    178 
    179 " Keywords {{{1
    180 let 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
    233 EOL
    234 " }}}
    235 
    236 for k in s:keywords
    237   exe 'syn match basicKeyword "\<' .. k .. '\>"'
    238 endfor
    239 
    240 " Functions {{{1
    241 syn keyword basicFunction abs asc atn cdbl chr$ cint clng command$ cos csng
    242 syn keyword basicFunction csrlin cvd cvdmbf cvi cvl cvs cvsmbf environ$ eof
    243 syn keyword basicFunction erdev erdev$ erl err exp fileattr fix fre freefile
    244 syn keyword basicFunction hex$ inkey$ inp input$ instr int ioctl$ left$ lbound
    245 syn keyword basicFunction lcase$ len loc lof log lpos ltrim$ mkd$ mkdmbf$ mki$
    246 syn keyword basicFunction mkl$ mks$ mksmbf$ oct$ peek pen point pos right$ rnd
    247 syn keyword basicFunction rtrim$ sadd setmem sgn sin space$ spc sqr stick str$
    248 syn keyword basicFunction strig string$ tab tan ubound ucase$ val valptr
    249 syn keyword basicFunction valseg varptr varptr$ varseg
    250 
    251 " Functions and statements (same name) {{{1
    252 syn match   basicStatement "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>" contained
    253 syn match   basicFunction  "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>"
    254 
    255 " Types {{{1
    256 syn 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
    262 syn match basicDataString "[^[:space:],:]\+\%(\s\+[^[:space:],:]\+\)*" contained
    263 
    264 syn region basicString start=+"+ end=+"+ oneline
    265 
    266 " Booleans {{{1
    267 if exists("basic_booleans")
    268   syn keyword basicBoolean true false
    269 endif
    270 
    271 " Numbers {{{1
    272 
    273 " Integers
    274 syn match basicNumber "-\=&o\=\o\+[%&]\=\>"
    275 syn match basicNumber "-\=&h\x\+[%&]\=\>"
    276 syn match basicNumber "-\=\<\d\+[%&]\=\>"
    277 
    278 " Floats
    279 syn match basicFloat "-\=\<\d\+\.\=\d*\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
    280 syn match basicFloat      "-\=\<\.\d\+\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"
    281 
    282 " Statement anchors {{{1
    283 syn match basicLineStart	  "^" nextgroup=@basicStatements,@basicLineIdentifier skipwhite
    284 syn match basicStatementSeparator ":" nextgroup=@basicStatements		      skipwhite
    285 
    286 " Line numbers and labels {{{1
    287 
    288 " QuickBASIC limits these to 65,529 and 40 chars respectively
    289 syn match basicLineNumber "\d\+"		  nextgroup=@basicStatements skipwhite contained
    290 syn match basicLineLabel  "\a[[:alnum:]]*\ze\s*:" nextgroup=@basicStatements skipwhite contained
    291 
    292 syn cluster basicLineIdentifier contains=basicLineNumber,basicLineLabel
    293 
    294 " Line Continuation {{{1
    295 syn match basicLineContinuation "\s*\zs_\ze\s*$"
    296 
    297 " Type suffixes {{{1
    298 if exists("basic_type_suffixes")
    299   syn match basicTypeSuffix "\a[[:alnum:].]*\zs[$%&!#]"
    300 endif
    301 
    302 " File numbers {{{1
    303 syn match basicFilenumber "#\d\+"
    304 syn match basicFilenumber "#\a[[:alnum:].]*[%&!#]\="
    305 
    306 " Operators {{{1
    307 if exists("basic_operators")
    308   syn match basicArithmeticOperator "[-+*/\\^]"
    309   syn match basicRelationalOperator "<>\|<=\|>=\|[><=]"
    310 endif
    311 syn match basicLogicalOperator	  "\<\%(not\|and\|or\|xor\|eqv\|imp\)\>"
    312 syn 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
    317 syn match basicMetacommand "$INCLUDE\s*:\s*'[^']\+'" contained containedin=@basicMetaComments
    318 syn match basicMetacommand "$\%(DYNAMIC\|STATIC\)"   contained containedin=@basicMetaComments
    319 
    320 " Comments {{{1
    321 syn keyword basicTodo TODO FIXME XXX NOTE contained
    322 
    323 syn region basicRemStatement matchgroup=basicStatement start="REM\>" end="$" contains=basicTodo,@Spell contained
    324 syn region basicComment				       start="'"     end="$" contains=basicTodo,@Spell
    325 
    326 if !exists("basic_no_comment_fold")
    327   syn region basicMultilineComment start="^\s*'.*\n\%(\s*'\)\@=" end="^\s*'.*\n\%(\s*'\)\@!" contains=@basicComments transparent fold keepend
    328 endif
    329 
    330 " Metacommands
    331 syn region  basicMetaRemStatement matchgroup=basicStatement start="REM\>\s*\$\@=" end="$" contains=basicTodo contained
    332 syn region  basicMetaComment				    start="'\s*\$\@="	  end="$" contains=basicTodo
    333 
    334 syn cluster basicMetaComments contains=basicMetaComment,basicMetaRemStatement
    335 syn cluster basicComments     contains=basicComment,basicMetaComment
    336 
    337 "syn sync ccomment basicComment
    338 
    339 " Default Highlighting {{{1
    340 hi def link basicArithmeticOperator basicOperator
    341 hi def link basicBoolean	    Boolean
    342 hi def link basicComment	    Comment
    343 hi def link basicCommentError	    Error
    344 hi def link basicDataString	    basicString
    345 hi def link basicFilenumber	    basicTypeSuffix " TODO: better group
    346 hi def link basicFloat		    Float
    347 hi def link basicFunction	    Function
    348 hi def link basicKeyword	    Keyword
    349 hi def link basicLineIdentifier	    LineNr
    350 hi def link basicLineContinuation   Special
    351 hi def link basicLineLabel	    basicLineIdentifier
    352 hi def link basicLineNumber	    basicLineIdentifier
    353 hi def link basicLogicalOperator    basicOperator
    354 hi def link basicMetacommand	    SpecialComment
    355 hi def link basicMetaComment	    Comment
    356 hi def link basicMetaRemStatement   Comment
    357 hi def link basicNumber		    Number
    358 hi def link basicOperator	    Operator
    359 hi def link basicPutAction	    Keyword
    360 hi def link basicRelationalOperator basicOperator
    361 hi def link basicRemStatement	    Comment
    362 hi def link basicSpaceError	    Error
    363 hi def link basicStatementSeparator Special
    364 hi def link basicStatement	    Statement
    365 hi def link basicString		    String
    366 hi def link basicTodo		    Todo
    367 hi def link basicType		    Type
    368 hi def link basicTypeSuffix	    Special
    369 if exists("basic_legacy_syntax_groups")
    370   hi def link basicTypeSpecifier      Type
    371   hi def link basicTypeSuffix	      basicTypeSpecifier
    372 endif
    373 
    374 " Postscript {{{1
    375 let b:current_syntax = "basic"
    376 
    377 let &cpo = s:cpo_save
    378 unlet s:cpo_save
    379 
    380 " vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker: