From 3478c462fa67cabcf9d3577361d7031d13fb8c4a Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 2 Aug 2022 18:35:11 +0200 Subject: [PATCH] docs: Custom pygments cpp lexer no longer needed --- docs/conf.py | 481 +-------------------------------------------------- 1 file changed, 2 insertions(+), 479 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 54aa719b..75d699cd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,488 +1,11 @@ -# -*- coding: utf-8 -*- -""" - pygments.lexers.c_cpp - ~~~~~~~~~~~~~~~~~~~~~ - - Lexers for C/C++ languages. - - :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import os -import re -import subprocess - -from pygments.lexer import ( - RegexLexer, - bygroups, - default, - include, - inherit, - this, - using, - words, -) -from pygments.token import ( - Comment, - Error, - Keyword, - Name, - Number, - Operator, - Punctuation, - String, - Text, -) -from pygments.util import get_bool_opt -from sphinx.highlighting import lexers - - -class MyCFamilyLexer(RegexLexer): - #: optional Comment or Whitespace - _ws = r"(?:\s|//.*?\n|/[*].*?[*]/)+" - - # The trailing ?, rather than *, avoids a geometric performance drop here. - #: only one /* */ style comment - _ws1 = r"\s*(?:/[*].*?[*]/\s*)?" - - tokens = { - "whitespace": [ - # preprocessor directives: without whitespace - (r"^#if\s+0", Comment.Preproc, "if0"), - ("^#", Comment.Preproc, "macro"), - # or with whitespace - ( - "^(" + _ws1 + r")(#if\s+0)", - bygroups(using(this), Comment.Preproc), - "if0", - ), - ("^(" + _ws1 + ")(#)", bygroups(using(this), Comment.Preproc), "macro"), - (r"\n", Text), - (r"\s+", Text), - (r"\\\n", Text), # line continuation - (r"//(\n|[\w\W]*?[^\\]\n)", Comment.Single), - (r"/(\\\n)?[*][\w\W]*?[*](\\\n)?/", Comment.Multiline), - # Open until EOF, so no ending delimeter - (r"/(\\\n)?[*][\w\W]*", Comment.Multiline), - ], - "statements": [ - (r'(L?)(")', bygroups(String.Affix, String), "string"), - ( - r"(L?)(')(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])(')", - bygroups(String.Affix, String.Char, String.Char, String.Char), - ), - (r"\*/", Error), - (r"[~!%^&*+=|?:<>/-]", Operator), - (r"[()\[\],.]", Punctuation), - ( - words( - ( - "asm", - "auto", - "break", - "case", - "const", - "continue", - "default", - "do", - "else", - "enum", - "extern", - "for", - "goto", - "if", - "register", - "restricted", - "return", - "sizeof", - "static", - "struct", - "switch", - "typedef", - "union", - "volatile", - "while", - ), - suffix=r"\b", - ), - Keyword, - ), - ( - r"(bool|int|long|float|short|double|char|unsigned|signed|void)\b", - Keyword.Type, - ), - ( - words( - ( - "inline", - "_inline", - "__inline", - "naked", - "restrict", - "thread", - "typename", - ), - suffix=r"\b", - ), - Keyword.Reserved, - ), - # Vector intrinsics - (r"(__m(128i|128d|128|64))\b", Keyword.Reserved), - # Microsoft-isms - ( - words( - ( - "asm", - "int8", - "based", - "except", - "int16", - "stdcall", - "cdecl", - "fastcall", - "int32", - "declspec", - "finally", - "int64", - "try", - "leave", - "wchar_t", - "w64", - "unaligned", - "raise", - "noop", - "identifier", - "forceinline", - "assume", - ), - prefix=r"__", - suffix=r"\b", - ), - Keyword.Reserved, - ), - (r"(true|false|NULL)\b", Name.Builtin), - (r"([a-zA-Z_]\w*)(\s*)(:)(?!:)", bygroups(Name.Label, Text, Punctuation)), - (r"[a-zA-Z_]\w*", Name), - ], - "root": [ - include("whitespace"), - # functions - ( - r"((?:[\w*\s])+?(?:\s|[*]))" # return arguments - r"([a-zA-Z_]\w*)" # method name - r"(\s*\([^;]*?\))" # signature - r"([^;{]*)(\{)", - bygroups( - using(this), Name.Function, using(this), using(this), Punctuation - ), - "function", - ), - # function declarations - ( - r"((?:[\w*\s])+?(?:\s|[*]))" # return arguments - r"([a-zA-Z_]\w*)" # method name - r"(\s*\([^;]*?\))" # signature - r"([^;]*)(;)", - bygroups( - using(this), Name.Function, using(this), using(this), Punctuation - ), - ), - default("statement"), - ], - "statement": [ - include("whitespace"), - include("statements"), - ("[{}]", Punctuation), - (";", Punctuation, "#pop"), - ], - "function": [ - include("whitespace"), - include("statements"), - (";", Punctuation), - (r"\{", Punctuation, "#push"), - (r"\}", Punctuation, "#pop"), - ], - "string": [ - (r'"', String, "#pop"), - ( - r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' - r"u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})", - String.Escape, - ), - (r'[^\\"\n]+', String), # all other characters - (r"\\\n", String), # line continuation - (r"\\", String), # stray backslash - ], - "macro": [ - ( - r"(include)(" + _ws1 + r")([^\n]+)", - bygroups(Comment.Preproc, Text, Comment.PreprocFile), - ), - (r"[^/\n]+", Comment.Preproc), - (r"/[*](.|\n)*?[*]/", Comment.Multiline), - (r"//.*?\n", Comment.Single, "#pop"), - (r"/", Comment.Preproc), - (r"(?<=\\)\n", Comment.Preproc), - (r"\n", Comment.Preproc, "#pop"), - ], - "if0": [ - (r"^\s*#if.*?(?)", Text, "#pop"), - ], - } - - def analyse_text(text): - if re.search("#include <[a-z_]+>", text): - return 0.2 - if re.search("using namespace ", text): - return 0.4 - - -lexers["cpp"] = MyCppLexer(startinline=True) - -# TODO Remove the above when Pygments release with fixes is available - - # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. # For a full list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html +import re + def get_version(): try: