1" Vim syntax file
2" Language:    Debian control files
3" Maintainer:  Debian Vim Maintainers <[email protected]>
4" Former Maintainers: Gerfried Fuchs <[email protected]>
5"                     Wichert Akkerman <[email protected]>
6" Last Change: 2017 Nov 04
7" URL: https://anonscm.debian.org/cgit/pkg-vim/vim.git/plain/runtime/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', 'javascript', '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" List of all legal keys, in order, from deb-src-control(5)
91" Source fields
92syn match debcontrolKey contained "^\%(Source\|Maintainer\|Uploaders\|Standards-Version\|Description\|Homepage\|Bugs\|Rules-Requires-Root\): *"
93syn match debcontrolKey contained "^\%(XS-\)\=Vcs-\%(Arch\|Bzr\|Cvs\|Darcs\|Git\|Hg\|Mtn\|Svn\|Browser\): *"
94syn match debcontrolKey contained "^\%(Origin\|Section\|Priority\): *"
95syn match debcontrolKey contained "^Build-\%(Depends\|Conflicts\)\%(-Arch\|-Indep\)\=: *"
96
97" Binary fields
98syn match debcontrolKey contained "^\%(Package\%(-Type\)\=\|Architecture\|Build-Profiles\): *"
99syn match debcontrolKey contained "^\%(\%(Build-\)\=Essential\|Multi-Arch\|Tag\): *"
100syn match debcontrolKey contained "^\%(\%(Pre-\)\=Depends\|Recommends\|Suggests\|Breaks\|Enhances\|Replaces\|Conflicts\|Provides\|Built-Using\): *"
101syn match debcontrolKey contained "^\%(Subarchitecture\|Kernel-Version\|Installer-Menu-Item\): *"
102
103" User-defined fields
104syn match debcontrolKey contained "^X[SBC]\{0,3\}\%(-Private\)\=-[-a-zA-Z0-9]\+: *"
105
106syn match debcontrolDeprecatedKey contained "^\%(\%(XS-\)\=DM-Upload-Allowed\): *"
107
108" Fields for which we do strict syntax checking
109syn region debcontrolStrictField start="^Architecture" end="$" contains=debcontrolKey,debcontrolArchitecture,debcontrolSpace oneline
110syn region debcontrolStrictField start="^Multi-Arch" end="$" contains=debcontrolKey,debcontrolMultiArch oneline
111syn region debcontrolStrictField start="^\%(Package\|Source\)" end="$" contains=debcontrolKey,debcontrolName oneline
112syn region debcontrolStrictField start="^Priority" end="$" contains=debcontrolKey,debcontrolPriority oneline
113syn region debcontrolStrictField start="^Section" end="$" contains=debcontrolKey,debcontrolSection oneline
114syn region debcontrolStrictField start="^\%(XC-\)\=Package-Type" end="$" contains=debcontrolKey,debcontrolPackageType oneline
115syn region debcontrolStrictField start="^Homepage" end="$" contains=debcontrolKey,debcontrolHTTPUrl oneline keepend
116syn region debcontrolStrictField start="^\%(XS-\)\=Vcs-\%(Browser\|Arch\|Bzr\|Darcs\|Hg\)" end="$" contains=debcontrolKey,debcontrolHTTPUrl oneline keepend
117syn region debcontrolStrictField start="^\%(XS-\)\=Vcs-Svn" end="$" contains=debcontrolKey,debcontrolVcsSvn,debcontrolHTTPUrl oneline keepend
118syn region debcontrolStrictField start="^\%(XS-\)\=Vcs-Cvs" end="$" contains=debcontrolKey,debcontrolVcsCvs oneline keepend
119syn region debcontrolStrictField start="^\%(XS-\)\=Vcs-Git" end="$" contains=debcontrolKey,debcontrolVcsGit oneline keepend
120syn region debcontrolStrictField start="^\%(XS-\)\=DM-Upload-Allowed" end="$" contains=debcontrolDeprecatedKey,debcontrolDmUpload oneline
121syn region debcontrolStrictField start="^Rules-Requires-Root" end="$" contains=debcontrolKey,debcontrolR3 oneline
122syn region debcontrolStrictField start="^\%(Build-\)\=Essential" end="$" contains=debcontrolKey,debcontrolYesNo oneline
123
124" Catch-all for the other legal fields
125syn region debcontrolField start="^\%(\%(XSBC-Original-\)\=Maintainer\|Standards-Version\|Bugs\|Origin\|X[SB]-Python-Version\|\%(XS-\)\=Vcs-Mtn\|\%(XS-\)\=Testsuite\|Build-Profiles\|Tag\|Subarchitecture\|Kernel-Version\|Installer-Menu-Item\):" end="$" contains=debcontrolKey,debcontrolVariable,debcontrolEmail oneline
126syn region debcontrolMultiField 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=debcontrolKey,debcontrolEmail,debcontrolVariable,debcontrolComment
127syn region debcontrolMultiFieldSpell start="^\%(Description\):" skip="^[ \t]" end="^$"me=s-1 end="^[^ \t#]"me=s-1 contains=debcontrolKey,debcontrolEmail,debcontrolVariable,debcontrolComment,@Spell
128
129" Associate our matches and regions with pretty colours
130hi def link debcontrolKey           Keyword
131hi def link debcontrolField         Normal
132hi def link debcontrolStrictField   Error
133hi def link debcontrolDeprecatedKey Error
134hi def link debcontrolMultiField    Normal
135hi def link debcontrolArchitecture  Normal
136hi def link debcontrolMultiArch     Normal
137hi def link debcontrolName          Normal
138hi def link debcontrolPriority      Normal
139hi def link debcontrolSection       Normal
140hi def link debcontrolPackageType   Normal
141hi def link debcontrolVariable      Identifier
142hi def link debcontrolEmail         Identifier
143hi def link debcontrolVcsSvn        Identifier
144hi def link debcontrolVcsCvs        Identifier
145hi def link debcontrolVcsGit        Identifier
146hi def link debcontrolHTTPUrl       Identifier
147hi def link debcontrolDmUpload      Identifier
148hi def link debcontrolYesNo         Identifier
149hi def link debcontrolR3            Identifier
150hi def link debcontrolComment       Comment
151hi def link debcontrolElse          Special
152
153let b:current_syntax = "debcontrol"
154
155let &cpo = s:cpo_save
156unlet s:cpo_save
157
158" vim: ts=8 sw=2
159