MasterBASIC Vim syntax file
Description of the page content
Vim syntax file for MasterBASIC.
I wrote this Vim syntax file (based on SuperBASIC Vim syntax file) as part of my project to write MasterBASIC programs using Vim, my favourite editor. But so far (2011-09) no method to migrate the source code into the MasterBASIC interpreter has succeeded.
Source code
" masterbasic.vim
" Vim syntax file
" Language: SAM Coupé's MasterBASIC with MasterDOS
" Author: Marcos Cruz (programandala.net)
" License: Vim license (GPL compatible)
" URL: http://programandala.net
" Updated: 2015-02-26
" -------------------------------------------------------------
" Changelog
" 2011-03-09: First version
" (based on superbasic.vim by the same author).
" 2011-03-11: FPAGES added.
" 2011-08-06: Added the iskeyword Vim variable, from superbasic.vim. Added the source-only hash-comments. Some fixes.
" 2011-08-07: Fixed: Qualifiers were not highlighted.
" 2011-08-08: Added the hash metacomments.
" 2011-08-12: Fixed: a single dash in their own line was not highlighted as meta comment.
" 2011-09-01: Hash metacomments moved to the addon mbim.vim sintax file (MBim: MasterBASIC improved).
" 2012-09-03: Moved the editing preferences to a filetype plugin.
" 2012-11-16: Fixed: 'else' was repeated: structure keyword and command.
" 2012-11-17: Fixed: 'do' and 'for' were in the command group, not the structure group.
" 2012-11-20: Fixed: 'stop', 'goto' and 'gosub' were in the command group, not the structure group.
" 2012-12-06: New: xxx, todo, fixme.
" 2012-12-07: Fixed: 'bor' is an operator, not a function.
" 2012-12-20: New: 'xos', 'yos', 'xrg', 'yrg'.
" 2013-01-08: New: hex numbers.
" 2013-01-09: Change: 'masterbasicMathsOperator' linked to 'Operator'.
" 2014-06-29: Fix: now math operator keywords are parsed apart;
" otherwise they are not highlighted at the start of a splitted source line.
" 2014-07-24: Fixes: matches with ending dollar (e.g. 'TIME$') are converted to
" keywords. Matches with inner space (e.g. 'DEF PROC') didn't have the word
" limits marks ('\<' and '\>').
" 2014-08-02: Fix: now 'rem' is highlighted only at the start of the line or
" after a colon.
" 2014-10-19: Fix: 'rem' was not highlighted after a line number.
" 2015-02-26: Vim license.
" -------------------------------------------------------------
" To-do
" Finish the colors
" Test.
" Fix: the code commented out is highlighted as metacomments when tabs are used for indentation.
" -------------------------------------------------------------
" For Vim version 5.x: Clear all syntax items
" For Vim version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
if version > 600
setlocal iskeyword=48-57,65-90,97-122,_,$,%
else
set iskeyword=48-57,65-90,97-122,_,$,%
endif
syn case ignore
" -------------------------------------------------------------
" Functions
syn keyword masterbasicFunction ABS
syn keyword masterbasicFunction ACS
syn keyword masterbasicFunction ASN
syn keyword masterbasicFunction ATN
syn keyword masterbasicFunction ATTR
syn keyword masterbasicFunction BIN$
syn keyword masterbasicFunction BUTTON
syn keyword masterbasicFunction CHR$
syn keyword masterbasicFunction CODE
syn keyword masterbasicFunction COS
syn keyword masterbasicFunction DATE$
syn keyword masterbasicFunction DIR$
syn keyword masterbasicFunction DIV
syn keyword masterbasicFunction DPEEK
syn keyword masterbasicFunction DSTAT
syn keyword masterbasicFunction DVAR
syn keyword masterbasicFunction EOF
syn keyword masterbasicFunction EQU
syn keyword masterbasicFunction EXP
syn keyword masterbasicFunction FN
syn keyword masterbasicFunction FPAGES
syn keyword masterbasicFunction FREE
syn keyword masterbasicFunction FSTAT
syn keyword masterbasicFunction HEX$
syn keyword masterbasicFunction IN
syn keyword masterbasicFunction INARRAY
syn keyword masterbasicFunction INKEY$
syn keyword masterbasicFunction INP$
syn keyword masterbasicFunction INSTR
syn keyword masterbasicFunction INT
syn keyword masterbasicFunction ITEM
syn keyword masterbasicFunction LEN
syn keyword masterbasicFunction LENGTH
syn keyword masterbasicFunction LN
syn keyword masterbasicFunction LOCN
syn keyword masterbasicFunction MEM$
syn keyword masterbasicFunction NOT
syn keyword masterbasicFunction NVAL
syn keyword masterbasicFunction PATH$
syn keyword masterbasicFunction PEEK
syn keyword masterbasicFunction PI
syn keyword masterbasicFunction POINT
syn keyword masterbasicFunction PTR
syn keyword masterbasicFunction RAMTOP
syn keyword masterbasicFunction RESERVED
syn keyword masterbasicFunction RND
syn keyword masterbasicFunction SCRAD
syn keyword masterbasicFunction SCREEN$
syn keyword masterbasicFunction SGN
syn keyword masterbasicFunction SHIFT$
syn keyword masterbasicFunction SIN
syn keyword masterbasicFunction SQR
syn keyword masterbasicFunction STR$
syn keyword masterbasicFunction STRING$
syn keyword masterbasicFunction SVAL$
syn keyword masterbasicFunction SVAR
syn keyword masterbasicFunction TAN
syn keyword masterbasicFunction TICS
syn keyword masterbasicFunction TIME$
syn keyword masterbasicFunction TIME$
syn keyword masterbasicFunction TRUNC$
syn keyword masterbasicFunction UDG
syn keyword masterbasicFunction USING$
syn keyword masterbasicFunction USR
syn keyword masterbasicFunction USR$
syn keyword masterbasicFunction VAL
syn keyword masterbasicFunction VAL$
syn keyword masterbasicFunction XMOUSE
syn keyword masterbasicFunction XPEN
syn keyword masterbasicFunction XVAR
syn keyword masterbasicFunction YMOUSE
syn keyword masterbasicFunction YPEN
" Special variables
syn keyword masterbasicFunction XOS
syn keyword masterbasicFunction XRG
syn keyword masterbasicFunction YOS
syn keyword masterbasicFunction YRG
" Qualifiers
syn keyword masterbasicQualifier AT
syn keyword masterbasicQualifier ERROR
syn keyword masterbasicQualifier LINE
syn keyword masterbasicQualifier OFF
" REF is also a command, but not usually in listings:
syn keyword masterbasicQualifier REF
syn keyword masterbasicQualifier STEP
syn keyword masterbasicQualifier TAB
syn keyword masterbasicQualifier TO
syn keyword masterbasicQualifier USING
" Structure
syn match masterbasicStructure "\<DEF \?FN\>"
syn match masterbasicStructure "\<DEF \?PROC\>"
syn keyword masterbasicStructure DO
syn keyword masterbasicStructure ELSE
syn match masterbasicStructure "\<END \?IF\>"
syn match masterbasicStructure "\<END \?PROC\>"
syn match masterbasicStructure "\<EXIT \?DO\>"
syn match masterbasicStructure "\<EXIT \?FOR\>"
syn match masterbasicStructure "\<EXIT \?IF\>"
syn match masterbasicStructure "\<EXIT \?PROC\>"
syn keyword masterbasicStructure FOR
syn match masterbasicStructure "\<GO \?SUB\>"
syn match masterbasicStructure "\<GO \?TO\>"
syn keyword masterbasicStructure IF
syn keyword masterbasicStructure LOOP
syn keyword masterbasicStructure NEXT
syn keyword masterbasicStructure ON
syn keyword masterbasicStructure STOP
syn keyword masterbasicStructure THEN
syn keyword masterbasicStructure UNTIL
syn keyword masterbasicStructure WHILE
" Commands
syn keyword masterbasicCommand ALTER
syn keyword masterbasicCommand AUTO
syn keyword masterbasicCommand BEEP
syn keyword masterbasicCommand BLITZ
syn keyword masterbasicCommand BLOCKS
syn keyword masterbasicCommand BOOM
syn keyword masterbasicCommand BOOT
syn keyword masterbasicCommand BORDER
syn keyword masterbasicCommand BRIGHT
syn keyword masterbasicCommand CALL
syn keyword masterbasicCommand CIRCLE
syn keyword masterbasicCommand CLEAR
syn keyword masterbasicCommand CLOSE
syn keyword masterbasicCommand CLS
syn keyword masterbasicCommand CONTINUE
syn keyword masterbasicCommand COPY
syn keyword masterbasicCommand CSIZE
syn keyword masterbasicCommand DATA
syn keyword masterbasicCommand DATE
syn keyword masterbasicCommand DEFAULT
syn match masterbasicCommand "\<DEF \?KEYCODE\>"
syn keyword masterbasicCommand DELETE
syn keyword masterbasicCommand DEVICE
syn keyword masterbasicCommand DIM
syn keyword masterbasicCommand DIR
syn keyword masterbasicCommand DISPLAY
syn keyword masterbasicCommand DPOKE
syn keyword masterbasicCommand DRAW
syn keyword masterbasicCommand DUMP
syn keyword masterbasicCommand EDIT
syn keyword masterbasicCommand ERASE
syn keyword masterbasicCommand FATPIX
syn keyword masterbasicCommand FILL
syn keyword masterbasicCommand FLASH
syn keyword masterbasicCommand FORMAT
syn keyword masterbasicCommand GET
syn keyword masterbasicCommand GRAB
syn keyword masterbasicCommand HIDE
syn keyword masterbasicCommand INPUT
syn keyword masterbasicCommand INVERSE
syn keyword masterbasicCommand JOIN
syn keyword masterbasicCommand KEY
syn keyword masterbasicCommand KEYCODE
syn keyword masterbasicCommand KEYIN
syn keyword masterbasicCommand LABEL
syn keyword masterbasicCommand LET
syn keyword masterbasicCommand LIST
syn keyword masterbasicCommand LLIST
syn keyword masterbasicCommand LOAD
syn keyword masterbasicCommand LOCAL
syn keyword masterbasicCommand LPRINT
syn keyword masterbasicCommand MERGE
syn keyword masterbasicCommand MODE
syn keyword masterbasicCommand MOVE
syn keyword masterbasicCommand NEW
syn keyword masterbasicCommand OPEN
syn keyword masterbasicCommand OUT
syn keyword masterbasicCommand OVER
syn keyword masterbasicCommand PALETTE
syn keyword masterbasicCommand PAPER
syn keyword masterbasicCommand PAUSE
syn keyword masterbasicCommand PEN
syn keyword masterbasicCommand PLOT
syn match masterbasicCommand "\<POINT \?#"
syn keyword masterbasicCommand POKE
syn keyword masterbasicCommand POP
syn keyword masterbasicCommand POW
syn keyword masterbasicCommand PRINT
syn keyword masterbasicCommand PROTECT
syn keyword masterbasicCommand PUT
syn keyword masterbasicCommand RANDOMIZE
syn keyword masterbasicCommand READ
syn keyword masterbasicCommand RECORD
syn keyword masterbasicCommand RENAME
syn keyword masterbasicCommand RENUM
syn keyword masterbasicCommand RESTORE
syn keyword masterbasicCommand RETURN
syn keyword masterbasicCommand ROLL
syn keyword masterbasicCommand RUN
syn keyword masterbasicCommand SAVE
syn keyword masterbasicCommand SCREEN
syn keyword masterbasicCommand SCROLL
syn keyword masterbasicCommand SOUND
syn keyword masterbasicCommand SORT
syn keyword masterbasicCommand TIME
syn keyword masterbasicCommand VERIFY
syn keyword masterbasicCommand WINDOW
syn keyword masterbasicCommand WRITE
syn keyword masterbasicCommand ZAP
syn keyword masterbasicCommand ZOOM
syn keyword masterbasicMathsOperator AND
syn keyword masterbasicMathsOperator OR
syn keyword masterbasicMathsOperator BAND
syn keyword masterbasicMathsOperator BOR
syn keyword masterbasicMathsOperator BIN
syn keyword masterbasicMathsOperator MOD
" -------------------------------------------------------------
"integer number, or floating point number without a dot.
syn match masterbasicNumber "\<\d\+\>"
"floating point number, with dot
syn match masterbasicNumber "\<\d\+\.\d*\>"
"floating point number, starting with a dot
syn match masterbasicNumber "\.\d\+\>"
"hex number.
syn match masterbasicNumber "&[0-9a-f]\+\>"
" String and Character constants
syn match masterbasicSpecial contained "\\\d\d\d\|\\."
"syn region masterbasicString start='"' skip='""' end='"' contains=masterbasicSpecial
syn region masterbasicString start='"' skip='""' end='"'
" Comments
syn keyword masterbasicTodo contained todo fixme xxx
syn region masterbasicComment start="\(\(^\d\+\s\+\)\?\|:\)\s*REM " end="$" contains=masterbasicTodo
syn region masterbasicLineNumber start="^\s*\d" end="\s"
syn match masterbasicTypeSpecifier "[a-zA-Z0-9][\$]"ms=s+1
"syn match masterbasicMathsOperator "[<>+\*^/=-]\| AND \| OR \| BAND \| BOR \| BIN \| MOD \|>=\|=<\|<>]"
syn match masterbasicMathsOperator "[<>+\*^/=-]\|>=\|=<\|<>]"
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_basic_syntax_inits")
if version < 508
let did_basic_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink masterbasicLineNumber Label
HiLink masterbasicNumber Number
HiLink masterbasicCommand Statement
HiLink masterbasicQualifier Statement
HiLink masterbasicStructure Structure
HiLink masterbasicString String
HiLink masterbasicComment Comment
HiLink masterbasicSpecial Special
HiLink masterbasicTodo Todo
HiLink masterbasicFunction Function
HiLink masterbasicTypeSpecifier Type
" hi masterbasicMathsOperator term=bold cterm=bold gui=bold
HiLink masterbasicMathsOperator Operator
delcommand HiLink
endif
let b:current_syntax = "masterbasic"