|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.rnc |
|
4 ~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for Relax-NG Compact syntax |
|
7 |
|
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 from pygments.lexer import RegexLexer |
|
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
14 Punctuation |
|
15 |
|
16 __all__ = ['RNCCompactLexer'] |
|
17 |
|
18 |
|
19 class RNCCompactLexer(RegexLexer): |
|
20 """ |
|
21 For `RelaxNG-compact <http://relaxng.org>`_ syntax. |
|
22 |
|
23 .. versionadded:: 2.2 |
|
24 """ |
|
25 |
|
26 name = 'Relax-NG Compact' |
|
27 aliases = ['rnc', 'rng-compact'] |
|
28 filenames = ['*.rnc'] |
|
29 |
|
30 tokens = { |
|
31 'root': [ |
|
32 (r'namespace\b', Keyword.Namespace), |
|
33 (r'(?:default|datatypes)\b', Keyword.Declaration), |
|
34 (r'##.*$', Comment.Preproc), |
|
35 (r'#.*$', Comment.Single), |
|
36 (r'"[^"]*"', String.Double), |
|
37 # TODO single quoted strings and escape sequences outside of |
|
38 # double-quoted strings |
|
39 (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'), |
|
40 (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'), |
|
41 (r'[,?&*=|~]|>>', Operator), |
|
42 (r'[(){}]', Punctuation), |
|
43 (r'.', Text), |
|
44 ], |
|
45 |
|
46 # a variable has been declared using `element` or `attribute` |
|
47 'variable': [ |
|
48 (r'[^{]+', Name.Variable), |
|
49 (r'\{', Punctuation, '#pop'), |
|
50 ], |
|
51 |
|
52 # after an xsd:<datatype> declaration there may be attributes |
|
53 'maybe_xsdattributes': [ |
|
54 (r'\{', Punctuation, 'xsdattributes'), |
|
55 (r'\}', Punctuation, '#pop'), |
|
56 (r'.', Text), |
|
57 ], |
|
58 |
|
59 # attributes take the form { key1 = value1 key2 = value2 ... } |
|
60 'xsdattributes': [ |
|
61 (r'[^ =}]', Name.Attribute), |
|
62 (r'=', Operator), |
|
63 (r'"[^"]*"', String.Double), |
|
64 (r'\}', Punctuation, '#pop'), |
|
65 (r'.', Text), |
|
66 ], |
|
67 } |