Enable automatic formatting for `sphinx/domains/cpp/`

This commit is contained in:
Adam Turner 2024-12-30 02:40:27 +00:00
parent 3e2f89b820
commit 51a38d5f98
6 changed files with 2247 additions and 1459 deletions

View File

@ -396,11 +396,6 @@ exclude = [
"sphinx/builders/latex/constants.py",
"sphinx/domains/changeset.py",
"sphinx/domains/citation.py",
"sphinx/domains/cpp/_parser.py",
"sphinx/domains/cpp/_ids.py",
"sphinx/domains/cpp/__init__.py",
"sphinx/domains/cpp/_symbol.py",
"sphinx/domains/cpp/_ast.py",
"sphinx/domains/index.py",
"sphinx/domains/javascript.py",
"sphinx/domains/math.py",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -254,13 +254,17 @@ from __future__ import annotations
import re
udl_identifier_re = re.compile(r'''
[a-zA-Z_][a-zA-Z0-9_]*\b # note, no word boundary in the beginning
''', re.VERBOSE)
_string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.DOTALL)
udl_identifier_re = re.compile(
r'[a-zA-Z_][a-zA-Z0-9_]*\b' # note, no word boundary in the beginning
)
_string_re = re.compile(
r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
r'|"([^"\\]*(?:\\.[^"\\]*)*)")',
re.DOTALL,
)
_visibility_re = re.compile(r'\b(public|private|protected)\b')
_operator_re = re.compile(r'''
_operator_re = re.compile(
r"""
\[\s*\]
| \(\s*\)
| \+\+ | --
@ -269,33 +273,49 @@ _operator_re = re.compile(r'''
| <=>
| [!<>=/*%+|&^~-]=?
| (\b(and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq)\b)
''', re.VERBOSE)
_fold_operator_re = re.compile(r'''
""",
re.VERBOSE,
)
_fold_operator_re = re.compile(
r"""
->\* | \.\* | \,
| (<<|>>)=? | && | \|\|
| !=
| [<>=/*%+|&^~-]=?
''', re.VERBOSE)
""",
re.VERBOSE,
)
# see https://en.cppreference.com/w/cpp/keyword
_keywords = [
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor',
'bool', 'break', 'case', 'catch', 'char', 'char8_t', 'char16_t', 'char32_t',
'class', 'compl', 'concept', 'const', 'consteval', 'constexpr', 'constinit',
'const_cast', 'continue',
'decltype', 'default', 'delete', 'do', 'double', 'dynamic_cast', 'else',
'enum', 'explicit', 'export', 'extern', 'false', 'float', 'for', 'friend',
'goto', 'if', 'inline', 'int', 'long', 'mutable', 'namespace', 'new',
'noexcept', 'not', 'not_eq', 'nullptr', 'operator', 'or', 'or_eq',
'private', 'protected', 'public', 'register', 'reinterpret_cast',
'requires', 'return', 'short', 'signed', 'sizeof', 'static',
'static_assert', 'static_cast', 'struct', 'switch', 'template', 'this',
'thread_local', 'throw', 'true', 'try', 'typedef', 'typeid', 'typename',
'union', 'unsigned', 'using', 'virtual', 'void', 'volatile', 'wchar_t',
'while', 'xor', 'xor_eq',
]
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto',
'bitand', 'bitor', 'bool', 'break',
'case', 'catch', 'class', 'compl', 'concept', 'continue',
'char', 'char8_t', 'char16_t', 'char32_t',
'const', 'const_cast', 'consteval', 'constexpr', 'constinit',
'decltype', 'default', 'delete', 'do', 'double', 'dynamic_cast',
'else', 'enum', 'explicit', 'export', 'extern',
'false', 'float', 'for', 'friend',
'goto',
'if', 'inline', 'int',
'long',
'mutable',
'namespace', 'new', 'noexcept', 'not', 'not_eq', 'nullptr',
'operator', 'or', 'or_eq',
'private', 'protected', 'public',
'register', 'reinterpret_cast', 'requires', 'return',
'short', 'signed', 'sizeof', 'static',
'static_assert', 'static_cast', 'struct', 'switch',
'template', 'this', 'thread_local', 'throw',
'true', 'try', 'typedef', 'typeid', 'typename',
'union', 'unsigned', 'using',
'virtual', 'void', 'volatile',
'wchar_t', 'while',
'xor', 'xor_eq',
] # fmt: skip
_simple_type_specifiers_re = re.compile(r"""
_simple_type_specifiers_re = re.compile(
r"""
\b(
auto|void|bool
|signed|unsigned
@ -307,7 +327,9 @@ _simple_type_specifiers_re = re.compile(r"""
|__float80|_Float64x|__float128|_Float128 # extension
|_Complex|_Imaginary # extension
)\b
""", re.VERBOSE)
""",
re.VERBOSE,
)
_max_id = 4
_id_prefix = [None, '', '_CPPv2', '_CPPv3', '_CPPv4']
@ -433,8 +455,10 @@ _id_fundamental_v2 = {
'float': 'f',
'double': 'd',
'long double': 'e',
'__float80': 'e', '_Float64x': 'e',
'__float128': 'g', '_Float128': 'g',
'__float80': 'e',
'_Float64x': 'e',
'__float128': 'g',
'_Float128': 'g',
'_Complex float': 'Cf',
'_Complex double': 'Cd',
'_Complex long double': 'Ce',
@ -456,38 +480,49 @@ _id_operator_v2 = {
# '-(unary)' : 'ng',
# '&(unary)' : 'ad',
# '*(unary)' : 'de',
'~': 'co', 'compl': 'co',
'~': 'co',
'compl': 'co',
'+': 'pl',
'-': 'mi',
'*': 'ml',
'/': 'dv',
'%': 'rm',
'&': 'an', 'bitand': 'an',
'|': 'or', 'bitor': 'or',
'^': 'eo', 'xor': 'eo',
'&': 'an',
'bitand': 'an',
'|': 'or',
'bitor': 'or',
'^': 'eo',
'xor': 'eo',
'=': 'aS',
'+=': 'pL',
'-=': 'mI',
'*=': 'mL',
'/=': 'dV',
'%=': 'rM',
'&=': 'aN', 'and_eq': 'aN',
'|=': 'oR', 'or_eq': 'oR',
'^=': 'eO', 'xor_eq': 'eO',
'&=': 'aN',
'and_eq': 'aN',
'|=': 'oR',
'or_eq': 'oR',
'^=': 'eO',
'xor_eq': 'eO',
'<<': 'ls',
'>>': 'rs',
'<<=': 'lS',
'>>=': 'rS',
'==': 'eq',
'!=': 'ne', 'not_eq': 'ne',
'!=': 'ne',
'not_eq': 'ne',
'<': 'lt',
'>': 'gt',
'<=': 'le',
'>=': 'ge',
'<=>': 'ss',
'!': 'nt', 'not': 'nt',
'&&': 'aa', 'and': 'aa',
'||': 'oo', 'or': 'oo',
'!': 'nt',
'not': 'nt',
'&&': 'aa',
'and': 'aa',
'||': 'oo',
'or': 'oo',
'++': 'pp',
'--': 'mm',
',': 'cm',
@ -505,12 +540,17 @@ _id_operator_unary_v2 = {
'&': 'ad',
'+': 'ps',
'-': 'ng',
'!': 'nt', 'not': 'nt',
'~': 'co', 'compl': 'co',
'!': 'nt',
'not': 'nt',
'~': 'co',
'compl': 'co',
}
_id_char_from_prefix: dict[str | None, str] = {
None: 'c', 'u8': 'c',
'u': 'Ds', 'U': 'Di', 'L': 'w',
None: 'c',
'u8': 'c',
'u': 'Ds',
'U': 'Di',
'L': 'w',
}
# these are ordered by preceedence
_expression_bin_ops = [
@ -526,9 +566,34 @@ _expression_bin_ops = [
['*', '/', '%'],
['.*', '->*'],
]
_expression_unary_ops = ["++", "--", "*", "&", "+", "-", "!", "not", "~", "compl"]
_expression_assignment_ops = ["=", "*=", "/=", "%=", "+=", "-=",
">>=", "<<=", "&=", "and_eq", "^=", "|=", "xor_eq", "or_eq"]
_expression_unary_ops = [
'++',
'--',
'*',
'&',
'+',
'-',
'!',
'not',
'~',
'compl',
]
_expression_assignment_ops = [
'=',
'*=',
'/=',
'%=',
'+=',
'-=',
'>>=',
'<<=',
'&=',
'and_eq',
'^=',
'|=',
'xor_eq',
'or_eq',
]
_id_explicit_cast = {
'dynamic_cast': 'dc',
'static_cast': 'sc',

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff