mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use `re` flags
This commit is contained in:
@@ -85,7 +85,7 @@ _string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
|
||||
r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S)
|
||||
|
||||
# bool, complex, and imaginary are macro "keywords", so they are handled seperately
|
||||
_simple_type_specifiers_re = re.compile(r"""(?x)
|
||||
_simple_type_specifiers_re = re.compile(r"""
|
||||
\b(
|
||||
void|_Bool
|
||||
|signed|unsigned
|
||||
@@ -101,7 +101,7 @@ _simple_type_specifiers_re = re.compile(r"""(?x)
|
||||
|__fp16 # extension
|
||||
|_Sat|_Fract|fract|_Accum|accum # extension
|
||||
)\b
|
||||
""")
|
||||
""", re.VERBOSE)
|
||||
|
||||
|
||||
class _DuplicateSymbolError(Exception):
|
||||
|
||||
@@ -289,13 +289,13 @@ T = TypeVar('T')
|
||||
nested-name
|
||||
"""
|
||||
|
||||
udl_identifier_re = re.compile(r'''(?x)
|
||||
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.S)
|
||||
_visibility_re = re.compile(r'\b(public|private|protected)\b')
|
||||
_operator_re = re.compile(r'''(?x)
|
||||
_operator_re = re.compile(r'''
|
||||
\[\s*\]
|
||||
| \(\s*\)
|
||||
| \+\+ | --
|
||||
@@ -304,13 +304,13 @@ _operator_re = re.compile(r'''(?x)
|
||||
| <=>
|
||||
| [!<>=/*%+|&^~-]=?
|
||||
| (\b(and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq)\b)
|
||||
''')
|
||||
_fold_operator_re = re.compile(r'''(?x)
|
||||
''', re.VERBOSE)
|
||||
_fold_operator_re = re.compile(r'''
|
||||
->\* | \.\* | \,
|
||||
| (<<|>>)=? | && | \|\|
|
||||
| !=
|
||||
| [<>=/*%+|&^~-]=?
|
||||
''')
|
||||
''', re.VERBOSE)
|
||||
# see https://en.cppreference.com/w/cpp/keyword
|
||||
_keywords = [
|
||||
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor',
|
||||
@@ -330,7 +330,7 @@ _keywords = [
|
||||
]
|
||||
|
||||
|
||||
_simple_type_specifiers_re = re.compile(r"""(?x)
|
||||
_simple_type_specifiers_re = re.compile(r"""
|
||||
\b(
|
||||
auto|void|bool
|
||||
|signed|unsigned
|
||||
@@ -342,7 +342,7 @@ _simple_type_specifiers_re = re.compile(r"""(?x)
|
||||
|__float80|_Float64x|__float128|_Float128 # extension
|
||||
|_Complex|_Imaginary # extension
|
||||
)\b
|
||||
""")
|
||||
""", re.VERBOSE)
|
||||
|
||||
_max_id = 4
|
||||
_id_prefix = [None, '', '_CPPv2', '_CPPv3', '_CPPv4']
|
||||
|
||||
@@ -210,8 +210,8 @@ class WordCollector(nodes.NodeVisitor):
|
||||
# Some people might put content in raw HTML that should be searched,
|
||||
# so we just amateurishly strip HTML tags and index the remaining
|
||||
# content
|
||||
nodetext = re.sub(r'(?is)<style.*?</style>', '', node.astext())
|
||||
nodetext = re.sub(r'(?is)<script.*?</script>', '', nodetext)
|
||||
nodetext = re.sub(r'<style.*?</style>', '', node.astext(), flags=re.IGNORECASE|re.DOTALL)
|
||||
nodetext = re.sub(r'<script.*?</script>', '', nodetext, flags=re.IGNORECASE|re.DOTALL)
|
||||
nodetext = re.sub(r'<[^<]+?>', '', nodetext)
|
||||
self.found_words.extend(self.lang.split(nodetext))
|
||||
raise nodes.SkipNode
|
||||
|
||||
@@ -18,21 +18,21 @@ logger = logging.getLogger(__name__)
|
||||
StringifyTransform = Callable[[Any], str]
|
||||
|
||||
|
||||
_whitespace_re = re.compile(r'(?u)\s+')
|
||||
_whitespace_re = re.compile(r'\s+')
|
||||
anon_identifier_re = re.compile(r'(@[a-zA-Z0-9_])[a-zA-Z0-9_]*\b')
|
||||
identifier_re = re.compile(r'''(?x)
|
||||
identifier_re = re.compile(r'''
|
||||
( # This 'extends' _anon_identifier_re with the ordinary identifiers,
|
||||
# make sure they are in sync.
|
||||
(~?\b[a-zA-Z_]) # ordinary identifiers
|
||||
| (@[a-zA-Z0-9_]) # our extension for names of anonymous entities
|
||||
)
|
||||
[a-zA-Z0-9_]*\b
|
||||
''')
|
||||
''', flags=re.VERBOSE)
|
||||
integer_literal_re = re.compile(r'[1-9][0-9]*(\'[0-9]+)*')
|
||||
octal_literal_re = re.compile(r'0[0-7]*(\'[0-7]+)*')
|
||||
hex_literal_re = re.compile(r'0[xX][0-9a-fA-F]+(\'[0-9a-fA-F]+)*')
|
||||
binary_literal_re = re.compile(r'0[bB][01]+(\'[01]+)*')
|
||||
integers_literal_suffix_re = re.compile(r'''(?x)
|
||||
integers_literal_suffix_re = re.compile(r'''
|
||||
# unsigned and/or (long) long, in any order, but at least one of them
|
||||
(
|
||||
([uU] ([lL] | (ll) | (LL))?)
|
||||
@@ -41,8 +41,8 @@ integers_literal_suffix_re = re.compile(r'''(?x)
|
||||
)\b
|
||||
# the ending word boundary is important for distinguishing
|
||||
# between suffixes and UDLs in C++
|
||||
''')
|
||||
float_literal_re = re.compile(r'''(?x)
|
||||
''', flags=re.VERBOSE)
|
||||
float_literal_re = re.compile(r'''
|
||||
[+-]?(
|
||||
# decimal
|
||||
([0-9]+(\'[0-9]+)*[eE][+-]?[0-9]+(\'[0-9]+)*)
|
||||
@@ -54,10 +54,10 @@ float_literal_re = re.compile(r'''(?x)
|
||||
[0-9a-fA-F]+(\'[0-9a-fA-F]+)*([pP][+-]?[0-9a-fA-F]+(\'[0-9a-fA-F]+)*)?)
|
||||
| (0[xX][0-9a-fA-F]+(\'[0-9a-fA-F]+)*\.([pP][+-]?[0-9a-fA-F]+(\'[0-9a-fA-F]+)*)?)
|
||||
)
|
||||
''')
|
||||
''', flags=re.VERBOSE)
|
||||
float_literal_suffix_re = re.compile(r'[fFlL]\b')
|
||||
# the ending word boundary is important for distinguishing between suffixes and UDLs in C++
|
||||
char_literal_re = re.compile(r'''(?x)
|
||||
char_literal_re = re.compile(r'''
|
||||
((?:u8)|u|U|L)?
|
||||
'(
|
||||
(?:[^\\'])
|
||||
@@ -69,7 +69,7 @@ char_literal_re = re.compile(r'''(?x)
|
||||
| (?:U[0-9a-fA-F]{8})
|
||||
))
|
||||
)'
|
||||
''')
|
||||
''', flags=re.VERBOSE)
|
||||
|
||||
|
||||
def verify_description_mode(mode: str) -> None:
|
||||
|
||||
@@ -114,8 +114,8 @@ class InventoryFile:
|
||||
|
||||
for line in stream.read_compressed_lines():
|
||||
# be careful to handle names with embedded spaces correctly
|
||||
m = re.match(r'(?x)(.+?)\s+(\S+)\s+(-?\d+)\s+?(\S*)\s+(.*)',
|
||||
line.rstrip())
|
||||
m = re.match(r'(.+?)\s+(\S+)\s+(-?\d+)\s+?(\S*)\s+(.*)',
|
||||
line.rstrip(), flags=re.VERBOSE)
|
||||
if not m:
|
||||
continue
|
||||
name, type, prio, location, dispname = m.groups()
|
||||
|
||||
Reference in New Issue
Block a user