~sircmpwn/names.sr.ht

ref: 4befa4e5942b52045dc9ef9bcd3473389db71d61 names.sr.ht/names/pygments.py -rw-r--r-- 1.3 KiB
4befa4e5Drew DeVault Add tables for remaining TLDs with special reqs 2 years ago
                                                                                
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
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import *

class ZoneLexer(RegexLexer):
    name = 'Zone'
    aliases = ['zone']
    filenames = ['*.zone']

    tokens = {
        'root': [
            (r';.*\n', Comment.Single),
            (r'(\$[A-Za-z]+ )(.*\n)',
                bygroups(Comment.PreProc, Name.String)),
            (r'''(?x)
                ([A-Za-z@_][A-Za-z0-9_.-]*[\t ]+|[\t ]+)
                (IN[\t ]+)
                ((AAAA|A|NS|MX|CNAME|SOA|PTR|TXT)[\t ]+)''',
                bygroups(Name.Entity, Keyword.Reserved, Keyword.Type),
                'simple'),
            (r'.*\n', Text),
        ],
        'value': [
            (r'\(', Text, 'parenthesized'),
            (r'\d.\d.\d.\d[\t ]*', Literal.Number),
            (r'([\dA-Fa-f]+(:|::))([\dA-Fa-f]+(:|::)?]*)[\t ]*', Literal.Number),
            (r'[a-zA-Z][a-zA-Z0-9_.-]+[\t ]*', Name.Entity),
            (r'"[^\n]*"', Literal.String),
            (r'\d+(d|w|h|y)', Literal.Date),
            (r'\d+', Literal.Number),
            (r'.', Text),
        ],
        'simple': [
            (r'\n', Text, '#pop'),
            include('value'),
        ],
        'parenthesized': [
            (r'\)', Text, '#pop'),
            (r'\n', Text),
            include('value'),
        ],
    }