codekingpro/portable-devtools
115k
1" Vim syntax file2" Language: BASIC (QuickBASIC 4.5)3" Maintainer: Doug Kearns <dougkearns@gmail.com>4" Previous Maintainer: Allan Kelly <allan@fruitloaf.co.uk>5" Contributors: Thilo Six6" Last Change: 2022 Jun 227 8" First version based on Micro$soft QBASIC circa 1989, as documented in9" 'Learn BASIC Now' by Halvorson&Rygmyr. Microsoft Press 1989.10"11" Second version attempts to match Microsoft QuickBASIC 4.5 while keeping FreeBASIC12" (-lang qb) and QB64 (excluding extensions) in mind. -- DJK13 14" Prelude {{{115if exists("b:current_syntax")16 finish17endif18 19let s:cpo_save = &cpo20set cpo&vim21 22syn iskeyword @,48-57,.,!,#,%,&,$23syn case ignore24 25" Whitespace Errors {{{126if exists("basic_space_errors")27 if !exists("basic_no_trail_space_error")28 syn match basicSpaceError display excludenl "\s\+$"29 endif30 if !exists("basic_no_tab_space_error")31 syn match basicSpaceError display " \+\t"me=e-132 endif33endif34 35" Comment Errors {{{136if !exists("basic_no_comment_errors")37 syn match basicCommentError "\<REM\>.*"38endif39 40" Not Top Cluster {{{141syn cluster basicNotTop contains=@basicLineIdentifier,basicDataString,basicDataSeparator,basicTodo42 43" Statements {{{144 45syn cluster basicStatements contains=basicStatement,basicDataStatement,basicMetaRemStatement,basicPutStatement,basicRemStatement46 47let s:statements =<< trim EOL " {{{248 beep49 bload50 bsave51 call52 calls53 case54 chain55 chdir56 circle57 clear58 close59 cls60 color61 com62 common63 const64 declare65 def66 def\s\+seg67 defdbl68 defint69 deflng70 defsng71 defstr72 dim73 do74 draw75 elseif76 end77 end\s\+\%(def\|function\|if\|select\|sub\|type\)78 environ79 erase80 error81 exit\s\+\%(def\|do\|for\|function\|sub\)82 field83 files84 for85 function86 get87 gosub88 goto89 if90 input91 ioctl92 key93 kill94 let95 line96 line\s\+input97 locate98 lock99 loop100 lprint101 lset102 mkdir103 name104 next105 on106 on\s\+error107 on\s\+uevent108 open109 open\s\+com110 option111 out112 paint113 palette114 palette\s\+using115 pcopy116 pen117 pmap118 poke119 preset120 print121 pset122 randomize123 read124 redim125 reset126 restore127 resume128 return129 rmdir130 rset131 run132 select\s\+case133 shared134 shell135 sleep136 sound137 static138 stop139 strig140 sub141 swap142 system143 troff144 tron145 type146 uevent147 unlock148 using149 view150 view\s\+print151 wait152 wend153 while154 width155 window156 write157EOL158" }}}159 160for s in s:statements161 exe 'syn match basicStatement "\<' .. s .. '\>" contained'162endfor163 164syn match basicStatement "\<\%(then\|else\)\>" nextgroup=@basicStatements skipwhite165 166" DATA Statement167syn match basicDataSeparator "," contained168syn region basicDataStatement matchgroup=basicStatement start="\<data\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicDataSeparator,basicDataString,basicNumber,basicFloat,basicString169 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 keepend172endif173 174" PUT File I/O and Graphics statements - needs special handling for graphics175" action verbs176syn match basicPutAction "\<\%(pset\|preset\|and\|or\|xor\)\>" contained177syn region basicPutStatement matchgroup=basicStatement start="\<put\>" matchgroup=basicStatementSeparator end=":\|$" contained contains=basicKeyword,basicPutAction,basicFilenumber178 179" Keywords {{{1180let s:keywords =<< trim EOL " {{{2181 absolute182 access183 alias184 append185 as186 base187 binary188 byval189 cdecl190 com191 def192 do193 for194 function195 gosub196 goto197 input198 int86old199 int86xold200 interrupt201 interruptx202 is203 key204 len205 list206 local207 lock208 lprint209 next210 off211 on212 output213 pen214 play215 random216 read217 resume218 screen219 seg220 shared221 signal222 static223 step224 stop225 strig226 sub227 timer228 to229 until230 using231 while232 write233EOL234" }}}235 236for k in s:keywords237 exe 'syn match basicKeyword "\<' .. k .. '\>"'238endfor239 240" Functions {{{1241syn keyword basicFunction abs asc atn cdbl chr$ cint clng command$ cos csng242syn keyword basicFunction csrlin cvd cvdmbf cvi cvl cvs cvsmbf environ$ eof243syn keyword basicFunction erdev erdev$ erl err exp fileattr fix fre freefile244syn keyword basicFunction hex$ inkey$ inp input$ instr int ioctl$ left$ lbound245syn keyword basicFunction lcase$ len loc lof log lpos ltrim$ mkd$ mkdmbf$ mki$246syn keyword basicFunction mkl$ mks$ mksmbf$ oct$ peek pen point pos right$ rnd247syn keyword basicFunction rtrim$ sadd setmem sgn sin space$ spc sqr stick str$248syn keyword basicFunction strig string$ tab tan ubound ucase$ val valptr249syn keyword basicFunction valseg varptr varptr$ varseg250 251" Functions and statements (same name) {{{1252syn match basicStatement "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>" contained253syn match basicFunction "\<\%(date\$\|mid\$\|play\|screen\|seek\|time\$\|timer\)\>"254 255" Types {{{1256syn keyword basicType integer long single double string any257 258" Strings {{{1259 260" Unquoted DATA strings - anything except [:,] and leading or trailing whitespace261" Needs lower priority than numbers262syn match basicDataString "[^[:space:],:]\+\%(\s\+[^[:space:],:]\+\)*" contained263 264syn region basicString start=+"+ end=+"+ oneline265 266" Booleans {{{1267if exists("basic_booleans")268 syn keyword basicBoolean true false269endif270 271" Numbers {{{1272 273" Integers274syn match basicNumber "-\=&o\=\o\+[%&]\=\>"275syn match basicNumber "-\=&h\x\+[%&]\=\>"276syn match basicNumber "-\=\<\d\+[%&]\=\>"277 278" Floats279syn match basicFloat "-\=\<\d\+\.\=\d*\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"280syn match basicFloat "-\=\<\.\d\+\%(\%([ed][+-]\=\d*\)\|[!#]\)\=\>"281 282" Statement anchors {{{1283syn match basicLineStart "^" nextgroup=@basicStatements,@basicLineIdentifier skipwhite284syn match basicStatementSeparator ":" nextgroup=@basicStatements skipwhite285 286" Line numbers and labels {{{1287 288" QuickBASIC limits these to 65,529 and 40 chars respectively289syn match basicLineNumber "\d\+" nextgroup=@basicStatements skipwhite contained290syn match basicLineLabel "\a[[:alnum:]]*\ze\s*:" nextgroup=@basicStatements skipwhite contained291 292syn cluster basicLineIdentifier contains=basicLineNumber,basicLineLabel293 294" Line Continuation {{{1295syn match basicLineContinuation "\s*\zs_\ze\s*$"296 297" Type suffixes {{{1298if exists("basic_type_suffixes")299 syn match basicTypeSuffix "\a[[:alnum:].]*\zs[$%&!#]"300endif301 302" File numbers {{{1303syn match basicFilenumber "#\d\+"304syn match basicFilenumber "#\a[[:alnum:].]*[%&!#]\="305 306" Operators {{{1307if exists("basic_operators")308 syn match basicArithmeticOperator "[-+*/\\^]"309 syn match basicRelationalOperator "<>\|<=\|>=\|[><=]"310endif311syn match basicLogicalOperator "\<\%(not\|and\|or\|xor\|eqv\|imp\)\>"312syn match basicArithmeticOperator "\<mod\>"313 314" Metacommands {{{1315" Note: No trailing word boundaries. Text may be freely mixed however there316" must be only leading whitespace prior to the first metacommand317syn match basicMetacommand "$INCLUDE\s*:\s*'[^']\+'" contained containedin=@basicMetaComments318syn match basicMetacommand "$\%(DYNAMIC\|STATIC\)" contained containedin=@basicMetaComments319 320" Comments {{{1321syn keyword basicTodo TODO FIXME XXX NOTE contained322 323syn region basicRemStatement matchgroup=basicStatement start="REM\>" end="$" contains=basicTodo,@Spell contained324syn region basicComment start="'" end="$" contains=basicTodo,@Spell325 326if !exists("basic_no_comment_fold")327 syn region basicMultilineComment start="^\s*'.*\n\%(\s*'\)\@=" end="^\s*'.*\n\%(\s*'\)\@!" contains=@basicComments transparent fold keepend328endif329 330" Metacommands331syn region basicMetaRemStatement matchgroup=basicStatement start="REM\>\s*\$\@=" end="$" contains=basicTodo contained332syn region basicMetaComment start="'\s*\$\@=" end="$" contains=basicTodo333 334syn cluster basicMetaComments contains=basicMetaComment,basicMetaRemStatement335syn cluster basicComments contains=basicComment,basicMetaComment336 337"syn sync ccomment basicComment338 339" Default Highlighting {{{1340hi def link basicArithmeticOperator basicOperator341hi def link basicBoolean Boolean342hi def link basicComment Comment343hi def link basicCommentError Error344hi def link basicDataString basicString345hi def link basicFilenumber basicTypeSuffix " TODO: better group346hi def link basicFloat Float347hi def link basicFunction Function348hi def link basicKeyword Keyword349hi def link basicLineIdentifier LineNr350hi def link basicLineContinuation Special351hi def link basicLineLabel basicLineIdentifier352hi def link basicLineNumber basicLineIdentifier353hi def link basicLogicalOperator basicOperator354hi def link basicMetacommand SpecialComment355hi def link basicMetaComment Comment356hi def link basicMetaRemStatement Comment357hi def link basicNumber Number358hi def link basicOperator Operator359hi def link basicPutAction Keyword360hi def link basicRelationalOperator basicOperator361hi def link basicRemStatement Comment362hi def link basicSpaceError Error363hi def link basicStatementSeparator Special364hi def link basicStatement Statement365hi def link basicString String366hi def link basicTodo Todo367hi def link basicType Type368hi def link basicTypeSuffix Special369if exists("basic_legacy_syntax_groups")370 hi def link basicTypeSpecifier Type371 hi def link basicTypeSuffix basicTypeSpecifier372endif373 374" Postscript {{{1375let b:current_syntax = "basic"376 377let &cpo = s:cpo_save378unlet s:cpo_save379 380" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:381 