1from pygments.lexer import RegexLexer
2from pygments.token import *
3
4"""
5 pygments.lexers.rnc
6 ~~~~~~~~~~~~~~~~~~~
7
8 Lexer for Relax-NG Compact syntax
9
10 :copyright: Copyright 2011 by the Pygments team, see AUTHORS.
11 :license: BSD, see LICENSE for details.
12"""
13
14import re
15import copy
16
17from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
18 include, this
19from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
20 Number, Other, Punctuation, Literal
21from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
22 html_doctype_matches
23from pygments.lexers.agile import RubyLexer
24from pygments.lexers.compiled import ScalaLexer
25
26
27__all__ = ['RNCCompactLexer']
28
29class RNCCompactLexer(RegexLexer):
30 name = 'Relax-NG Compact'
31 aliases = ['rnc', 'rng-compact']
32 filenames = ['*.rnc']
33
34 tokens = {
35 'root': [
36 (r'namespace', Keyword.Namespace),
37 (r'(default|datatypes)', Keyword.Declaration),
38 (r'##.*$', Comment.Preproc),
39 (r'#.*$', Comment.Single),
40 (r'"[^"]*"', String.Double),
41 (r'(element|attribute)', Keyword.Declaration, 'variable'),
42 (r'(text|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'),
43 (r'[,?&*=|]', Operator),
44 (r'[(){}]', Punctuation),
45 (r'.', Text),
46 ],
47
48 # a variable has been declared using `element` or `attribute`
49 'variable': [
50 (r'[^{]+', Name.Variable),
51 (r'\{', Punctuation, '#pop'),
52 ],
53
54 # after an xsd:<datatype> declaration there may be attributes
55 'maybe_xsdattributes': [
56 (r'\{', Punctuation, 'xsdattributes'),
57 (r'\}', Punctuation, '#pop'),
58 (r'.', Text),
59 ],
60
61 # attributes take the form { key1 = value1 key2 = value2 ... }
62 'xsdattributes': [
63 (r'[^ =}]', Name.Attribute),
64 (r'=', Operator),
65 (r'"[^"]*"', String.Double),
66 (r'\}', Punctuation, '#pop'),
67 (r'.', Text),
68 ]
69 }