Skip to content

Commit

Permalink
TOPAS syntax highlighting for included parameter files and snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchall committed Jul 21, 2016
1 parent 257c8f0 commit 8d1e884
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.build
__pycache__
5 changes: 5 additions & 0 deletions .templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{# layout.html #}
{# Import the theme's layout. #}
{% extends "!layout.html" %}

{% set css_files = css_files + ['_static/pygments.css'] %}
13 changes: 12 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@
#show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = 'emacs'

# The default language used to highlight source code
highlight_language = 'topas'

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
Expand Down Expand Up @@ -362,3 +365,11 @@

# If false, no index is generated.
#epub_use_index = True

def setup(sphinx):
sys.path.insert(0, os.path.abspath('./util'))
from topas_lexer import TopasLexer
sphinx.add_lexer("topas", TopasLexer())

from pygments.styles import STYLE_MAP
print(sorted(STYLE_MAP.keys()))
30 changes: 30 additions & 0 deletions util/topas_lexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *

__all__ = ['TopasLexer']


class TopasLexer(RegexLexer):

name = 'TOPAS'
aliases = ['topas']
filenames = ['*.txt']

tokens = {
'root': [
(r'#.*$', Comment),
(r'(?i)(includefile|inheritedvalue)', Keyword.Namespace),
(r'^([bidus]v?)(:)', bygroups(Keyword.Type, Text)),
(r'(?i)(ma|el|is|ge|gr|ph|so|sc|tf|ts|vr)([/\w]*/)([\w]+)',
bygroups(Name.Class, Name.Class, Name.Variable)),
(r'"(?i)(true|false|t|f|1|0)"', Keyword.Constant),
(r'"', String, 'string'),
(r'(?<!\w)[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?', Number),
(r'[=+*-]', Operator),
(r'.', Text),
],
'string': [
('[^"]+', String),
('"', String, '#pop'),
]
}

0 comments on commit 8d1e884

Please sign in to comment.