@@ -157,30 +157,31 @@ def check_directive_missing_colons(file, lines, options=None):
157157 yield lno , "comment seems to be intended as a directive"
158158
159159
160+ # The difficulty here is that the following is valid:
161+ # The :literal:`:exc:`Exceptions``
162+ # While this is not:
163+ # The :literal:`:exc:`Exceptions``s
164+ _ROLE_BODY = rf"([^`]|\s`+|\\`|:{ rst .SIMPLENAME } :`([^`]|\s`+|\\`)+`)+"
165+ _ALLOWED_AFTER_ROLE = (
166+ rst .ASCII_ALLOWED_AFTER_INLINE_MARKUP
167+ + rst .UNICODE_ALLOWED_AFTER_INLINE_MARKUP
168+ + r"|\s"
169+ )
170+ _SUSPICIOUS_ROLE = re .compile (
171+ f":{ rst .SIMPLENAME } :`{ _ROLE_BODY } `[^{ _ALLOWED_AFTER_ROLE } ]"
172+ )
173+
174+
160175@checker (".rst" , ".po" )
161176def check_missing_space_after_role (file , lines , options = None ):
162177 r"""Search for roles immediately followed by a character.
163178
164179 Bad: :exc:`Exception`s.
165180 Good: :exc:`Exceptions`\ s
166181 """
167- # The difficulty here is that the following is valid:
168- # The :literal:`:exc:`Exceptions``
169- # While this is not:
170- # The :literal:`:exc:`Exceptions``s
171- role_body = rf"([^`]|\s`+|\\`|:{ rst .SIMPLENAME } :`([^`]|\s`+|\\`)+`)+"
172- allowed_after_role = (
173- rst .ASCII_ALLOWED_AFTER_INLINE_MARKUP
174- + rst .UNICODE_ALLOWED_AFTER_INLINE_MARKUP
175- + r"|\s"
176- )
177-
178- suspicious_role = re .compile (
179- f":{ rst .SIMPLENAME } :`{ role_body } `[^{ allowed_after_role } ]"
180- )
181182 for lno , line in enumerate (lines , start = 1 ):
182183 line = clean_paragraph (line )
183- role = suspicious_role .search (line )
184+ role = _SUSPICIOUS_ROLE .search (line )
184185 if role :
185186 yield lno , f"role missing (escaped) space after role: { role .group (0 )!r} "
186187
0 commit comments