aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py3/pygments/lexers/sieve.py
blob: 19d9d549dc0aec933dfc5ad0361e1e1b3fbde399 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
    pygments.lexers.sieve
    ~~~~~~~~~~~~~~~~~~~~~

    Lexer for Sieve file format.

    https://tools.ietf.org/html/rfc5228
    https://tools.ietf.org/html/rfc5173
    https://tools.ietf.org/html/rfc5229
    https://tools.ietf.org/html/rfc5230
    https://tools.ietf.org/html/rfc5232
    https://tools.ietf.org/html/rfc5235
    https://tools.ietf.org/html/rfc5429
    https://tools.ietf.org/html/rfc8580

    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

from pygments.lexer import RegexLexer, bygroups
from pygments.token import Comment, Name, Literal, String, Text, Punctuation, \
    Keyword

__all__ = ["SieveLexer"]


class SieveLexer(RegexLexer):
    """
    Lexer for sieve format.
    """
    name = 'Sieve'
    filenames = ['*.siv', '*.sieve']
    aliases = ['sieve']
    url = 'https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)'
    version_added = '2.6'

    tokens = {
        'root': [
            (r'\s+', Text),
            (r'[();,{}\[\]]', Punctuation),
            # import:
            (r'(?i)require',
             Keyword.Namespace),
            # tags:
            (r'(?i)(:)(addresses|all|contains|content|create|copy|comparator|'
             r'count|days|detail|domain|fcc|flags|from|handle|importance|is|'
             r'localpart|length|lowerfirst|lower|matches|message|mime|options|'
             r'over|percent|quotewildcard|raw|regex|specialuse|subject|text|'
             r'under|upperfirst|upper|value)',
             bygroups(Name.Tag, Name.Tag)),
            # tokens:
            (r'(?i)(address|addflag|allof|anyof|body|discard|elsif|else|envelope|'
             r'ereject|exists|false|fileinto|if|hasflag|header|keep|'
             r'notify_method_capability|notify|not|redirect|reject|removeflag|'
             r'setflag|size|spamtest|stop|string|true|vacation|virustest)',
             Name.Builtin),
            (r'(?i)set',
             Keyword.Declaration),
            # number:
            (r'([0-9.]+)([kmgKMG])?',
             bygroups(Literal.Number, Literal.Number)),
            # comment:
            (r'#.*$',
             Comment.Single),
            (r'/\*.*\*/',
             Comment.Multiline),
            # string:
            (r'"[^"]*?"',
             String),
            # text block:
            (r'text:',
             Name.Tag, 'text'),
        ],
        'text': [
            (r'[^.].*?\n', String),
            (r'^\.', Punctuation, "#pop"),
        ]
    }