summaryrefslogtreecommitdiff
path: root/pygments/lexers/rnc.py
diff options
context:
space:
mode:
authorMike Elson <mike.elson@gmail.com>2016-04-19 23:05:08 +0200
committerMike Elson <mike.elson@gmail.com>2016-04-19 23:05:08 +0200
commit23cad0ac92561664e4425d6887f51cb712fe4de5 (patch)
treee14d021c096b8e6c742014db3c64962610c10be8 /pygments/lexers/rnc.py
parentef6cb21358bf39090ddbc047c2b76adee0ac939a (diff)
downloadpygments-23cad0ac92561664e4425d6887f51cb712fe4de5.tar.gz
Added RNC lexer and sample file
Diffstat (limited to 'pygments/lexers/rnc.py')
-rw-r--r--pygments/lexers/rnc.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/pygments/lexers/rnc.py b/pygments/lexers/rnc.py
new file mode 100644
index 00000000..810b24f6
--- /dev/null
+++ b/pygments/lexers/rnc.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.rnc
+ ~~~~~~~~~~~~~~~~~~~
+
+ Lexer for Relax-NG Compact syntax
+
+ :copyright: Copyright 2016 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.
+ """
+
+ name = 'Relax-NG Compact'
+ aliases = ['rnc', 'rng-compact']
+ filenames = ['*.rnc']
+
+ tokens = {
+ 'root': [
+ (r'namespace', Keyword.Namespace),
+ (r'(default|datatypes)', Keyword.Declaration),
+ (r'##.*$', Comment.Preproc),
+ (r'#.*$', Comment.Single),
+ (r'"[^"]*"', String.Double),
+ (r'(element|attribute|mixed)', Keyword.Declaration, 'variable'),
+ (r'(text|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),
+ ]
+ }