2018-09-24 20:40:17 -04:00
|
|
|
" gomod.vim: Vim syntax file for go.mod file
|
|
|
|
"
|
|
|
|
" Quit when a (custom) syntax file was already loaded
|
|
|
|
if exists("b:current_syntax")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
syntax case match
|
|
|
|
|
|
|
|
" match keywords
|
|
|
|
syntax keyword gomodModule module
|
2019-11-16 10:28:42 -05:00
|
|
|
syntax keyword gomodGo go contained
|
2018-09-24 20:40:17 -04:00
|
|
|
syntax keyword gomodRequire require
|
|
|
|
syntax keyword gomodExclude exclude
|
|
|
|
syntax keyword gomodReplace replace
|
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
" require, exclude, replace, and go can be also grouped into block
|
2018-09-24 20:40:17 -04:00
|
|
|
syntax region gomodRequire start='require (' end=')' transparent contains=gomodRequire,gomodVersion
|
|
|
|
syntax region gomodExclude start='exclude (' end=')' transparent contains=gomodExclude,gomodVersion
|
|
|
|
syntax region gomodReplace start='replace (' end=')' transparent contains=gomodReplace,gomodVersion
|
2019-11-16 10:28:42 -05:00
|
|
|
syntax match gomodGo '^go .*$' transparent contains=gomodGo,gomodGoVersion
|
2018-09-24 20:40:17 -04:00
|
|
|
|
|
|
|
" set highlights
|
|
|
|
highlight default link gomodModule Keyword
|
2019-11-16 10:28:42 -05:00
|
|
|
highlight default link gomodGo Keyword
|
2018-09-24 20:40:17 -04:00
|
|
|
highlight default link gomodRequire Keyword
|
|
|
|
highlight default link gomodExclude Keyword
|
|
|
|
highlight default link gomodReplace Keyword
|
|
|
|
|
|
|
|
" comments are always in form of // ...
|
|
|
|
syntax region gomodComment start="//" end="$" contains=@Spell
|
|
|
|
highlight default link gomodComment Comment
|
|
|
|
|
|
|
|
" make sure quoted import paths are higlighted
|
|
|
|
syntax region gomodString start=+"+ skip=+\\\\\|\\"+ end=+"+
|
|
|
|
highlight default link gomodString String
|
|
|
|
|
|
|
|
" replace operator is in the form of '=>'
|
|
|
|
syntax match gomodReplaceOperator "\v\=\>"
|
|
|
|
highlight default link gomodReplaceOperator Operator
|
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
" match go versions
|
|
|
|
syntax match gomodGoVersion "1\.\d\+" contained
|
|
|
|
highlight default link gomodGoVersion Identifier
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
|
2018-11-01 06:03:42 -04:00
|
|
|
" highlight versions:
|
2019-03-27 11:08:56 -04:00
|
|
|
" * vX.Y.Z-pre
|
2018-11-01 06:03:42 -04:00
|
|
|
" * vX.Y.Z
|
|
|
|
" * vX.0.0-yyyyymmddhhmmss-abcdefabcdef
|
|
|
|
" * vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef
|
|
|
|
" * vX.Y.(Z+1)-0.yyyymmddhhss-abcdefabcdef
|
2019-03-27 11:08:56 -04:00
|
|
|
" see https://godoc.org/golang.org/x/tools/internal/semver for more
|
|
|
|
" information about how semantic versions are parsed and
|
|
|
|
" https://golang.org/cmd/go/ for how pseudo-versions and +incompatible
|
|
|
|
" are applied.
|
|
|
|
|
|
|
|
|
2018-11-01 06:03:42 -04:00
|
|
|
" match vX.Y.Z and their prereleases
|
2019-03-27 11:08:56 -04:00
|
|
|
syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?"
|
|
|
|
" ^--- version ---^^------------ pre-release ---------------------^^--------------- metadata ---------------------^
|
|
|
|
" ^--------------------------------------- semantic version -------------------------------------------------------^
|
|
|
|
|
|
|
|
" match pseudo versions
|
|
|
|
" without a major version before the commit (e.g. vX.0.0-yyyymmddhhmmss-abcdefabcdef)
|
|
|
|
syntax match gomodVersion "v\d\+\.0\.0-\d\{14\}-\x\+"
|
|
|
|
" when most recent version before target is a pre-release
|
|
|
|
syntax match gomodVersion "v\d\+\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\+"
|
|
|
|
" ^--- version ---^^--- ------ pre-release -----------------^^--------------- metadata ---------------------^
|
|
|
|
" ^------------------------------------- semantic version --------------------------------------------------^
|
|
|
|
" most recent version before the target is X.Y.Z
|
|
|
|
syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\+"
|
|
|
|
" ^--- version ---^^--------------- metadata ---------------------^
|
|
|
|
|
|
|
|
" match incompatible vX.Y.Z and their prereleases
|
|
|
|
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?+incompatible"
|
|
|
|
" ^------- version -------^^------------- pre-release ---------------------^^--------------- metadata ---------------------^
|
|
|
|
" ^------------------------------------------- semantic version -----------------------------------------------------------^
|
2018-11-01 06:03:42 -04:00
|
|
|
|
2019-03-27 11:08:56 -04:00
|
|
|
" match incompatible pseudo versions
|
|
|
|
" incompatible without a major version before the commit (e.g. vX.0.0-yyyymmddhhmmss-abcdefabcdef)
|
|
|
|
syntax match gomodVersion "v[2-9]\{1}\d*\.0\.0-\d\{14\}-\x\++incompatible"
|
|
|
|
" when most recent version before target is a pre-release
|
|
|
|
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\++incompatible"
|
|
|
|
" ^------- version -------^^---------- pre-release -----------------^^--------------- metadata ---------------------^
|
|
|
|
" ^---------------------------------------- semantic version ------------------------------------------------------^
|
|
|
|
" most recent version before the target is X.Y.Z
|
|
|
|
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\++incompatible"
|
|
|
|
" ^------- version -------^^---------------- metadata ---------------------^
|
2018-09-24 20:40:17 -04:00
|
|
|
highlight default link gomodVersion Identifier
|
|
|
|
|
|
|
|
let b:current_syntax = "gomod"
|