Skip to content

CND Highlighting extension #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _exts/phpcr/sphinx/cnd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from phpcr.sphinx.lexer_cnd import CndLexer

def setup(app):
app.add_lexer('cnd', CndLexer())
40 changes: 40 additions & 0 deletions _exts/phpcr/sphinx/lexer_cnd.py
Original file line number Diff line number Diff line change
@@ -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 = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can easily (well, patiently) extend this so that it is aware of the node type grammer and then it can act as a validator too..

'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),
]
}
6 changes: 5 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down