aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py2/pygments/lexers/rnc.py
blob: 03c6ea7b2aa03ae0b49e52f6c1a065b90fa9f2de (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
# -*- coding: utf-8 -*- 
""" 
    pygments.lexers.rnc 
    ~~~~~~~~~~~~~~~~~~~ 
 
    Lexer for Relax-NG Compact syntax 
 
    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. 
    :license: BSD, see LICENSE for details. 
""" 
 
from pygments.lexer import RegexLexer 
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 
    Punctuation 
 
__all__ = ['RNCCompactLexer'] 
 
 
class RNCCompactLexer(RegexLexer): 
    """ 
    For `RelaxNG-compact <http://relaxng.org>`_ syntax. 
 
    .. versionadded:: 2.2 
    """ 
 
    name = 'Relax-NG Compact' 
    aliases = ['rnc', 'rng-compact'] 
    filenames = ['*.rnc'] 
 
    tokens = { 
        'root': [ 
            (r'namespace\b', Keyword.Namespace), 
            (r'(?:default|datatypes)\b', Keyword.Declaration), 
            (r'##.*$', Comment.Preproc), 
            (r'#.*$', Comment.Single), 
            (r'"[^"]*"', String.Double), 
            # TODO single quoted strings and escape sequences outside of 
            # double-quoted strings 
            (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'), 
            (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'), 
            (r'[,?&*=|~]|>>', Operator), 
            (r'[(){}]', Punctuation), 
            (r'.', Text), 
        ], 
 
        # a variable has been declared using `element` or `attribute` 
        'variable': [ 
            (r'[^{]+', Name.Variable), 
            (r'\{', Punctuation, '#pop'), 
        ], 
 
        # after an xsd:<datatype> declaration there may be attributes 
        'maybe_xsdattributes': [ 
            (r'\{', Punctuation, 'xsdattributes'), 
            (r'\}', Punctuation, '#pop'), 
            (r'.', Text), 
        ], 
 
        # attributes take the form { key1 = value1 key2 = value2 ... } 
        'xsdattributes': [ 
            (r'[^ =}]', Name.Attribute), 
            (r'=', Operator), 
            (r'"[^"]*"', String.Double), 
            (r'\}', Punctuation, '#pop'), 
            (r'.', Text), 
        ], 
    }