diff --git a/_exts/phpcr/sphinx/cnd.py b/_exts/phpcr/sphinx/cnd.py new file mode 100644 index 0000000..dc04166 --- /dev/null +++ b/_exts/phpcr/sphinx/cnd.py @@ -0,0 +1,4 @@ +from phpcr.sphinx.lexer_cnd import CndLexer + +def setup(app): + app.add_lexer('cnd', CndLexer()) diff --git a/_exts/phpcr/sphinx/lexer_cnd.py b/_exts/phpcr/sphinx/lexer_cnd.py new file mode 100644 index 0000000..1cd1632 --- /dev/null +++ b/_exts/phpcr/sphinx/lexer_cnd.py @@ -0,0 +1,40 @@ +from pygments.lexer import RegexLexer +from pygments.token import * +import re + +class CndLexer(RegexLexer): + """ + For JCR Compact Namespace and Node Type Definition files. + """ + + name = 'Cnd' + aliases = ['cnd'] + filenames = ['*.cnd'] + + tokens = { + 'root': [ + (r'^<.*?>', Name.Namespace), + (r'^//.*$', Comment), + (r'/\*\*/', Comment.Multiline), + (r'/\*.*?\*/', Comment.Multiline), + (r'\[.*?\]', Name.Entity, 'nodetype'), + (r'\((string|binary|long|double|date|boolean|name|path|reference|weakreference|uri|decimal)\)', Name.Label), + (r'(\[|\(|\)|\])', Name.Tag), + (r'^\+', Keyword.Declaration), + (r'^\-', Keyword.Declaration), + (r'(mandatory|autocreated|protected|version|primary)', Keyword), + (r'(mixin|orderable)', Keyword), + (r'(mandatory|autocreated|protected|multiple|version|primary)', Keyword), + (r'(>|=|<|\*)', Operator), + (r'\'.*?\'', String.Single), + (r',', Punctuation), + (r'\s+', Text), + (r'[\w:]', Text), + ], + 'nodetype': [ + (r'>', Name.Punctuation), + (r'[\w:]', Name.Class), + (r',', Punctuation), + (r' ', Text), + ] + } diff --git a/conf.py b/conf.py index 3c386f6..061df32 100644 --- a/conf.py +++ b/conf.py @@ -23,9 +23,13 @@ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' + +# Add ourxextension directory to the system paths +sys.path.append(os.path.abspath('_exts')) + # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = [] +extensions = ['phpcr.sphinx.cnd'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']