|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.sieve |
|
4 ~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for Sieve file format. |
|
7 |
|
8 https://tools.ietf.org/html/rfc5228 |
|
9 https://tools.ietf.org/html/rfc5173 |
|
10 https://tools.ietf.org/html/rfc5229 |
|
11 https://tools.ietf.org/html/rfc5230 |
|
12 https://tools.ietf.org/html/rfc5232 |
|
13 https://tools.ietf.org/html/rfc5235 |
|
14 https://tools.ietf.org/html/rfc5429 |
|
15 https://tools.ietf.org/html/rfc8580 |
|
16 |
|
17 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
|
18 :license: BSD, see LICENSE for details. |
|
19 """ |
|
20 |
|
21 from pygments.lexer import RegexLexer, bygroups |
|
22 from pygments.token import Comment, Name, Literal, String, Text, Punctuation, Keyword |
|
23 |
|
24 __all__ = ["SieveLexer"] |
|
25 |
|
26 |
|
27 class SieveLexer(RegexLexer): |
|
28 """ |
|
29 Lexer for sieve format. |
|
30 """ |
|
31 name = 'Sieve' |
|
32 filenames = ['*.siv', '*.sieve'] |
|
33 aliases = ['sieve'] |
|
34 |
|
35 tokens = { |
|
36 'root': [ |
|
37 (r'\s+', Text), |
|
38 (r'[();,{}\[\]]', Punctuation), |
|
39 # import: |
|
40 (r'(?i)require', |
|
41 Keyword.Namespace), |
|
42 # tags: |
|
43 (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)', |
|
44 bygroups(Name.Tag, Name.Tag)), |
|
45 # tokens: |
|
46 (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)', |
|
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 } |