robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
662681694b
master
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" ) 16finish 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" ) 27if ! exists ( "basic_no_trail_space_error" ) 28syn match basicSpaceError display excludenl "\s\+$ " 29endif 30if ! exists ( "basic_no_tab_space_error" ) 31syn match basicSpaceError display "\+\t "me= e-1 32endif 33endif 34 35" Comment Errors {{{1 36if ! exists ( "basic_no_comment_errors" ) 37syn 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 48beep 49bload 50bsave 51call 52calls 53case 54chain 55chdir 56circle 57clear 58close 59cls 60color 61com 62common 63const 64declare 65def 66def\s\+seg 67defdbl 68defint 69deflng 70defsng 71defstr 72dim 73do 74draw 75elseif 76end 77end\s\+\%(def\|function\|if\|select\|sub\|type\) 78environ 79erase 80error 81exit\s\+\%(def\|do\|for\|function\|sub\) 82field 83files 84for 85function 86get 87gosub 88goto 89if 90input 91ioctl 92key 93kill 94let 95line 96line\s\+input 97locate 98lock 99loop 100lprint 101lset 102mkdir 103name 104next 105on 106on\s\+error 107on\s\+uevent 108open 109open\s\+com 110option 111out 112paint 113palette 114palette\s\+using 115pcopy 116pen 117pmap 118poke 119preset 120pset 122randomize 123read 124redim 125reset 126restore 127resume 128return 129rmdir 130rset 131run 132select\s\+case 133shared 134shell 135sleep 136sound 137static 138stop 139strig 140sub 141swap 142system 143troff 144tron 145type 146uevent 147unlock 148using 149view 150view\s\+print 151wait 152wend 153while 154width 155window 156write 157EOL 158" }}} 159 160for s in s: statements 161exe '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" ) 171syn 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 181absolute 182access 183alias 184append 185as 186base 187binary 188byval 189cdecl 190com 191def 192do 193for 194function 195gosub 196goto 197input 198int86old 199int86xold 200interrupt 201interruptx 202is 203key 204len 205list 206local 207lock 208lprint 209next 210off 211on 212output 213pen 214play 215random 216read 217resume 218screen 219seg 220shared 221signal 222static 223step 224stop 225strig 226sub 227timer 228to 229until 230using 231while 232write 233EOL 234" }}} 235 236for k in s: keywords 237exe 'syn match basicKeyword "\<' .. k .. '\>"' 238endfor 239 240" Functions {{{1 241syn keyword basicFunction abs asc atn cdbl chr $ cint clngcommand $ 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" ) 268syn 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" ) 299syn 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" ) 308syn match basicArithmeticOperator "[ -+*/\\^ ] " 309syn 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" ) 327syn 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" ) 370hi def link basicTypeSpecifier Type 371hi 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: