Commits

Kirill Simonov committed fc56287

Added HTSQL lexer for pygments to `htsqldoc` sphinx extension.

  • Participants
  • Parent commits 39acc55

Comments (0)

Files changed (1)

File src/sphinxext_htsqldoc/__init__.py

 from docutils import nodes
 from docutils.parsers.rst import Directive, directives
 from sphinx.util.osutil import copyfile
+from pygments.lexer import RegexLexer
+from pygments.token import Punctuation, Text, Operator, Name, String, Number
 
 import os, os.path
 from urllib2 import quote, urlopen, Request, HTTPError, URLError
 from json import loads
 
 
+class HtsqlLexer(RegexLexer):
+
+    name = 'HTSQL'
+    aliases = ['htsql']
+    filenames = ['*.htsql']
+    mimetypes = ['text/x-htsql', 'application/x-htsql']
+
+    tokens = {
+        'root': [
+            (r'\s+', Text),
+            (r'(?<=:)(?!\d)\w+', Name.Function),
+            (r'(?!\d)\w+(?=\s*\()', Name.Function),
+            (r'(?!\d)\w+', Name.Builtin),
+            (r'(?:\d*\.)?\d+[eE][+-]?\d+|\d*\.\d+|\d+\.?', Number),
+            (r'\'(?:[^\']|\'\')*\'', String),
+            (r'=~~|=~|\^~~|\^~|\$~~|\$~|~~|~|'
+             r'!=~~|!=~|!\^~~|!\^~|!\$~~|!\$~|!~~|!~|'
+             r'<=|<|>=|>|==|=|!==|!=|!|'
+             r'&|\||->|\?|\^|/|\*|\+|-', Operator),
+            (r'\.|,|\(|\)|\{|\}|\[|\]|:|\$', Punctuation),
+        ]
+    }
+
+
 class HTSQLServerDirective(Directive):
     required_arguments = 1
     has_content = False
                  html=(visit_htsql_block, depart_htsql_block))
     app.add_stylesheet('htsqldoc.css')
     app.add_javascript('htsqldoc.js')
+    app.add_lexer('htsql', HtsqlLexer())