From 3336886f59872d34874cc01acea5fbf752e5c19f Mon Sep 17 00:00:00 2001 From: William Andrea Date: Sun, 20 Aug 2023 16:54:41 -0400 Subject: [PATCH 1/5] Fix grammar token links in string.rst Fix links from Format String Syntax grammar and Format Specification Mini-Language grammar to Python grammar. Also link `arg_name` token within Format String Syntax grammar. --- Doc/library/string.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 9b28f99536a3ae..32dbd2d50d62d7 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -208,10 +208,10 @@ The grammar for a replacement field is as follows: .. productionlist:: format-string replacement_field: "{" [`field_name`] ["!" `conversion`] [":" `format_spec`] "}" - field_name: arg_name ("." `attribute_name` | "[" `element_index` "]")* - arg_name: [`identifier` | `digit`+] - attribute_name: `identifier` - element_index: `digit`+ | `index_string` + field_name: `arg_name` ("." `attribute_name` | "[" `element_index` "]")* + arg_name: [`~python-grammar:identifier` | `~python-grammar:digit`+] + attribute_name: `~python-grammar:identifier` + element_index: `~python-grammar:digit`+ | `index_string` index_string: + conversion: "r" | "s" | "a" format_spec: @@ -316,9 +316,9 @@ The general form of a *standard format specifier* is: fill: align: "<" | ">" | "=" | "^" sign: "+" | "-" | " " - width: `digit`+ + width: `~python-grammar:digit`+ grouping_option: "_" | "," - precision: `digit`+ + precision: `~python-grammar:digit`+ type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%" If a valid *align* value is specified, it can be preceded by a *fill* From 3b891e2bd6083d412fb4a83e4d4a3624685654c1 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 10 Sep 2023 02:40:47 +0100 Subject: [PATCH 2/5] Patch ``sphinx.domains.std.token_re`` --- Doc/tools/extensions/pyspecific.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 3cf4d236604bcb..91ab36e8c20ab2 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -48,6 +48,10 @@ Body.enum.converters['lowerroman'] = \ Body.enum.converters['upperroman'] = lambda x: None +# monkey-patch productionlist directive to allow hyphens in group names +from sphinx.domains import std + +std.token_re = re.compile(r'`((~?[\w-]*:)?\w+)`') # Support for marking up and linking to bugs.python.org issues From d0241c46f4ce46ed8b8456fd0150da6cb5ddf9b7 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 10 Sep 2023 02:45:11 +0100 Subject: [PATCH 3/5] Remove --- Doc/tools/.nitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore index a6268048e143db..964c182c15d6ad 100644 --- a/Doc/tools/.nitignore +++ b/Doc/tools/.nitignore @@ -116,7 +116,6 @@ Doc/library/socket.rst Doc/library/socketserver.rst Doc/library/ssl.rst Doc/library/stdtypes.rst -Doc/library/string.rst Doc/library/subprocess.rst Doc/library/sys_path_init.rst Doc/library/syslog.rst From 15087a09d2b535e1ff4c9fc8d3c54adcf8403217 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 10 Sep 2023 02:48:09 +0100 Subject: [PATCH 4/5] grammar --- Doc/tools/extensions/pyspecific.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 91ab36e8c20ab2..890520edb59d39 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -48,7 +48,7 @@ Body.enum.converters['lowerroman'] = \ Body.enum.converters['upperroman'] = lambda x: None -# monkey-patch productionlist directive to allow hyphens in group names +# monkey-patch the productionlist directive to allow hyphens in group names from sphinx.domains import std std.token_re = re.compile(r'`((~?[\w-]*:)?\w+)`') From 4fcf84cfe3931e7783640770738491f007cf2a9b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 9 Jan 2024 02:40:06 +0000 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Sergey B Kirpichev --- Doc/library/string.rst | 2 +- Doc/tools/extensions/pyspecific.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 14f66c11342e37..1867678b2077fc 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -214,7 +214,7 @@ The grammar for a replacement field is as follows: element_index: `~python-grammar:digit`+ | `index_string` index_string: + conversion: "r" | "s" | "a" - format_spec: + format_spec: `format-spec:format_spec` In less formal terms, the replacement field can start with a *field_name* that specifies the object whose value is to be formatted and inserted diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index b455c221c4ace1..cd441836f62bde 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -49,6 +49,7 @@ Body.enum.converters['upperroman'] = lambda x: None # monkey-patch the productionlist directive to allow hyphens in group names +# https://github.com/sphinx-doc/sphinx/issues/11854 from sphinx.domains import std std.token_re = re.compile(r'`((~?[\w-]*:)?\w+)`')