srcinfo.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. pygments.lexers.srcinfo
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for .SRCINFO files used by Arch Linux Packages.
  5. The description of the format can be found in the wiki:
  6. https://wiki.archlinux.org/title/.SRCINFO
  7. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
  8. :license: BSD, see LICENSE for details.
  9. """
  10. from pygments.lexer import RegexLexer, words
  11. from pygments.token import Text, Comment, Keyword, Name, Operator, Whitespace
  12. __all__ = ['SrcinfoLexer']
  13. keywords = (
  14. 'pkgbase', 'pkgname',
  15. 'pkgver', 'pkgrel', 'epoch',
  16. 'pkgdesc', 'url', 'install', 'changelog',
  17. 'arch', 'groups', 'license', 'noextract', 'options', 'backup',
  18. 'validpgpkeys',
  19. )
  20. architecture_dependent_keywords = (
  21. 'source', 'depends', 'checkdepends', 'makedepends', 'optdepends',
  22. 'provides', 'conflicts', 'replaces',
  23. 'md5sums', 'sha1sums', 'sha224sums', 'sha256sums', 'sha384sums',
  24. 'sha512sums',
  25. )
  26. class SrcinfoLexer(RegexLexer):
  27. """Lexer for .SRCINFO files used by Arch Linux Packages.
  28. .. versionadded:: 2.11
  29. """
  30. name = 'Srcinfo'
  31. aliases = ['srcinfo']
  32. filenames = ['.SRCINFO']
  33. tokens = {
  34. 'root': [
  35. (r'\s+', Whitespace),
  36. (r'#.*', Comment.Single),
  37. (words(keywords), Keyword, 'assignment'),
  38. (words(architecture_dependent_keywords, suffix=r'_\w+'),
  39. Keyword, 'assignment'),
  40. (r'\w+', Name.Variable, 'assignment'),
  41. ],
  42. 'assignment': [
  43. (r' +', Whitespace),
  44. (r'=', Operator, 'value'),
  45. ],
  46. 'value': [
  47. (r' +', Whitespace),
  48. (r'.*', Text, '#pop:2'),
  49. ],
  50. }