From: Aaron Taylor Date: Fri, 13 Mar 2020 07:27:16 +0000 (-0700) Subject: Added `syntax_highlighting/` folder and instructions for vim and neatvi. X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/commitdiff_plain/6464ec02c9fe89f5092c3b942f67d752895f24bd Added `syntax_highlighting/` folder and instructions for vim and neatvi. --- diff --git a/syntax_highlighting/README.md b/syntax_highlighting/README.md new file mode 100644 index 0000000..0228471 --- /dev/null +++ b/syntax_highlighting/README.md @@ -0,0 +1,107 @@ +VVhitespace Syntax Highlighting +=============================== + +![VVS Syntax Highlighting Example](vvs_syntax_highlighting.gif) + +I find it useful to highlight each IMP a different color as well as highlight +code comments and label definitions. The above image is typical of my +VVhitespace editing environment. + +If you would like something similar, the configuration examples below can be +used with `vim` or `neatvi`. Other editors that use regex matching can reuse +the regular expressions from these examples to achieve similar results. + +This syntax highlighting definition works only with the way I write VVhitespace +code in this repository. Comments in particular can take many forms other +than specified here. + +If you take the time to put together a configuration for other editors, or +improve the regex definitions, let me know. + + +VIM Highlighting +---------------- + +If they don't already exist, create the folders `~/.vim/syntax` and +`~/.vim/ftdetect`. + + % mkdir -p ~/.vim/syntax + % mkdir -p ~/.vim/ftdetect + +Create a file named `~/.vim/ftdetect/vvhitespace.vim` to detect the filetype +based on the file extension. It should contain a single line: + + au BufRead,BufNewFile *.pvvs set filetype=vvhitespace + +Create a file named `~/.vim/syntax/vvhitespace.vim` containing the following: + + if exists("b:current_syntax") + finish + endif + + let b:current_synax = "vvhitespace" + + " Stack IMP + syn match stackIMP '^[sS][sS]' + syn match stackIMP '^[sS][nN][sStTnN]' + + " Arithmetic IMP + syn match arithIMP '^[tT][sS][sStT][sStTnN]' + + " Heap IMP + syn match heapIMP '^[tT][tT][sStT]' + + " Control Flow IMP + syn match controlIMP '^[nN][nNsStT][nNsStT]' + + " IO IMP + syn match ioIMP '^[tT][nN][sStT][sStT]' + + " Label Definition + syn match labelDef 'V[sStT]\+N' + + " Comments + syn match commentBlock '|.*$' + syn match commentBlock '@.*$' + + " Define colors using existing Highlight Groups. + " To see a list of other Highlight Groups, type `:highlight` in vim. + hi def link stackIMP Type + hi def link arithIMP ModeMsg + hi def link heapIMP Special + hi def link controlIMP Constant + hi def link ioIMP Keyword + hi def link labelDef Function + hi def link commentBlock NonText + +That's it! You should now see syntax highlighting when opening files with names +ending in `*.pvvs`. + +If you don't any see syntax highlighting, check your `.vimrc` and other config +locations for conflicting options. Try manually enabling syntax highlighting +with the `syntax on` configuration directive. + + +NeatVI Highlighting +------------------- + +Open the file `conf.h` for editing. + +Add the following line to the `filetypes` array, matching all `*.pvvs` files. + + {"pvvs", "\\.pvvs$"}, /* VVhitespace */ + +Add the following block to the `highlights` array. + + {"pvvs", {2}, "^[sS][sS]"}, /* IMP: Stack Manipulation */ + {"pvvs", {2}, "^[sS][nN][sStTnN]"}, /* IMP: Stack Manipulation */ + {"pvvs", {8}, "^[tT][sS][sStT][sStTnN]"}, /* IMP: Arithmetic */ + {"pvvs", {5}, "^[tT][tT][sStT]"}, /* IMP: Heap Access */ + {"pvvs", {1}, "^[nN][nNsStT][nNsStT]"}, /* IMP: Control Flow */ + {"pvvs", {4}, "^[tT][nN][sStT][sStT]"}, /* IMP: Input/Output */ + {"pvvs", {6 | SYN_BD}, "V[sStT]+N "}, /* Label Definitions */ + {"pvvs", {3 | SYN_IT}, "\\|.*$"}, /* Comments */ + {"pvvs", {3 | SYN_IT}, "\\@.*$"}, /* Comments */ + +Recompile NeatVI and syntax highlighting should work on all files with names +ending in `*.pvvs`. diff --git a/syntax_highlighting/vvhitespace.vim b/syntax_highlighting/vvhitespace.vim new file mode 100644 index 0000000..8c0e095 --- /dev/null +++ b/syntax_highlighting/vvhitespace.vim @@ -0,0 +1,42 @@ +" Vim syntax file +" Language: VVhitespace +" Based on: https://vim.fandom.com/wiki/Creating_your_own_syntax_files + +if exists("b:current_syntax") + finish +endif + +let b:current_synax = "vvhitespace" + +" Stack IMP +syn match stackIMP '^[sS][sS]' +syn match stackIMP '^[sS][nN][sStTnN]' + +" Arithmetic IMP +syn match arithIMP '^[tT][sS][sStT][sStTnN]' + +" Heap IMP +syn match heapIMP '^[tT][tT][sStT]' + +" Control Flow IMP +syn match controlIMP '^[nN][nNsStT][nNsStT]' + +" IO IMP +syn match ioIMP '^[tT][nN][sStT][sStT]' + +" Label Definition +syn match labelDef 'V[sStT]\+N' + +" Comments +syn match commentBlock '|.*$' +syn match commentBlock '@.*$' + +" Define colors using existing Highlight Groups. +" To see a list of other Highlight Groups, type `:highlight` in vim. +hi def link stackIMP Type +hi def link arithIMP ModeMsg +hi def link heapIMP Special +hi def link controlIMP Constant +hi def link ioIMP Keyword +hi def link labelDef Function +hi def link commentBlock NonText diff --git a/syntax_highlighting/vvs_syntax_highlighting.gif b/syntax_highlighting/vvs_syntax_highlighting.gif new file mode 100644 index 0000000..69fdcf0 Binary files /dev/null and b/syntax_highlighting/vvs_syntax_highlighting.gif differ