Abersoft Forth Vim syntax file

Description of the page content

Vim syntax file for highlighting Abersoft Forth code.

Tags:

I wrote the following Vim syntax file in order to work with Abersoft Forth more comfortably, with my favourite editor.

Source code

" abersoftforth.vim
" Vim syntax file 
" Language: Abersoft Forth (ZX Spectrum computer)
" Author:   Marcos Cruz (programandala.net)
" License:  Vim license (GPL compatible)
" URL:      http://programandala.net/en.program.abersoft_forth_vim_syntax_file.html
" Updated:  2015-05-01

" History:

" --------------------------------------------------------------
" Change log

" 2014-10-19: First version.
"
" 2014-10-21: 'X1' and 'Y1' are moved to the graphics group, after Don
" Thomasson's "Advanced Spectrum Forth" book (1984).  Only five undocumented
" words remain.
"
" 2015-01-10: Typo.
"
" 2015-02-26: Vim license.
"
" 2015-03-12: 'DR0', 'LO' and 'HI' are moved to the files group; 'INCX' and
" 'INCY' are moved to the graphics; all after Don Thomasson's "Advanced
" Spectrum Forth" book. No undocumented word remains.
" 
" 2015-03-13: 'CALL' removed; support for hex numbers.
"
" 2015-03-18: '[' and '[COMPILE]' were not properly rendered, because of the
" open bracket. 'match' was needed instead of 'keyword'.
"
" 2015-03-28: Fix: '?DUP' removed.
"
" 2015-03-28: Fix: 'NEGATE' removed.
"
" 2015-03-30: Fix: 'INVERT' removed.
"
" 2015-05-01: Improved support for hex numbers.

" --------------------------------------------------------------
" Usage

" Possible locations of this file:

" ~/.vim/syntax/abersoftforth.vim
" /usr/share/vim/vimcurrent/syntax/abersoftforth.vim

" --------------------------------------------------------------

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
    syntax clear
elseif exists("b:current_syntax")
    finish
endif

" Synchronization method
syn sync ccomment
syn sync maxlines=200

" Abersoft Forth is case sensitive:
"syn case ignore

" Some special, non-Forth keywords
syn keyword abersoftforthTodo contained TODO
syn keyword abersoftforthTodo contained FIXME
syn keyword abersoftforthTodo contained XXX
syn match abersoftforthTodo contained 'Copyright\(\s([Cc])\)\=\(\s[0-9]\{2,4}\)\='

" Characters allowed in keywords
if version >= 600
    setlocal iskeyword=33-255
else
    set iskeyword=33-255
endif

" Keywords

syn keyword abersoftforthAssembler ;CODE
syn keyword abersoftforthAssembler PUSHDE
syn keyword abersoftforthAssembler PUSHHL
syn keyword abersoftforthCharacterInput EXPECT
syn keyword abersoftforthCharacterInput INKEY
syn keyword abersoftforthCharacterInput KEY
syn keyword abersoftforthCharacterInput QUERY
syn keyword abersoftforthCharacterInput TEXT
syn keyword abersoftforthCharacterInput TIB
syn keyword abersoftforthCharacterOutput .
syn keyword abersoftforthCharacterOutput .R
syn keyword abersoftforthCharacterOutput BL
syn keyword abersoftforthCharacterOutput CR
syn keyword abersoftforthCharacterOutput D.
syn keyword abersoftforthCharacterOutput D.R
syn keyword abersoftforthCharacterOutput EMIT
syn keyword abersoftforthCharacterOutput OUT
syn keyword abersoftforthCharacterOutput SPACE
syn keyword abersoftforthCharacterOutput SPACES
syn keyword abersoftforthCharacterOutput TYPE
syn keyword abersoftforthCharacterOutput U.
syn keyword abersoftforthCharacterOutput U.R
syn keyword abersoftforthConversion #
syn keyword abersoftforthConversion #>
syn keyword abersoftforthConversion #S
syn keyword abersoftforthConversion <#
syn keyword abersoftforthConversion DIGIT
syn keyword abersoftforthConversion DPL
syn keyword abersoftforthConversion FLD
syn keyword abersoftforthConversion HLD
syn keyword abersoftforthConversion HOLD
syn keyword abersoftforthConversion SIGN
syn keyword abersoftforthDefine '
syn keyword abersoftforthDefine ,
syn keyword abersoftforthDefine 2CONSTANT
syn keyword abersoftforthDefine 2VARIABLE
syn keyword abersoftforthDefine ;
syn keyword abersoftforthDefine <BUILDS
syn keyword abersoftforthDefine BACK
syn keyword abersoftforthDefine COMPILE
syn keyword abersoftforthDefine CONSTANT
syn keyword abersoftforthDefine CREATE
syn keyword abersoftforthDefine DLITERAL
syn keyword abersoftforthDefine DOES>
syn keyword abersoftforthDefine IMMEDIATE
syn keyword abersoftforthDefine INTERPRET
syn keyword abersoftforthDefine LIT
syn keyword abersoftforthDefine LITERAL
syn keyword abersoftforthDefine SMUDGE
syn keyword abersoftforthDefine USER
syn keyword abersoftforthDefine VARIABLE
syn keyword abersoftforthDefine WORD
syn keyword abersoftforthDefine ]
syn keyword abersoftforthFiles #BUFF
syn keyword abersoftforthFiles (TAPE)
syn keyword abersoftforthFiles +BUF
syn keyword abersoftforthFiles -->
syn keyword abersoftforthFiles .LINE
syn keyword abersoftforthFiles ;S
syn keyword abersoftforthFiles B/BUF
syn keyword abersoftforthFiles B/SCR
syn keyword abersoftforthFiles BLK
syn keyword abersoftforthFiles BLOCK
syn keyword abersoftforthFiles BUFFER
syn keyword abersoftforthFiles C/L
syn keyword abersoftforthFiles DR0
syn keyword abersoftforthFiles EDITOR
syn keyword abersoftforthFiles EMPTY-BUFFERS
syn keyword abersoftforthFiles FIRST
syn keyword abersoftforthFiles FLUSH
syn keyword abersoftforthFiles HI
syn keyword abersoftforthFiles INDEX
syn keyword abersoftforthFiles INIT-DISC
syn keyword abersoftforthFiles LIST
syn keyword abersoftforthFiles LO
syn keyword abersoftforthFiles LOAD
syn keyword abersoftforthFiles LOADT
syn keyword abersoftforthFiles MESSAGE
syn keyword abersoftforthFiles OFFSET
syn keyword abersoftforthFiles PREV
syn keyword abersoftforthFiles R#
syn keyword abersoftforthFiles R/W
syn keyword abersoftforthFiles SAVET
syn keyword abersoftforthFiles SCR
syn keyword abersoftforthFiles TRIAD
syn keyword abersoftforthFiles UPDATE
syn keyword abersoftforthFiles USE
syn keyword abersoftforthFiles VERIFY
syn keyword abersoftforthFiles WHERE
syn keyword abersoftforthFlow +LOOP
syn keyword abersoftforthFlow 0BRANCH
syn keyword abersoftforthFlow ABORT
syn keyword abersoftforthFlow AGAIN
syn keyword abersoftforthFlow BEGIN
syn keyword abersoftforthFlow BRANCH
syn keyword abersoftforthFlow CASE
syn keyword abersoftforthFlow COLD
syn keyword abersoftforthFlow DO
syn keyword abersoftforthFlow ELSE
syn keyword abersoftforthFlow END
syn keyword abersoftforthFlow ENDCASE
syn keyword abersoftforthFlow ENDIF
syn keyword abersoftforthFlow ENDOF
syn keyword abersoftforthFlow EXECUTE
syn keyword abersoftforthFlow EXIT
syn keyword abersoftforthFlow I
syn keyword abersoftforthFlow I'
syn keyword abersoftforthFlow IF
syn keyword abersoftforthFlow J
syn keyword abersoftforthFlow LEAVE
syn keyword abersoftforthFlow LOOP
syn keyword abersoftforthFlow MON
syn keyword abersoftforthFlow NEXT
syn keyword abersoftforthFlow OF
syn keyword abersoftforthFlow QUIT
syn keyword abersoftforthFlow REPEAT
syn keyword abersoftforthFlow THEN
syn keyword abersoftforthFlow UNTIL
syn keyword abersoftforthFlow WARM
syn keyword abersoftforthFlow WHILE
syn keyword abersoftforthForth !CSP
syn keyword abersoftforthForth (+LOOP)
syn keyword abersoftforthForth (.")
syn keyword abersoftforthForth (;CODE)
syn keyword abersoftforthForth (ABORT)
syn keyword abersoftforthForth (DO)
syn keyword abersoftforthForth (FIND)
syn keyword abersoftforthForth (LINE)
syn keyword abersoftforthForth (LOOP)
syn keyword abersoftforthForth (NUMBER)
syn keyword abersoftforthForth +ORIGIN
syn keyword abersoftforthForth .CPU
syn keyword abersoftforthForth ?COMP
syn keyword abersoftforthForth ?CSP
syn keyword abersoftforthForth ?ERROR
syn keyword abersoftforthForth ?EXEC
syn keyword abersoftforthForth ?LOADING
syn keyword abersoftforthForth ?PAIRS
syn keyword abersoftforthForth ?STACK
syn keyword abersoftforthForth ?TERMINAL
syn keyword abersoftforthForth CFA
syn keyword abersoftforthForth CSP
syn keyword abersoftforthForth ENCLOSE
syn keyword abersoftforthForth ERROR
syn keyword abersoftforthForth FREE
syn keyword abersoftforthForth IN
syn keyword abersoftforthForth LATEST
syn keyword abersoftforthForth LFA
syn keyword abersoftforthForth LIMIT
syn keyword abersoftforthForth LINE
syn keyword abersoftforthForth NFA
syn keyword abersoftforthForth NOOP
syn keyword abersoftforthForth PAD
syn keyword abersoftforthForth PFA
syn keyword abersoftforthForth STATE
syn keyword abersoftforthForth WARNING
syn keyword abersoftforthForth WIDTH
syn keyword abersoftforthGraphics AT
syn keyword abersoftforthGraphics ATTR
syn keyword abersoftforthGraphics BORDER
syn keyword abersoftforthGraphics BRIGHT
syn keyword abersoftforthGraphics CLS
syn keyword abersoftforthGraphics DRAW
syn keyword abersoftforthGraphics FLASH
syn keyword abersoftforthGraphics GOVER
syn keyword abersoftforthGraphics INCX
syn keyword abersoftforthGraphics INCY
syn keyword abersoftforthGraphics INK
syn keyword abersoftforthGraphics INVERSE
syn keyword abersoftforthGraphics PAPER
syn keyword abersoftforthGraphics PLOT
syn keyword abersoftforthGraphics POINT
syn keyword abersoftforthGraphics SCREEN
syn keyword abersoftforthGraphics UDG
syn keyword abersoftforthGraphics X1
syn keyword abersoftforthGraphics Y1
syn keyword abersoftforthHardware BLEEP
syn keyword abersoftforthHardware INP
syn keyword abersoftforthHardware LINK
syn keyword abersoftforthHardware OUTP
syn keyword abersoftforthMath BASE
syn keyword abersoftforthMath DECIMAL
syn keyword abersoftforthMath HEX
syn keyword abersoftforthMemory !
syn keyword abersoftforthMemory -TRAILING
syn keyword abersoftforthMemory 2!
syn keyword abersoftforthMemory 2@
syn keyword abersoftforthMemory ?
syn keyword abersoftforthMemory @
syn keyword abersoftforthMemory ALLOT
syn keyword abersoftforthMemory BLANKS
syn keyword abersoftforthMemory C!
syn keyword abersoftforthMemory C,
syn keyword abersoftforthMemory C@
syn keyword abersoftforthMemory CMOVE
syn keyword abersoftforthMemory COUNT
syn keyword abersoftforthMemory DP
syn keyword abersoftforthMemory ERASE
syn keyword abersoftforthMemory FENCE
syn keyword abersoftforthMemory FILL
syn keyword abersoftforthMemory HERE
syn keyword abersoftforthOperator *
syn keyword abersoftforthOperator */
syn keyword abersoftforthOperator */MOD
syn keyword abersoftforthOperator +
syn keyword abersoftforthOperator +!
syn keyword abersoftforthOperator +-
syn keyword abersoftforthOperator -
syn keyword abersoftforthOperator /
syn keyword abersoftforthOperator /MOD
syn keyword abersoftforthOperator 0<
syn keyword abersoftforthOperator 0=
syn keyword abersoftforthOperator 1+
syn keyword abersoftforthOperator 2+
syn keyword abersoftforthOperator <
syn keyword abersoftforthOperator =
syn keyword abersoftforthOperator >
syn keyword abersoftforthOperator ABS
syn keyword abersoftforthOperator AND
syn keyword abersoftforthOperator D+
syn keyword abersoftforthOperator D+-
syn keyword abersoftforthOperator D<
syn keyword abersoftforthOperator DABS
syn keyword abersoftforthOperator DMINUS
syn keyword abersoftforthOperator M*
syn keyword abersoftforthOperator M/
syn keyword abersoftforthOperator M/MOD
syn keyword abersoftforthOperator MAX
syn keyword abersoftforthOperator MIN
syn keyword abersoftforthOperator MINUS
syn keyword abersoftforthOperator MOD
syn keyword abersoftforthOperator NOT
syn keyword abersoftforthOperator OR
syn keyword abersoftforthOperator S->D
syn keyword abersoftforthOperator TOGGLE
syn keyword abersoftforthOperator U*
syn keyword abersoftforthOperator U/MOD
syn keyword abersoftforthOperator U<
syn keyword abersoftforthOperator XOR
syn keyword abersoftforthReturnStack >R
syn keyword abersoftforthReturnStack R
syn keyword abersoftforthReturnStack R0
syn keyword abersoftforthReturnStack R>
syn keyword abersoftforthReturnStack RP!
syn keyword abersoftforthReturnStack RP@
syn keyword abersoftforthStack -DUP
syn keyword abersoftforthStack 2DROP
syn keyword abersoftforthStack 2DUP
syn keyword abersoftforthStack 2OVER
syn keyword abersoftforthStack 2SWAP
syn keyword abersoftforthStack DROP
syn keyword abersoftforthStack DUP
syn keyword abersoftforthStack OVER
syn keyword abersoftforthStack ROT
syn keyword abersoftforthStack S0
syn keyword abersoftforthStack SP!
syn keyword abersoftforthStack SP@
syn keyword abersoftforthStack SWAP
syn keyword abersoftforthVocs -FIND
syn keyword abersoftforthVocs CONTEXT
syn keyword abersoftforthVocs CURRENT
syn keyword abersoftforthVocs DEFINITIONS
syn keyword abersoftforthVocs FIND
syn keyword abersoftforthVocs FORGET
syn keyword abersoftforthVocs FORTH
syn keyword abersoftforthVocs ID.
syn keyword abersoftforthVocs SIZE
syn keyword abersoftforthVocs TRAVERSE
syn keyword abersoftforthVocs VLIST
syn keyword abersoftforthVocs VOC-LINK
syn keyword abersoftforthVocs VOCABULARY
syn match abersoftforthColonDef '\<:\s\+[^ \t]\+\>'

" Special cases because of the open bracket

"syn keyword abersoftforthDefine [
syn match abersoftforthDefine "\<\[\>"
"syn keyword abersoftforthDefine [COMPILE]
syn match abersoftforthDefine "\<\[COMPILE]\>"

" Numbers

"syn match abersoftforthNumber '\<-\=[0-9.]*[0-9.]\+\>'

syn match abersoftforthNumber '\<-\=[0-9A-F.]\{2}\>'
syn match abersoftforthNumber '\<-\=[0-9A-F.]\{4}\>'
"syn match abersoftforthNumber '\<-\=[0-9A-F.]\{8}\>'
syn match abersoftforthNumber '\<-\=[0-9.]\+\>'

" Strings

syn region abersoftforthString start=+\.\"+ end=+"+ end=+$+
"syn region abersoftforthCharOps start=+."\s+ skip=+\\"+ end=+"+

" Comments

syn match abersoftforthComment '\<(\s[^)]*)' contains=abersoftforthTodo

" Block Titles
" Adapted from fsb
" http://programandala.net/en.program.fsb.html

" syn match abersoftforthBlockTitle /^\.\?(\s.\+)\(\s\+.*\)\?$/
syn match abersoftforthBlockTitle /^\.\?(\s.\{-})/

" Define the highlighting.

hi def link abersoftforthBlockTitle Underlined
hi def link abersoftforthAssembler Include
hi def link abersoftforthCharacterInput Character
hi def link abersoftforthCharacterOutput Character
hi def link abersoftforthColonDef Define
hi def link abersoftforthComment Comment
hi def link abersoftforthConversion String
hi def link abersoftforthDefine Define
hi def link abersoftforthFiles Statement
hi def link abersoftforthFlow Repeat
hi def link abersoftforthForth Statement
hi def link abersoftforthGraphics Statement
hi def link abersoftforthHardware Statement
hi def link abersoftforthNumber Number
hi def link abersoftforthMath Number
hi def link abersoftforthMemory Statement
hi def link abersoftforthOperator Operator
hi def link abersoftforthReturnStack Special
hi def link abersoftforthStack Special
hi def link abersoftforthString String
hi def link abersoftforthTodo Todo
hi def link abersoftforthUndocumented Statement
hi def link abersoftforthVocs Statement

let b:current_syntax = "abersoftforth"

" vim:ts=2:sts=2:sw=2:et:nocindent:smartindent:


Downloads

Related pages

Abersoft Forth Disassembled
Disassembled and commented code of ZX Spectrum's Abersoft Forth, with the tools that were written to obtain it.
Abersoft Forth Afera syntax file
Vim syntax file for highlighting Abersoft Forth code expanded with the Afera library.