blob: 944bdcaa3756c00a8551b68b669c1f4c4b8cb9b2 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Filename: spec.vim
2" Purpose: Vim syntax file
3" Language: SPEC: Build/install scripts for Linux RPM packages
Bram Moolenaar08589172014-03-08 18:38:28 +01004" Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com
5" Former Maintainer: Donovan Rebbechi elflord@panix.com (until March 2014)
Bram Moolenaar388a5d42020-05-26 21:20:45 +02006" Last Change: 2020 May 25
fundawang2241f082024-09-10 21:31:49 +02007" 2024 Sep 10 by Vim Project: add file triggers support, #15569
fundawangadfeb4a2025-05-05 20:12:40 +02008" 2025 May 05 by Vim Project: update for rpm 4.2 #17258
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020010" quit when a syntax file was already loaded
11if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000012 finish
13endif
14
15syn sync minlines=1000
16
17syn match specSpecialChar contained '[][!$()\\|>^;:{}]'
18syn match specColon contained ':'
19syn match specPercent contained '%'
20
21syn match specVariables contained '\$\h\w*' contains=specSpecialVariablesNames,specSpecialChar
22syn match specVariables contained '\${\w*}' contains=specSpecialVariablesNames,specSpecialChar
23
24syn match specMacroIdentifier contained '%\h\w*' contains=specMacroNameLocal,specMacroNameOther,specPercent
25syn match specMacroIdentifier contained '%{\w*}' contains=specMacroNameLocal,specMacroNameOther,specPercent,specSpecialChar
26
27syn match specSpecialVariables contained '\$[0-9]\|\${[0-9]}'
28syn match specCommandOpts contained '\s\(-\w\+\|--\w[a-zA-Z_-]\+\)'ms=s+1
29syn match specComment '^\s*#.*$'
30
31
32syn case match
33
34
35"matches with no highlight
36syn match specNoNumberHilite 'X11\|X11R6\|[a-zA-Z]*\.\d\|[a-zA-Z][-/]\d'
37syn match specManpageFile '[a-zA-Z]\.1'
38
39"Day, Month and most used license acronyms
40syn keyword specLicense contained GPL LGPL BSD MIT GNU
41syn keyword specWeekday contained Mon Tue Wed Thu Fri Sat Sun
42syn keyword specMonth contained Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec
43syn keyword specMonth contained January February March April May June July August September October November December
44
45"#, @, www
46syn match specNumber '\(^-\=\|[ \t]-\=\|-\)[0-9.-]*[0-9]'
47syn match specEmail contained "<\=\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\+\>>\="
48syn match specURL contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#-]\+\>'
49syn match specURLMacro contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#%{}-]\+\>' contains=specMacroIdentifier
50
51"TODO take specSpecialVariables out of the cluster for the sh* contains (ALLBUT)
52"Special system directories
53syn match specListedFilesPrefix contained '/\(usr\|local\|opt\|X11R6\|X11\)/'me=e-1
54syn match specListedFilesBin contained '/s\=bin/'me=e-1
55syn match specListedFilesLib contained '/\(lib\|include\)/'me=e-1
56syn match specListedFilesDoc contained '/\(man\d*\|doc\|info\)\>'
57syn match specListedFilesEtc contained '/etc/'me=e-1
58syn match specListedFilesShare contained '/share/'me=e-1
59syn cluster specListedFiles contains=specListedFilesBin,specListedFilesLib,specListedFilesDoc,specListedFilesEtc,specListedFilesShare,specListedFilesPrefix,specVariables,specSpecialChar
60
Viktor Szépe3fc7a7e2023-08-23 21:20:00 +020061"specCommands
Bram Moolenaar071d4272004-06-13 20:20:40 +000062syn match specConfigure contained '\./configure'
63syn match specTarCommand contained '\<tar\s\+[cxvpzIf]\{,5}\s*'
64syn keyword specCommandSpecial contained root
65syn keyword specCommand contained make xmkmf mkdir chmod ln find sed rm strip moc echo grep ls rm mv mkdir install cp pwd cat tail then else elif cd gzip rmdir ln eval export touch
66syn cluster specCommands contains=specCommand,specTarCommand,specConfigure,specCommandSpecial
67
68"frequently used rpm env vars
69syn keyword specSpecialVariablesNames contained RPM_BUILD_ROOT RPM_BUILD_DIR RPM_SOURCE_DIR RPM_OPT_FLAGS LDFLAGS CC CC_FLAGS CPPNAME CFLAGS CXX CXXFLAGS CPPFLAGS
70
71"valid macro names from /usr/lib/rpm/macros
72syn keyword specMacroNameOther contained buildroot buildsubdir distribution disturl ix86 name nil optflags perl_sitearch release requires_eq vendor version
73syn match specMacroNameOther contained '\<\(PATCH\|SOURCE\)\d*\>'
74
75"valid _macro names from /usr/lib/rpm/macros
fundawangadfeb4a2025-05-05 20:12:40 +020076syn keyword specMacroNameLocal contained _arch _binary_payload _bindir _build _build_alias _build_cpu _build_os _build_vendor _builddir _buildshell _buildsubdir _bzip2bin _datadir _dbpath _dbpath_rebuild _defaultdocdir _defaultlicensedir _docdir _excludedocs _exec_prefix _fixgroup _fixowner _fixperms _ftpport _ftpproxy _gpg_path _group_path _gzipbin _host _host_alias _host_cpu _host_os _host_vendor _httpport _httpproxy _iconsdir _includedir _infodir _install_langs _install_script_path _instchangelog _keyring _keyringpath _langpatt _lib _libdir _libexecdir _localstatedir _mandir _netsharedpath _oldincludedir _os _passwd_path _pgp_path _pgpbin _preScriptEnvironment _prefix _provides _rpmconfigdir _rpmdir _rpmfilename _rpmformat _rpmluadir _rpmmacrodir _sbindir _sharedstatedir _signature _source_payload _sourcedir _specdir _srcrpmdir _sysconfdir _sysusersdir _target _target_alias _target_cpu _target_os _target_platform _target_vendor _timecheck _tmppath _topdir _unitdir _usr _usrsrc _var _vendor
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
78
79"------------------------------------------------------------------------------
80" here's is all the spec sections definitions: PreAmble, Description, Package,
81" Scripts, Files and Changelog
82
83"One line macros - valid in all ScriptAreas
Bram Moolenaardef9e822004-12-31 20:58:58 +000084"tip: remember do include new items on specScriptArea's skip section
Bram Moolenaar82af8712016-06-04 20:20:29 +020085syn region specSectionMacroArea oneline matchgroup=specSectionMacro start='^%\(define\|global\|patch\d*\|setup\|autosetup\|autopatch\|configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\|include\)\>' end='$' contains=specCommandOpts,specMacroIdentifier
86syn region specSectionMacroBracketArea oneline matchgroup=specSectionMacro start='^%{\(configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\)}' end='$' contains=specCommandOpts,specMacroIdentifier
Bram Moolenaar071d4272004-06-13 20:20:40 +000087
88"%% Files Section %%
89"TODO %config valid parameters: missingok\|noreplace
90"TODO %verify valid parameters: \(not\)\= \(md5\|atime\|...\)
Bram Moolenaara6c27c42019-05-09 19:16:22 +020091syn region specFilesArea matchgroup=specSection start='^%[Ff][Ii][Ll][Ee][Ss]\>' skip='%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|license\|verify\|ghost\|exclude\)\>' end='^%[a-zA-Z]'me=e-2 contains=specFilesOpts,specFilesDirective,@specListedFiles,specComment,specCommandSpecial,specMacroIdentifier
Viktor Szépe3fc7a7e2023-08-23 21:20:00 +020092"tip: remember to include new items in specFilesArea above
Bram Moolenaara6c27c42019-05-09 19:16:22 +020093syn match specFilesDirective contained '%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|license\|verify\|ghost\|exclude\)\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
95"valid options for certain section headers
96syn match specDescriptionOpts contained '\s-[ln]\s*\a'ms=s+1,me=e-1
97syn match specPackageOpts contained '\s-n\s*\w'ms=s+1,me=e-1
98syn match specFilesOpts contained '\s-f\s*\w'ms=s+1,me=e-1
99
100
101syn case ignore
102
103
104"%% PreAmble Section %%
105"Copyright and Serial were deprecated by License and Epoch
106syn region specPreAmbleDeprecated oneline matchgroup=specError start='^\(Copyright\|Serial\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
Petr Pisar315cd1f2024-02-22 20:39:09 +0100107syn region specPreAmble oneline matchgroup=specCommand start='^\(Prereq\|Summary\|Name\|Version\|Packager\|Requires\|Recommends\|Suggests\|Supplements\|Enhances\|Icon\|URL\|SourceLicense\|Source\d*\|Patch\d*\|Prefix\|Packager\|Group\|License\|Release\|BuildRoot\|Distribution\|Vendor\|Provides\|ExclusiveArch\|ExcludeArch\|ExclusiveOS\|Obsoletes\|BuildArch\|BuildArchitectures\|BuildRequires\|BuildConflicts\|BuildPreReq\|Conflicts\|AutoRequires\|AutoReq\|AutoReqProv\|AutoProv\|Epoch\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
109"%% Description Section %%
110syn region specDescriptionArea matchgroup=specSection start='^%description' end='^%'me=e-1 contains=specDescriptionOpts,specEmail,specURL,specNumber,specMacroIdentifier,specComment
111
112"%% Package Section %%
113syn region specPackageArea matchgroup=specSection start='^%package' end='^%'me=e-1 contains=specPackageOpts,specPreAmble,specComment
114
115"%% Scripts Section %%
fundawang2241f082024-09-10 21:31:49 +0200116syn region specScriptArea matchgroup=specSection start='^%\(prep\|generate_buildrequires\|conf\|build\|install\|clean\|check\|pre\|postun\|preun\|post\|posttrans\|filetriggerin\|filetriggerun\|filetriggerpostun\|transfiletriggerin\|transfiletriggerun\|transfiletriggerpostun\)\>' skip='^%{\|^%\(define\|patch\d*\|configure\|GNUconfigure\|setup\|autosetup\|autopatch\|find_lang\|make_build\|makeinstall\|make_install\)\>' end='^%'me=e-1 contains=specSpecialVariables,specVariables,@specCommands,specVariables,shDo,shFor,shCaseEsac,specNoNumberHilite,specCommandOpts,shComment,shIf,specSpecialChar,specMacroIdentifier,specSectionMacroArea,specSectionMacroBracketArea,shOperator,shQuote1,shQuote2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117
118"%% Changelog Section %%
119syn region specChangelogArea matchgroup=specSection start='^%changelog' end='^%'me=e-1 contains=specEmail,specURL,specWeekday,specMonth,specNumber,specComment,specLicense
120
121
122
123"------------------------------------------------------------------------------
124"here's the shell syntax for all the Script Sections
125
126
127syn case match
128
129
130"sh-like comment stile, only valid in script part
131syn match shComment contained '#.*$'
132
Bram Moolenaar388a5d42020-05-26 21:20:45 +0200133syn region dnlComment matchgroup=specComment start=+%dnl+ end=+$+
134
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135syn region shQuote1 contained matchgroup=shQuoteDelim start=+'+ skip=+\\'+ end=+'+ contains=specMacroIdentifier
136syn region shQuote2 contained matchgroup=shQuoteDelim start=+"+ skip=+\\"+ end=+"+ contains=specVariables,specMacroIdentifier
137
138syn match shOperator contained '[><|!&;]\|[!=]='
139syn region shDo transparent matchgroup=specBlock start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase,specPreAmble,@specListedFiles
140
141syn region specIf matchgroup=specBlock start="%ifosf\|%ifos\|%ifnos\|%ifarch\|%ifnarch\|%else" end='%endif' contains=ALLBUT, specIfError, shCase
142
143syn region shIf transparent matchgroup=specBlock start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase,@specListedFiles
144
145syn region shFor matchgroup=specBlock start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase,@specListedFiles
146
147syn region shCaseEsac transparent matchgroup=specBlock start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError,@specListedFiles nextgroup=shCaseEsac
148syn region shCaseEsac matchgroup=specBlock start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError,@specListedFilesBin
149syn region shCase matchgroup=specBlock contained start=")" end=";;" contains=ALLBUT,shFunction,shCaseError,shCase,@specListedFiles
150
151syn sync match shDoSync grouphere shDo "\<do\>"
152syn sync match shDoSync groupthere shDo "\<done\>"
153syn sync match shIfSync grouphere shIf "\<if\>"
154syn sync match shIfSync groupthere shIf "\<fi\>"
155syn sync match specIfSync grouphere specIf "%ifarch\|%ifos\|%ifnos"
156syn sync match specIfSync groupthere specIf "%endIf"
157syn sync match shForSync grouphere shFor "\<for\>"
158syn sync match shForSync groupthere shFor "\<in\>"
159syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
160syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
161
162" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200163" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200165"main types color definitions
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200166hi def link specSection Structure
167hi def link specSectionMacro Macro
168hi def link specWWWlink PreProc
169hi def link specOpts Operator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200171"yes, it's ugly, but white is sooo cool
172if &background == "dark"
173hi def specGlobalMacro ctermfg=white
174else
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200175hi def link specGlobalMacro Identifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176endif
177
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200178"sh colors
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200179hi def link shComment Comment
Bram Moolenaar388a5d42020-05-26 21:20:45 +0200180hi def link dnlComment Comment
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200181hi def link shIf Statement
182hi def link shOperator Special
183hi def link shQuote1 String
184hi def link shQuote2 String
185hi def link shQuoteDelim Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200186
187"spec colors
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200188hi def link specBlock Function
189hi def link specColon Special
190hi def link specCommand Statement
191hi def link specCommandOpts specOpts
192hi def link specCommandSpecial Special
193hi def link specComment Comment
194hi def link specConfigure specCommand
195hi def link specDate String
196hi def link specDescriptionOpts specOpts
197hi def link specEmail specWWWlink
198hi def link specError Error
199hi def link specFilesDirective specSectionMacro
200hi def link specFilesOpts specOpts
201hi def link specLicense String
202hi def link specMacroNameLocal specGlobalMacro
203hi def link specMacroNameOther specGlobalMacro
204hi def link specManpageFile NONE
205hi def link specMonth specDate
206hi def link specNoNumberHilite NONE
207hi def link specNumber Number
208hi def link specPackageOpts specOpts
209hi def link specPercent Special
210hi def link specSpecialChar Special
211hi def link specSpecialVariables specGlobalMacro
212hi def link specSpecialVariablesNames specGlobalMacro
213hi def link specTarCommand specCommand
214hi def link specURL specWWWlink
215hi def link specURLMacro specWWWlink
216hi def link specVariables Identifier
217hi def link specWeekday specDate
218hi def link specListedFilesBin Statement
219hi def link specListedFilesDoc Statement
220hi def link specListedFilesEtc Statement
221hi def link specListedFilesLib Statement
222hi def link specListedFilesPrefix Statement
223hi def link specListedFilesShare Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200224
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200225
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226let b:current_syntax = "spec"
227
228" vim: ts=8