Karsten Hopp 50ff73
" Filename:    spec.vim
Karsten Hopp 50ff73
" Purpose:     Vim syntax file
Karsten Hopp 50ff73
" Language:    SPEC: Build/install scripts for Linux RPM packages
Karsten Hopp 50ff73
" Maintainer:  Igor Gnatenko i.gnatenko.brain@gmail.com
Karsten Hopp 50ff73
" Former Maintainer:  Donovan Rebbechi elflord@panix.com (until March 2014)
Karsten Hopp 50ff73
" Last Change: Sat Apr 9 15:30 2016 Filip SzymaƄski
Karsten Hopp 50ff73
Karsten Hopp 50ff73
" For version 5.x: Clear all syntax items
Karsten Hopp 50ff73
" For version 6.x: Quit when a syntax file was already loaded
Karsten Hopp 50ff73
if version < 600
Karsten Hopp 50ff73
  syntax clear
Karsten Hopp 50ff73
elseif exists("b:current_syntax")
Karsten Hopp 50ff73
  finish
Karsten Hopp 50ff73
endif
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn sync minlines=1000
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn match specSpecialChar contained '[][!$()\\|>^;:{}]'
Karsten Hopp 50ff73
syn match specColon       contained ':'
Karsten Hopp 50ff73
syn match specPercent     contained '%'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn match specVariables   contained '\$\h\w*' contains=specSpecialVariablesNames,specSpecialChar
Karsten Hopp 50ff73
syn match specVariables   contained '\${\w*}' contains=specSpecialVariablesNames,specSpecialChar
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn match specMacroIdentifier contained '%\h\w*' contains=specMacroNameLocal,specMacroNameOther,specPercent
Karsten Hopp 50ff73
syn match specMacroIdentifier contained '%{\w*}' contains=specMacroNameLocal,specMacroNameOther,specPercent,specSpecialChar
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn match specSpecialVariables contained '\$[0-9]\|\${[0-9]}'
Karsten Hopp 50ff73
syn match specCommandOpts      contained '\s\(-\w\+\|--\w[a-zA-Z_-]\+\)'ms=s+1
Karsten Hopp 50ff73
syn match specComment '^\s*#.*$'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn case match
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"matches with no highlight
Karsten Hopp 50ff73
syn match specNoNumberHilite 'X11\|X11R6\|[a-zA-Z]*\.\d\|[a-zA-Z][-/]\d'
Karsten Hopp 50ff73
syn match specManpageFile '[a-zA-Z]\.1'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"Day, Month and most used license acronyms
Karsten Hopp 50ff73
syn keyword specLicense contained GPL LGPL BSD MIT GNU
Karsten Hopp 50ff73
syn keyword specWeekday contained Mon Tue Wed Thu Fri Sat Sun
Karsten Hopp 50ff73
syn keyword specMonth   contained Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec
Karsten Hopp 50ff73
syn keyword specMonth   contained January February March April May June July August September October November December
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"#, @, www
Karsten Hopp 50ff73
syn match specNumber '\(^-\=\|[ \t]-\=\|-\)[0-9.-]*[0-9]'
Karsten Hopp 50ff73
syn match specEmail contained "<\=\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\+\>>\="
Karsten Hopp 50ff73
syn match specURL      contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#-]\+\>'
Karsten Hopp 50ff73
syn match specURLMacro contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#%{}-]\+\>' contains=specMacroIdentifier
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"TODO take specSpecialVariables out of the cluster for the sh* contains (ALLBUT)
Karsten Hopp 50ff73
"Special system directories
Karsten Hopp 50ff73
syn match specListedFilesPrefix contained '/\(usr\|local\|opt\|X11R6\|X11\)/'me=e-1
Karsten Hopp 50ff73
syn match specListedFilesBin    contained '/s\=bin/'me=e-1
Karsten Hopp 50ff73
syn match specListedFilesLib    contained '/\(lib\|include\)/'me=e-1
Karsten Hopp 50ff73
syn match specListedFilesDoc    contained '/\(man\d*\|doc\|info\)\>'
Karsten Hopp 50ff73
syn match specListedFilesEtc    contained '/etc/'me=e-1
Karsten Hopp 50ff73
syn match specListedFilesShare  contained '/share/'me=e-1
Karsten Hopp 50ff73
syn cluster specListedFiles contains=specListedFilesBin,specListedFilesLib,specListedFilesDoc,specListedFilesEtc,specListedFilesShare,specListedFilesPrefix,specVariables,specSpecialChar
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"specComands
Karsten Hopp 50ff73
syn match   specConfigure  contained '\./configure'
Karsten Hopp 50ff73
syn match   specTarCommand contained '\
Karsten Hopp 50ff73
syn keyword specCommandSpecial contained root
Karsten Hopp 50ff73
syn 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
Karsten Hopp 50ff73
syn cluster specCommands contains=specCommand,specTarCommand,specConfigure,specCommandSpecial
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"frequently used rpm env vars
Karsten Hopp 50ff73
syn keyword specSpecialVariablesNames contained RPM_BUILD_ROOT RPM_BUILD_DIR RPM_SOURCE_DIR RPM_OPT_FLAGS LDFLAGS CC CC_FLAGS CPPNAME CFLAGS CXX CXXFLAGS CPPFLAGS
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"valid macro names from /usr/lib/rpm/macros
Karsten Hopp 50ff73
syn keyword specMacroNameOther contained buildroot buildsubdir distribution disturl ix86 name nil optflags perl_sitearch release requires_eq vendor version
Karsten Hopp 50ff73
syn match   specMacroNameOther contained '\<\(PATCH\|SOURCE\)\d*\>'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"valid _macro names from /usr/lib/rpm/macros
Karsten Hopp 50ff73
syn keyword specMacroNameLocal contained _arch _binary_payload _bindir _build _build_alias _build_cpu _builddir _build_os _buildshell _buildsubdir _build_vendor _bzip2bin _datadir _dbpath _dbpath_rebuild _defaultdocdir _docdir _excludedocs _exec_prefix _fixgroup _fixowner _fixperms _ftpport _ftpproxy _gpg_path _gzipbin _host _host_alias _host_cpu _host_os _host_vendor _httpport _httpproxy _includedir _infodir _install_langs _install_script_path _instchangelog _langpatt _lib _libdir _libexecdir _localstatedir _mandir _netsharedpath _oldincludedir _os _pgpbin _pgp_path _prefix _preScriptEnvironment _provides _rpmdir _rpmfilename _sbindir _sharedstatedir _signature _sourcedir _source_payload _specdir _srcrpmdir _sysconfdir _target _target_alias _target_cpu _target_os _target_platform _target_vendor _timecheck _tmppath _topdir _usr _usrsrc _var _vendor
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"------------------------------------------------------------------------------
Karsten Hopp 50ff73
" here's is all the spec sections definitions: PreAmble, Description, Package,
Karsten Hopp 50ff73
"   Scripts, Files and Changelog
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"One line macros - valid in all ScriptAreas
Karsten Hopp 50ff73
"tip: remember do include new items on specScriptArea's skip section
Karsten Hopp 50ff73
syn 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
Karsten Hopp 50ff73
syn region specSectionMacroBracketArea oneline matchgroup=specSectionMacro start='^%{\(configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\)}' end='$' contains=specCommandOpts,specMacroIdentifier
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% Files Section %%
Karsten Hopp 50ff73
"TODO %config valid parameters: missingok\|noreplace
Karsten Hopp 50ff73
"TODO %verify valid parameters: \(not\)\= \(md5\|atime\|...\)
Karsten Hopp 50ff73
syn region specFilesArea matchgroup=specSection start='^%[Ff][Ii][Ll][Ee][Ss]\>' skip='%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|verify\|ghost\)\>' end='^%[a-zA-Z]'me=e-2 contains=specFilesOpts,specFilesDirective,@specListedFiles,specComment,specCommandSpecial,specMacroIdentifier
Karsten Hopp 50ff73
"tip: remember to include new itens in specFilesArea above
Karsten Hopp 50ff73
syn match  specFilesDirective contained '%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|verify\|ghost\)\>'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"valid options for certain section headers
Karsten Hopp 50ff73
syn match specDescriptionOpts contained '\s-[ln]\s*\a'ms=s+1,me=e-1
Karsten Hopp 50ff73
syn match specPackageOpts     contained    '\s-n\s*\w'ms=s+1,me=e-1
Karsten Hopp 50ff73
syn match specFilesOpts       contained    '\s-f\s*\w'ms=s+1,me=e-1
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn case ignore
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% PreAmble Section %%
Karsten Hopp 50ff73
"Copyright and Serial were deprecated by License and Epoch
Karsten Hopp 50ff73
syn region specPreAmbleDeprecated oneline matchgroup=specError start='^\(Copyright\|Serial\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
Karsten Hopp 50ff73
syn region specPreAmble oneline matchgroup=specCommand start='^\(Prereq\|Summary\|Name\|Version\|Packager\|Requires\|Recommends\|Suggests\|Supplements\|Enhances\|Icon\|URL\|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
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% Description Section %%
Karsten Hopp 50ff73
syn region specDescriptionArea matchgroup=specSection start='^%description' end='^%'me=e-1 contains=specDescriptionOpts,specEmail,specURL,specNumber,specMacroIdentifier,specComment
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% Package Section %%
Karsten Hopp 50ff73
syn region specPackageArea matchgroup=specSection start='^%package' end='^%'me=e-1 contains=specPackageOpts,specPreAmble,specComment
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% Scripts Section %%
Karsten Hopp 50ff73
syn region specScriptArea matchgroup=specSection start='^%\(prep\|build\|install\|clean\|pre\|postun\|preun\|post\|posttrans\)\>' 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
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"%% Changelog Section %%
Karsten Hopp 50ff73
syn region specChangelogArea matchgroup=specSection start='^%changelog' end='^%'me=e-1 contains=specEmail,specURL,specWeekday,specMonth,specNumber,specComment,specLicense
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"------------------------------------------------------------------------------
Karsten Hopp 50ff73
"here's the shell syntax for all the Script Sections
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn case match
Karsten Hopp 50ff73
Karsten Hopp 50ff73
Karsten Hopp 50ff73
"sh-like comment stile, only valid in script part
Karsten Hopp 50ff73
syn match shComment contained '#.*$'
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn region shQuote1 contained matchgroup=shQuoteDelim start=+'+ skip=+\\'+ end=+'+ contains=specMacroIdentifier
Karsten Hopp 50ff73
syn region shQuote2 contained matchgroup=shQuoteDelim start=+"+ skip=+\\"+ end=+"+ contains=specVariables,specMacroIdentifier
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn match shOperator contained '[><|!&;]\|[!=]='
Karsten Hopp 50ff73
syn region shDo transparent matchgroup=specBlock start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase,specPreAmble,@specListedFiles
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn region specIf  matchgroup=specBlock start="%ifosf\|%ifos\|%ifnos\|%ifarch\|%ifnarch\|%else"  end='%endif'  contains=ALLBUT, specIfError, shCase
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn region  shIf transparent matchgroup=specBlock start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase,@specListedFiles
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn region  shFor  matchgroup=specBlock start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase,@specListedFiles
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn region shCaseEsac transparent matchgroup=specBlock start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError,@specListedFiles nextgroup=shCaseEsac
Karsten Hopp 50ff73
syn region shCaseEsac matchgroup=specBlock start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError,@specListedFilesBin
Karsten Hopp 50ff73
syn region shCase matchgroup=specBlock contained start=")"  end=";;" contains=ALLBUT,shFunction,shCaseError,shCase,@specListedFiles
Karsten Hopp 50ff73
Karsten Hopp 50ff73
syn sync match shDoSync       grouphere  shDo       "\<do\>"
Karsten Hopp 50ff73
syn sync match shDoSync       groupthere shDo       "\<done\>"
Karsten Hopp 50ff73
syn sync match shIfSync       grouphere  shIf       "\<if\>"
Karsten Hopp 50ff73
syn sync match shIfSync       groupthere shIf       "\<fi\>"
Karsten Hopp 50ff73
syn sync match specIfSync     grouphere  specIf     "%ifarch\|%ifos\|%ifnos"
Karsten Hopp 50ff73
syn sync match specIfSync     groupthere specIf     "%endIf"
Karsten Hopp 50ff73
syn sync match shForSync      grouphere  shFor      "\<for\>"
Karsten Hopp 50ff73
syn sync match shForSync      groupthere shFor      "\<in\>"
Karsten Hopp 50ff73
syn sync match shCaseEsacSync grouphere  shCaseEsac "\<case\>"
Karsten Hopp 50ff73
syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
Karsten Hopp 50ff73
Karsten Hopp 50ff73
" Define the default highlighting.
Karsten Hopp 50ff73
" For version 5.7 and earlier: only when not done already
Karsten Hopp 50ff73
" For version 5.8 and later: only when an item doesn't have highlighting yet
Karsten Hopp 50ff73
if version >= 508 || !exists("did_spec_syntax_inits")
Karsten Hopp 50ff73
  if version < 508
Karsten Hopp 50ff73
    let did_spec_syntax_inits = 1
Karsten Hopp 50ff73
    command -nargs=+ HiLink hi link <args>
Karsten Hopp 50ff73
  else
Karsten Hopp 50ff73
    command -nargs=+ HiLink hi def link <args>
Karsten Hopp 50ff73
  endif
Karsten Hopp 50ff73
Karsten Hopp 50ff73
  "main types color definitions
Karsten Hopp 50ff73
  HiLink specSection			Structure
Karsten Hopp 50ff73
  HiLink specSectionMacro		Macro
Karsten Hopp 50ff73
  HiLink specWWWlink			PreProc
Karsten Hopp 50ff73
  HiLink specOpts			Operator
Karsten Hopp 50ff73
Karsten Hopp 50ff73
  "yes, it's ugly, but white is sooo cool
Karsten Hopp 50ff73
  if &background == "dark"
Karsten Hopp 50ff73
    hi def specGlobalMacro		ctermfg=white
Karsten Hopp 50ff73
  else
Karsten Hopp 50ff73
    HiLink specGlobalMacro		Identifier
Karsten Hopp 50ff73
  endif
Karsten Hopp 50ff73
Karsten Hopp 50ff73
  "sh colors
Karsten Hopp 50ff73
  HiLink shComment			Comment
Karsten Hopp 50ff73
  HiLink shIf				Statement
Karsten Hopp 50ff73
  HiLink shOperator			Special
Karsten Hopp 50ff73
  HiLink shQuote1			String
Karsten Hopp 50ff73
  HiLink shQuote2			String
Karsten Hopp 50ff73
  HiLink shQuoteDelim			Statement
Karsten Hopp 50ff73
Karsten Hopp 50ff73
  "spec colors
Karsten Hopp 50ff73
  HiLink specBlock			Function
Karsten Hopp 50ff73
  HiLink specColon			Special
Karsten Hopp 50ff73
  HiLink specCommand			Statement
Karsten Hopp 50ff73
  HiLink specCommandOpts		specOpts
Karsten Hopp 50ff73
  HiLink specCommandSpecial		Special
Karsten Hopp 50ff73
  HiLink specComment			Comment
Karsten Hopp 50ff73
  HiLink specConfigure			specCommand
Karsten Hopp 50ff73
  HiLink specDate			String
Karsten Hopp 50ff73
  HiLink specDescriptionOpts		specOpts
Karsten Hopp 50ff73
  HiLink specEmail			specWWWlink
Karsten Hopp 50ff73
  HiLink specError			Error
Karsten Hopp 50ff73
  HiLink specFilesDirective		specSectionMacro
Karsten Hopp 50ff73
  HiLink specFilesOpts			specOpts
Karsten Hopp 50ff73
  HiLink specLicense			String
Karsten Hopp 50ff73
  HiLink specMacroNameLocal		specGlobalMacro
Karsten Hopp 50ff73
  HiLink specMacroNameOther		specGlobalMacro
Karsten Hopp 50ff73
  HiLink specManpageFile		NONE
Karsten Hopp 50ff73
  HiLink specMonth			specDate
Karsten Hopp 50ff73
  HiLink specNoNumberHilite		NONE
Karsten Hopp 50ff73
  HiLink specNumber			Number
Karsten Hopp 50ff73
  HiLink specPackageOpts		specOpts
Karsten Hopp 50ff73
  HiLink specPercent			Special
Karsten Hopp 50ff73
  HiLink specSpecialChar		Special
Karsten Hopp 50ff73
  HiLink specSpecialVariables		specGlobalMacro
Karsten Hopp 50ff73
  HiLink specSpecialVariablesNames	specGlobalMacro
Karsten Hopp 50ff73
  HiLink specTarCommand			specCommand
Karsten Hopp 50ff73
  HiLink specURL			specWWWlink
Karsten Hopp 50ff73
  HiLink specURLMacro			specWWWlink
Karsten Hopp 50ff73
  HiLink specVariables			Identifier
Karsten Hopp 50ff73
  HiLink specWeekday			specDate
Karsten Hopp 50ff73
  HiLink specListedFilesBin		Statement
Karsten Hopp 50ff73
  HiLink specListedFilesDoc		Statement
Karsten Hopp 50ff73
  HiLink specListedFilesEtc		Statement
Karsten Hopp 50ff73
  HiLink specListedFilesLib		Statement
Karsten Hopp 50ff73
  HiLink specListedFilesPrefix		Statement
Karsten Hopp 50ff73
  HiLink specListedFilesShare		Statement
Karsten Hopp 50ff73
Karsten Hopp 50ff73
  delcommand HiLink
Karsten Hopp 50ff73
endif
Karsten Hopp 50ff73
Karsten Hopp 50ff73
let b:current_syntax = "spec"
Karsten Hopp 50ff73
Karsten Hopp 50ff73
" vim: ts=8