1" Vim syntax file
2" Language:    Debian control files
3" Maintainer:  Debian Vim Maintainers
4" Former Maintainers: Gerfried Fuchs <[email protected]>
5"                     Wichert Akkerman <[email protected]>
6" Last Change: 2018 Jan 28
7" URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debcontrol.vim
8
9" Standard syntax initialization
10if exists('b:current_syntax')
11  finish
12endif
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17" Should match case except for the keys of each field
18syn case match
19
20syn iskeyword @,48-57,-,/
21
22" Everything that is not explicitly matched by the rules below
23syn match debcontrolElse "^.*$"
24
25" Common seperators
26syn match debControlComma ",[ \t]*"
27syn match debControlSpace "[ \t]"
28
29let s:kernels = ['linux', 'hurd', 'kfreebsd', 'knetbsd', 'kopensolaris', 'netbsd']
30let s:archs = [
31      \ 'alpha', 'amd64', 'armeb', 'armel', 'armhf', 'arm64', 'avr32', 'hppa'
32      \, 'i386', 'ia64', 'lpia', 'm32r', 'm68k', 'mipsel', 'mips64el', 'mips'
33      \, 'powerpcspe', 'powerpc', 'ppc64el', 'ppc64', 's390x', 's390', 'sh3eb'
34      \, 'sh3', 'sh4eb', 'sh4', 'sh', 'sparc64', 'sparc', 'x32'
35      \ ]
36let s:pairs = [
37      \ 'hurd-i386', 'kfreebsd-i386', 'kfreebsd-amd64', 'knetbsd-i386'
38      \, 'kopensolaris-i386', 'netbsd-alpha', 'netbsd-i386'
39      \ ]
40
41" Define some common expressions we can use later on
42syn keyword debcontrolArchitecture contained all any
43exe 'syn keyword debcontrolArchitecture contained '. join(map(s:kernels, {k,v -> v .'-any'}))
44exe 'syn keyword debcontrolArchitecture contained '. join(map(s:archs, {k,v -> 'any-'.v}))
45exe 'syn keyword debcontrolArchitecture contained '. join(s:archs)
46exe 'syn keyword debcontrolArchitecture contained '. join(s:pairs)
47
48unlet s:kernels s:archs s:pairs
49
50let s:sections = [
51      \ 'admin', 'cli-mono', 'comm', 'database', 'debian-installer', 'debug'
52      \, 'devel', 'doc', 'editors', 'education', 'electronics', 'embedded'
53      \, 'fonts', 'games', 'gnome', 'gnustep', 'gnu-r', 'golang', 'graphics'
54      \, 'hamradio', 'haskell', 'httpd', 'interpreters', 'introspection'
55      \, 'java\%(script\)\=', 'kde', 'kernel', 'libs', 'libdevel', 'lisp'
56      \, 'localization', 'mail', 'math', 'metapackages', 'misc', 'net'
57      \, 'news', 'ocaml', 'oldlibs', 'otherosfs', 'perl', 'php', 'python'
58      \, 'ruby', 'rust', 'science', 'shells', 'sound', 'text', 'tex'
59      \, 'utils', 'vcs', 'video', 'web', 'x11', 'xfce', 'zope'
60      \ ]
61
62syn keyword debcontrolMultiArch contained no foreign allowed same
63syn match debcontrolName contained "[a-z0-9][a-z0-9+.-]\+"
64syn keyword debcontrolPriority contained extra important optional required standard
65exe 'syn match debcontrolSection contained "\%(\%(contrib\|non-free\|non-US/main\|non-US/contrib\|non-US/non-free\|restricted\|universe\|multiverse\)/\)\=\%('.join(s:sections, '\|').'\)"'
66syn keyword debcontrolPackageType contained udeb deb
67syn match debcontrolVariable contained "\${.\{-}}"
68syn keyword debcontrolDmUpload contained yes
69syn keyword debcontrolYesNo contained yes no
70syn match debcontrolR3 contained "\<\%(no\|binary-targets\|[[:graph:]]\+/[[:graph:]]\+\%( \+[[:graph:]]\+/[[:graph:]]\+\)*\)\>"
71
72unlet s:sections
73
74" A URL (using the domain name definitions from RFC 1034 and 1738), right now
75" only enforce protocol and some sanity on the server/path part;
76syn match debcontrolHTTPUrl contained "\vhttps?://[[:alnum:]][-[:alnum:]]*[[:alnum:]]?(\.[[:alnum:]][-[:alnum:]]*[[:alnum:]]?)*\.[[:alpha:]][-[:alnum:]]*[[:alpha:]]?(:\d+)?(/[^[:space:]]*)?$"
77syn match debcontrolVcsSvn contained "\vsvn%(\+ssh)?://[[:alnum:]][-[:alnum:]]*[[:alnum:]]?(\.[[:alnum:]][-[:alnum:]]*[[:alnum:]]?)*\.[[:alpha:]][-[:alnum:]]*[[:alpha:]]?(:\d+)?(/[^[:space:]]*)?$"
78syn match debcontrolVcsCvs contained "\v%(\-d *)?:pserver:[^@]+\@[[:alnum:]][-[:alnum:]]*[[:alnum:]]?(\.[[:alnum:]][-[:alnum:]]*[[:alnum:]]?)*\.[[:alpha:]][-[:alnum:]]*[[:alpha:]]?:/[^[:space:]]*%( [^[:space:]]+)?$"
79syn match debcontrolVcsGit contained "\v%(git|https?)://[[:alnum:]][-[:alnum:]]*[[:alnum:]]?(\.[[:alnum:]][-[:alnum:]]*[[:alnum:]]?)*\.[[:alpha:]][-[:alnum:]]*[[:alpha:]]?(:\d+)?(/[^[:space:]]*)?%(\s+-b\s+[^ ~^:?*[\\]+)?$"
80
81" An email address
82syn match	debcontrolEmail	"[_=[:alnum:]\.+-]\+@[[:alnum:]\./\-]\+"
83syn match	debcontrolEmail	"<.\{-}>"
84
85" #-Comments
86syn match debcontrolComment "^#.*$" contains=@Spell
87
88syn case ignore
89
90" Handle all fields from deb-src-control(5)
91
92" Fields for which we do strict syntax checking
93syn region debcontrolStrictField matchgroup=debcontrolKey start="^Architecture: *" end="$" contains=debcontrolArchitecture,debcontrolSpace oneline
94syn region debcontrolStrictField matchgroup=debcontrolKey start="^Multi-Arch: *" end="$" contains=debcontrolMultiArch oneline
95syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(Package\|Source\): *" end="$" contains=debcontrolName oneline
96syn region debcontrolStrictField matchgroup=debcontrolKey start="^Priority: *" end="$" contains=debcontrolPriority oneline
97syn region debcontrolStrictField matchgroup=debcontrolKey start="^Section: *" end="$" contains=debcontrolSection oneline
98syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(XC-\)\=Package-Type: *" end="$" contains=debcontrolPackageType oneline
99syn region debcontrolStrictField matchgroup=debcontrolKey start="^Homepage: *" end="$" contains=debcontrolHTTPUrl oneline keepend
100syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(XS-\)\=Vcs-\%(Browser\|Arch\|Bzr\|Darcs\|Hg\): *" end="$" contains=debcontrolHTTPUrl oneline keepend
101syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(XS-\)\=Vcs-Svn: *" end="$" contains=debcontrolVcsSvn,debcontrolHTTPUrl oneline keepend
102syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(XS-\)\=Vcs-Cvs: *" end="$" contains=debcontrolVcsCvs oneline keepend
103syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(XS-\)\=Vcs-Git: *" end="$" contains=debcontrolVcsGit oneline keepend
104syn region debcontrolStrictField matchgroup=debcontrolKey start="^Rules-Requires-Root: *" end="$" contains=debcontrolR3 oneline
105syn region debcontrolStrictField matchgroup=debcontrolKey start="^\%(Build-\)\=Essential: *" end="$" contains=debcontrolYesNo oneline
106
107syn region debcontrolStrictField matchgroup=debcontrolDeprecatedKey start="^\%(XS-\)\=DM-Upload-Allowed: *" end="$" contains=debcontrolDmUpload oneline
108
109" Catch-all for the other legal fields
110syn region debcontrolField matchgroup=debcontrolKey start="^\%(\%(XSBC-Original-\)\=Maintainer\|Standards-Version\|Bugs\|Origin\|X[SB]-Python-Version\|\%(XS-\)\=Vcs-Mtn\|\%(XS-\)\=Testsuite\%(-Triggers\)\=\|Build-Profiles\|Tag\|Subarchitecture\|Kernel-Version\|Installer-Menu-Item\): " end="$" contains=debcontrolVariable,debcontrolEmail oneline
111syn region debcontrolMultiField matchgroup=debcontrolKey start="^\%(Build-\%(Conflicts\|Depends\)\%(-Arch\|-Indep\)\=\|\%(Pre-\)\=Depends\|Recommends\|Suggests\|Breaks\|Enhances\|Replaces\|Conflicts\|Provides\|Built-Using\|Uploaders\|X[SBC]\{0,3\}\%(Private-\)\=-[-a-zA-Z0-9]\+\): *" skip="^[ \t]" end="^$"me=s-1 end="^[^ \t#]"me=s-1 contains=debcontrolEmail,debcontrolVariable,debcontrolComment
112syn region debcontrolMultiFieldSpell matchgroup=debcontrolKey start="^Description: *" skip="^[ \t]" end="^$"me=s-1 end="^[^ \t#]"me=s-1 contains=debcontrolEmail,debcontrolVariable,debcontrolComment,@Spell
113
114" Associate our matches and regions with pretty colours
115hi def link debcontrolKey           Keyword
116hi def link debcontrolField         Normal
117hi def link debcontrolStrictField   Error
118hi def link debcontrolDeprecatedKey Error
119hi def link debcontrolMultiField    Normal
120hi def link debcontrolArchitecture  Normal
121hi def link debcontrolMultiArch     Normal
122hi def link debcontrolName          Normal
123hi def link debcontrolPriority      Normal
124hi def link debcontrolSection       Normal
125hi def link debcontrolPackageType   Normal
126hi def link debcontrolVariable      Identifier
127hi def link debcontrolEmail         Identifier
128hi def link debcontrolVcsSvn        Identifier
129hi def link debcontrolVcsCvs        Identifier
130hi def link debcontrolVcsGit        Identifier
131hi def link debcontrolHTTPUrl       Identifier
132hi def link debcontrolDmUpload      Identifier
133hi def link debcontrolYesNo         Identifier
134hi def link debcontrolR3            Identifier
135hi def link debcontrolComment       Comment
136hi def link debcontrolElse          Special
137
138let b:current_syntax = 'debcontrol'
139
140let &cpo = s:cpo_save
141unlet s:cpo_save
142
143" vim: ts=8 sw=2
144