From c7ec85754a53230945bd2ea57519f4fd7f12479c Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 10 Dec 2015 17:30:23 +0100 Subject: Pygments highlighting rules for Solidity. --- docs/conf.py | 8 +++-- docs/utils/SolidityLexer.py | 85 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 docs/utils/SolidityLexer.py diff --git a/docs/conf.py b/docs/conf.py index 7f5d4514..48664344 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,7 +19,11 @@ import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) + +def setup(sphinx): + sys.path.insert(0, os.path.abspath('./utils')) + from SolidityLexer import SolidityLexer + sphinx.add_lexer('Solidity', SolidityLexer()) # -- General configuration ------------------------------------------------ @@ -88,7 +92,7 @@ exclude_patterns = ['_build'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' -highlight_language = 'javascript' +highlight_language = 'Solidity' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] diff --git a/docs/utils/SolidityLexer.py b/docs/utils/SolidityLexer.py new file mode 100644 index 00000000..d05c7b0c --- /dev/null +++ b/docs/utils/SolidityLexer.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- + +import re +import copy + +from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ + include, this +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Other, Punctuation, Literal + +__all__ = ['SolidityLexer'] + +class SolidityLexer(RegexLexer): + name = "Solidity" + aliases = ['sol', 'solidity'] + filenames = ['*.sol'] + mimetypes = [] + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'