sieve.py 2.2 KB

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