sieve.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.sieve
  4. ~~~~~~~~~~~~~~~~~~~~~
  5. Lexer for Sieve file format.
  6. https://tools.ietf.org/html/rfc5228
  7. https://tools.ietf.org/html/rfc5173
  8. https://tools.ietf.org/html/rfc5229
  9. https://tools.ietf.org/html/rfc5230
  10. https://tools.ietf.org/html/rfc5232
  11. https://tools.ietf.org/html/rfc5235
  12. https://tools.ietf.org/html/rfc5429
  13. https://tools.ietf.org/html/rfc8580
  14. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  15. :license: BSD, see LICENSE for details.
  16. """
  17. from pygments.lexer import RegexLexer, bygroups
  18. from pygments.token import Comment, Name, Literal, String, Text, Punctuation, 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. tokens = {
  28. 'root': [
  29. (r'\s+', Text),
  30. (r'[();,{}\[\]]', Punctuation),
  31. # import:
  32. (r'(?i)require',
  33. Keyword.Namespace),
  34. # tags:
  35. (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)',
  36. bygroups(Name.Tag, Name.Tag)),
  37. # tokens:
  38. (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)',
  39. Name.Builtin),
  40. (r'(?i)set',
  41. Keyword.Declaration),
  42. # number:
  43. (r'([0-9.]+)([kmgKMG])?',
  44. bygroups(Literal.Number, Literal.Number)),
  45. # comment:
  46. (r'#.*$',
  47. Comment.Single),
  48. (r'/\*.*\*/',
  49. Comment.Multiline),
  50. # string:
  51. (r'"[^"]*?"',
  52. String),
  53. # text block:
  54. (r'text:',
  55. Name.Tag, 'text'),
  56. ],
  57. 'text': [
  58. (r'[^.].*?\n', String),
  59. (r'^\.', Punctuation, "#pop"),
  60. ]
  61. }