2
\$\begingroup\$

I recently made vim-dyon which is a syntax highlighter and indenter for the dyon programming language. There are probably some issues with being absolutely correct (since I am not too familiar with dyon), but it seems to do a good job in terms of how it works and looks. I am new to VimScript and I am looking for mostly a critique of my VimScript.

ftdetect/dyon.vim

autocmd BufNewFile,BufRead *.dyon setfiletype dyon

ftplugin/dyon.vim

if exists("b:did_ftplugin")
  finish
endif

let b:did_ftplugin = 1

setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4

indent/dyon.vim

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

if exists("*DyonIndent")
  finish
endif

" Dyon works similar to C, but without ;.
setlocal smartindent

syntax/dyon.vim

if exists("b:current_syntax")
    finish
endif

" Function/Closure
syntax keyword dyonKeyword fn grab

" Boolean
syntax keyword dyonKeyword true false

" Control keywords
syntax keyword dyonKeyword break continue else if for loop return in

" Special keywords
syntax keyword dyonKeyword mut go in any vec4

highlight link dyonKeyword Keyword

" Highlight functions 
" (see: https://stackoverflow.com/a/45626295/667648)
syntax match dyonFunction "\zs\(\k\w*\)*\s*\ze(" 
highlight link dyonFunction Function

" Arithmetic operations

" a * b
syntax match dyonOperator "\v\*"
" a / b
syntax match dyonOperator "\v/"
" a % b
syntax match dyonOperator "\v\%"
" a + b
syntax match dyonOperator "\v\+"
" a - b
syntax match dyonOperator "\v-"
" a ^ b
syntax match dyonOperator "\v\^"
" a *= b
syntax match dyonOperator "\v\*\="
" a /= b
syntax match dyonOperator "\v/\="
" a %= b
syntax match dyonOperator "\v\%\="
" a += b
syntax match dyonOperator "\v\+\="
" a -= b
syntax match dyonOperator "\v-\="
" a ^= b
syntax match dyonOperator "\v\^\="
" a := b
syntax match dyonOperator "\v:\="

syntax match dyonOperator "\v[a-zA-z]+:"

" Boolean operations

" a && b
syntax match dyonOperator "\v\&\&"
" a and b
syntax match dyonOperator "\v and "
" a || b
syntax match dyonOperator "\v\|\|"
" a or b
syntax match dyonOperator "\v or "

highlight link dyonOperator Operator

" Numbers and strings
" (see
" https://github.com/pangloss/vim-javascript/blob/89fcb6bfcada1c4256284723778d128342b48350/syntax/javascript.vim#L57)
syntax match dyonString "\v#[0-9a-f]+"
syntax match dyonString /\c\<\%(\d\+\%(e[+-]\=\d\+\)\=\|0b[01]\+\|0o\o\+\|0x\x\+\)\>/
syntax region dyonString start=/\v"/ skip=/\v\\./ end=/\v"/
highlight link dyonString String

highlight link dyonNumber String


" Matches // style comment
syntax region dyonComment start="//" end="$"
highlight link dyonComment Comment


let b:current_syntax = "dyon"
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.