sieve.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. pygments.lexers.sieve
  3. ~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for Sieve file format.
  5. https://tools.ietf.org/html/rfc5228
  6. https://tools.ietf.org/html/rfc5173
  7. https://tools.ietf.org/html/rfc5229
  8. https://tools.ietf.org/html/rfc5230
  9. https://tools.ietf.org/html/rfc5232
  10. https://tools.ietf.org/html/rfc5235
  11. https://tools.ietf.org/html/rfc5429
  12. https://tools.ietf.org/html/rfc8580
  13. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  14. :license: BSD, see LICENSE for details.
  15. """
  16. from pygments.lexer import RegexLexer, bygroups
  17. from pygments.token import Comment, Name, Literal, String, Text, Punctuation, \
  18. Keyword
  19. __all__ = ["SieveLexer"]
  20. class SieveLexer(RegexLexer):
  21. """
  22. Lexer for sieve format.
  23. """
  24. name = 'Sieve'
  25. filenames = ['*.siv', '*.sieve']
  26. aliases = ['sieve']
  27. url = 'https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)'
  28. version_added = '2.6'
  29. tokens = {
  30. 'root': [
  31. (r'\s+', Text),
  32. (r'[();,{}\[\]]', Punctuation),
  33. # import:
  34. (r'(?i)require',
  35. Keyword.Namespace),
  36. # tags:
  37. (r'(?i)(:)(addresses|all|contains|content|create|copy|comparator|'
  38. r'count|days|detail|domain|fcc|flags|from|handle|importance|is|'
  39. r'localpart|length|lowerfirst|lower|matches|message|mime|options|'
  40. r'over|percent|quotewildcard|raw|regex|specialuse|subject|text|'
  41. r'under|upperfirst|upper|value)',
  42. bygroups(Name.Tag, Name.Tag)),
  43. # tokens:
  44. (r'(?i)(address|addflag|allof|anyof|body|discard|elsif|else|envelope|'
  45. r'ereject|exists|false|fileinto|if|hasflag|header|keep|'
  46. r'notify_method_capability|notify|not|redirect|reject|removeflag|'
  47. r'setflag|size|spamtest|stop|string|true|vacation|virustest)',
  48. Name.Builtin),
  49. (r'(?i)set',
  50. Keyword.Declaration),
  51. # number:
  52. (r'([0-9.]+)([kmgKMG])?',
  53. bygroups(Literal.Number, Literal.Number)),
  54. # comment:
  55. (r'#.*$',
  56. Comment.Single),
  57. (r'/\*.*\*/',
  58. Comment.Multiline),
  59. # string:
  60. (r'"[^"]*?"',
  61. String),
  62. # text block:
  63. (r'text:',
  64. Name.Tag, 'text'),
  65. ],
  66. 'text': [
  67. (r'[^.].*?\n', String),
  68. (r'^\.', Punctuation, "#pop"),
  69. ]
  70. }