sieve.py 2.4 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-2023 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. .. versionadded:: 2.6
  24. """
  25. name = 'Sieve'
  26. filenames = ['*.siv', '*.sieve']
  27. aliases = ['sieve']
  28. tokens = {
  29. 'root': [
  30. (r'\s+', Text),
  31. (r'[();,{}\[\]]', Punctuation),
  32. # import:
  33. (r'(?i)require',
  34. Keyword.Namespace),
  35. # tags:
  36. (r'(?i)(:)(addresses|all|contains|content|create|copy|comparator|'
  37. r'count|days|detail|domain|fcc|flags|from|handle|importance|is|'
  38. r'localpart|length|lowerfirst|lower|matches|message|mime|options|'
  39. r'over|percent|quotewildcard|raw|regex|specialuse|subject|text|'
  40. r'under|upperfirst|upper|value)',
  41. bygroups(Name.Tag, Name.Tag)),
  42. # tokens:
  43. (r'(?i)(address|addflag|allof|anyof|body|discard|elsif|else|envelope|'
  44. r'ereject|exists|false|fileinto|if|hasflag|header|keep|'
  45. r'notify_method_capability|notify|not|redirect|reject|removeflag|'
  46. r'setflag|size|spamtest|stop|string|true|vacation|virustest)',
  47. Name.Builtin),
  48. (r'(?i)set',
  49. Keyword.Declaration),
  50. # number:
  51. (r'([0-9.]+)([kmgKMG])?',
  52. bygroups(Literal.Number, Literal.Number)),
  53. # comment:
  54. (r'#.*$',
  55. Comment.Single),
  56. (r'/\*.*\*/',
  57. Comment.Multiline),
  58. # string:
  59. (r'"[^"]*?"',
  60. String),
  61. # text block:
  62. (r'text:',
  63. Name.Tag, 'text'),
  64. ],
  65. 'text': [
  66. (r'[^.].*?\n', String),
  67. (r'^\.', Punctuation, "#pop"),
  68. ]
  69. }