lkundrak / rpms / vim

Forked from rpms/vim 4 years ago
Clone
50ff73b
" Filename:    spec.vim
50ff73b
" Purpose:     Vim syntax file
50ff73b
" Language:    SPEC: Build/install scripts for Linux RPM packages
50ff73b
" Maintainer:  Igor Gnatenko i.gnatenko.brain@gmail.com
50ff73b
" Former Maintainer:  Donovan Rebbechi elflord@panix.com (until March 2014)
50ff73b
" Last Change: Sat Apr 9 15:30 2016 Filip SzymaƄski
50ff73b
50ff73b
" For version 5.x: Clear all syntax items
50ff73b
" For version 6.x: Quit when a syntax file was already loaded
50ff73b
if version < 600
50ff73b
  syntax clear
50ff73b
elseif exists("b:current_syntax")
50ff73b
  finish
50ff73b
endif
50ff73b
50ff73b
syn sync minlines=1000
50ff73b
50ff73b
syn match specSpecialChar contained '[][!$()\\|>^;:{}]'
50ff73b
syn match specColon       contained ':'
50ff73b
syn match specPercent     contained '%'
50ff73b
50ff73b
syn match specVariables   contained '\$\h\w*' contains=specSpecialVariablesNames,specSpecialChar
50ff73b
syn match specVariables   contained '\${\w*}' contains=specSpecialVariablesNames,specSpecialChar
50ff73b
50ff73b
syn match specMacroIdentifier contained '%\h\w*' contains=specMacroNameLocal,specMacroNameOther,specPercent
50ff73b
syn match specMacroIdentifier contained '%{\w*}' contains=specMacroNameLocal,specMacroNameOther,specPercent,specSpecialChar
50ff73b
50ff73b
syn match specSpecialVariables contained '\$[0-9]\|\${[0-9]}'
50ff73b
syn match specCommandOpts      contained '\s\(-\w\+\|--\w[a-zA-Z_-]\+\)'ms=s+1
50ff73b
syn match specComment '^\s*#.*$'
50ff73b
50ff73b
50ff73b
syn case match
50ff73b
50ff73b
50ff73b
"matches with no highlight
50ff73b
syn match specNoNumberHilite 'X11\|X11R6\|[a-zA-Z]*\.\d\|[a-zA-Z][-/]\d'
50ff73b
syn match specManpageFile '[a-zA-Z]\.1'
50ff73b
50ff73b
"Day, Month and most used license acronyms
50ff73b
syn keyword specLicense contained GPL LGPL BSD MIT GNU
50ff73b
syn keyword specWeekday contained Mon Tue Wed Thu Fri Sat Sun
50ff73b
syn keyword specMonth   contained Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec
50ff73b
syn keyword specMonth   contained January February March April May June July August September October November December
50ff73b
50ff73b
"#, @, www
50ff73b
syn match specNumber '\(^-\=\|[ \t]-\=\|-\)[0-9.-]*[0-9]'
50ff73b
syn match specEmail contained "<\=\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\+\>>\="
50ff73b
syn match specURL      contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#-]\+\>'
50ff73b
syn match specURLMacro contained '\<\(\(https\{0,1}\|ftp\)://\|\(www[23]\{0,1}\.\|ftp\.\)\)[A-Za-z0-9._/~:,#%{}-]\+\>' contains=specMacroIdentifier
50ff73b
50ff73b
"TODO take specSpecialVariables out of the cluster for the sh* contains (ALLBUT)
50ff73b
"Special system directories
50ff73b
syn match specListedFilesPrefix contained '/\(usr\|local\|opt\|X11R6\|X11\)/'me=e-1
50ff73b
syn match specListedFilesBin    contained '/s\=bin/'me=e-1
50ff73b
syn match specListedFilesLib    contained '/\(lib\|include\)/'me=e-1
50ff73b
syn match specListedFilesDoc    contained '/\(man\d*\|doc\|info\)\>'
50ff73b
syn match specListedFilesEtc    contained '/etc/'me=e-1
50ff73b
syn match specListedFilesShare  contained '/share/'me=e-1
50ff73b
syn cluster specListedFiles contains=specListedFilesBin,specListedFilesLib,specListedFilesDoc,specListedFilesEtc,specListedFilesShare,specListedFilesPrefix,specVariables,specSpecialChar
50ff73b
50ff73b
"specComands
50ff73b
syn match   specConfigure  contained '\./configure'
50ff73b
syn match   specTarCommand contained '\
50ff73b
syn keyword specCommandSpecial contained root
50ff73b
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
50ff73b
syn cluster specCommands contains=specCommand,specTarCommand,specConfigure,specCommandSpecial
50ff73b
50ff73b
"frequently used rpm env vars
50ff73b
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
50ff73b
50ff73b
"valid macro names from /usr/lib/rpm/macros
50ff73b
syn keyword specMacroNameOther contained buildroot buildsubdir distribution disturl ix86 name nil optflags perl_sitearch release requires_eq vendor version
50ff73b
syn match   specMacroNameOther contained '\<\(PATCH\|SOURCE\)\d*\>'
50ff73b
50ff73b
"valid _macro names from /usr/lib/rpm/macros
50ff73b
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
50ff73b
50ff73b
50ff73b
"------------------------------------------------------------------------------
50ff73b
" here's is all the spec sections definitions: PreAmble, Description, Package,
50ff73b
"   Scripts, Files and Changelog
50ff73b
50ff73b
"One line macros - valid in all ScriptAreas
50ff73b
"tip: remember do include new items on specScriptArea's skip section
50ff73b
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
50ff73b
syn region specSectionMacroBracketArea oneline matchgroup=specSectionMacro start='^%{\(configure\|GNUconfigure\|find_lang\|make_build\|makeinstall\|make_install\)}' end='$' contains=specCommandOpts,specMacroIdentifier
50ff73b
50ff73b
"%% Files Section %%
50ff73b
"TODO %config valid parameters: missingok\|noreplace
50ff73b
"TODO %verify valid parameters: \(not\)\= \(md5\|atime\|...\)
50ff73b
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
50ff73b
"tip: remember to include new itens in specFilesArea above
50ff73b
syn match  specFilesDirective contained '%\(attrib\|defattr\|attr\|dir\|config\|docdir\|doc\|lang\|verify\|ghost\)\>'
50ff73b
50ff73b
"valid options for certain section headers
50ff73b
syn match specDescriptionOpts contained '\s-[ln]\s*\a'ms=s+1,me=e-1
50ff73b
syn match specPackageOpts     contained    '\s-n\s*\w'ms=s+1,me=e-1
50ff73b
syn match specFilesOpts       contained    '\s-f\s*\w'ms=s+1,me=e-1
50ff73b
50ff73b
50ff73b
syn case ignore
50ff73b
50ff73b
50ff73b
"%% PreAmble Section %%
50ff73b
"Copyright and Serial were deprecated by License and Epoch
50ff73b
syn region specPreAmbleDeprecated oneline matchgroup=specError start='^\(Copyright\|Serial\)' end='$' contains=specEmail,specURL,specURLMacro,specLicense,specColon,specVariables,specSpecialChar,specMacroIdentifier
50ff73b
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
50ff73b
50ff73b
"%% Description Section %%
50ff73b
syn region specDescriptionArea matchgroup=specSection start='^%description' end='^%'me=e-1 contains=specDescriptionOpts,specEmail,specURL,specNumber,specMacroIdentifier,specComment
50ff73b
50ff73b
"%% Package Section %%
50ff73b
syn region specPackageArea matchgroup=specSection start='^%package' end='^%'me=e-1 contains=specPackageOpts,specPreAmble,specComment
50ff73b
50ff73b
"%% Scripts Section %%
50ff73b
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
50ff73b
50ff73b
"%% Changelog Section %%
50ff73b
syn region specChangelogArea matchgroup=specSection start='^%changelog' end='^%'me=e-1 contains=specEmail,specURL,specWeekday,specMonth,specNumber,specComment,specLicense
50ff73b
50ff73b
50ff73b
50ff73b
"------------------------------------------------------------------------------
50ff73b
"here's the shell syntax for all the Script Sections
50ff73b
50ff73b
50ff73b
syn case match
50ff73b
50ff73b
50ff73b
"sh-like comment stile, only valid in script part
50ff73b
syn match shComment contained '#.*$'
50ff73b
50ff73b
syn region shQuote1 contained matchgroup=shQuoteDelim start=+'+ skip=+\\'+ end=+'+ contains=specMacroIdentifier
50ff73b
syn region shQuote2 contained matchgroup=shQuoteDelim start=+"+ skip=+\\"+ end=+"+ contains=specVariables,specMacroIdentifier
50ff73b
50ff73b
syn match shOperator contained '[><|!&;]\|[!=]='
50ff73b
syn region shDo transparent matchgroup=specBlock start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase,specPreAmble,@specListedFiles
50ff73b
50ff73b
syn region specIf  matchgroup=specBlock start="%ifosf\|%ifos\|%ifnos\|%ifarch\|%ifnarch\|%else"  end='%endif'  contains=ALLBUT, specIfError, shCase
50ff73b
50ff73b
syn region  shIf transparent matchgroup=specBlock start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase,@specListedFiles
50ff73b
50ff73b
syn region  shFor  matchgroup=specBlock start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase,@specListedFiles
50ff73b
50ff73b
syn region shCaseEsac transparent matchgroup=specBlock start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError,@specListedFiles nextgroup=shCaseEsac
50ff73b
syn region shCaseEsac matchgroup=specBlock start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError,@specListedFilesBin
50ff73b
syn region shCase matchgroup=specBlock contained start=")"  end=";;" contains=ALLBUT,shFunction,shCaseError,shCase,@specListedFiles
50ff73b
50ff73b
syn sync match shDoSync       grouphere  shDo       "\<do\>"
50ff73b
syn sync match shDoSync       groupthere shDo       "\<done\>"
50ff73b
syn sync match shIfSync       grouphere  shIf       "\<if\>"
50ff73b
syn sync match shIfSync       groupthere shIf       "\<fi\>"
50ff73b
syn sync match specIfSync     grouphere  specIf     "%ifarch\|%ifos\|%ifnos"
50ff73b
syn sync match specIfSync     groupthere specIf     "%endIf"
50ff73b
syn sync match shForSync      grouphere  shFor      "\<for\>"
50ff73b
syn sync match shForSync      groupthere shFor      "\<in\>"
50ff73b
syn sync match shCaseEsacSync grouphere  shCaseEsac "\<case\>"
50ff73b
syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
50ff73b
50ff73b
" Define the default highlighting.
50ff73b
" For version 5.7 and earlier: only when not done already
50ff73b
" For version 5.8 and later: only when an item doesn't have highlighting yet
50ff73b
if version >= 508 || !exists("did_spec_syntax_inits")
50ff73b
  if version < 508
50ff73b
    let did_spec_syntax_inits = 1
50ff73b
    command -nargs=+ HiLink hi link <args>
50ff73b
  else
50ff73b
    command -nargs=+ HiLink hi def link <args>
50ff73b
  endif
50ff73b
50ff73b
  "main types color definitions
50ff73b
  HiLink specSection			Structure
50ff73b
  HiLink specSectionMacro		Macro
50ff73b
  HiLink specWWWlink			PreProc
50ff73b
  HiLink specOpts			Operator
50ff73b
50ff73b
  "yes, it's ugly, but white is sooo cool
50ff73b
  if &background == "dark"
50ff73b
    hi def specGlobalMacro		ctermfg=white
50ff73b
  else
50ff73b
    HiLink specGlobalMacro		Identifier
50ff73b
  endif
50ff73b
50ff73b
  "sh colors
50ff73b
  HiLink shComment			Comment
50ff73b
  HiLink shIf				Statement
50ff73b
  HiLink shOperator			Special
50ff73b
  HiLink shQuote1			String
50ff73b
  HiLink shQuote2			String
50ff73b
  HiLink shQuoteDelim			Statement
50ff73b
50ff73b
  "spec colors
50ff73b
  HiLink specBlock			Function
50ff73b
  HiLink specColon			Special
50ff73b
  HiLink specCommand			Statement
50ff73b
  HiLink specCommandOpts		specOpts
50ff73b
  HiLink specCommandSpecial		Special
50ff73b
  HiLink specComment			Comment
50ff73b
  HiLink specConfigure			specCommand
50ff73b
  HiLink specDate			String
50ff73b
  HiLink specDescriptionOpts		specOpts
50ff73b
  HiLink specEmail			specWWWlink
50ff73b
  HiLink specError			Error
50ff73b
  HiLink specFilesDirective		specSectionMacro
50ff73b
  HiLink specFilesOpts			specOpts
50ff73b
  HiLink specLicense			String
50ff73b
  HiLink specMacroNameLocal		specGlobalMacro
50ff73b
  HiLink specMacroNameOther		specGlobalMacro
50ff73b
  HiLink specManpageFile		NONE
50ff73b
  HiLink specMonth			specDate
50ff73b
  HiLink specNoNumberHilite		NONE
50ff73b
  HiLink specNumber			Number
50ff73b
  HiLink specPackageOpts		specOpts
50ff73b
  HiLink specPercent			Special
50ff73b
  HiLink specSpecialChar		Special
50ff73b
  HiLink specSpecialVariables		specGlobalMacro
50ff73b
  HiLink specSpecialVariablesNames	specGlobalMacro
50ff73b
  HiLink specTarCommand			specCommand
50ff73b
  HiLink specURL			specWWWlink
50ff73b
  HiLink specURLMacro			specWWWlink
50ff73b
  HiLink specVariables			Identifier
50ff73b
  HiLink specWeekday			specDate
50ff73b
  HiLink specListedFilesBin		Statement
50ff73b
  HiLink specListedFilesDoc		Statement
50ff73b
  HiLink specListedFilesEtc		Statement
50ff73b
  HiLink specListedFilesLib		Statement
50ff73b
  HiLink specListedFilesPrefix		Statement
50ff73b
  HiLink specListedFilesShare		Statement
50ff73b
50ff73b
  delcommand HiLink
50ff73b
endif
50ff73b
50ff73b
let b:current_syntax = "spec"
50ff73b
50ff73b
" vim: ts=8