@@ -1080,8 +1080,24 @@ even if they do not include expressions::
10801080 * :meth: `str.format `, which uses a related format string mechanism.
10811081
10821082
1083+ .. _t-strings :
1084+ .. _template-string-literals :
1085+
1086+ t-strings
1087+ ---------
1088+
1089+ .. versionadded :: 3.14
1090+
1091+ A :dfn: `template string literal ` or :dfn: `t-string ` is a string literal
1092+ that is prefixed with '``t ``' or '``T ``'.
1093+ These strings follow the same syntax rules as
1094+ :ref: `formatted string literals <f-strings >`.
1095+ For differences in evaluation rules, see the
1096+ :ref: `Standard Library section on t-strings <stdtypes-tstrings >`
1097+
1098+
10831099Formal grammar for f-strings
1084- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1100+ ----------------------------
10851101
10861102F-strings are handled partly by the :term: `lexical analyzer `, which produces the
10871103tokens :py:data: `~token.FSTRING_START `, :py:data: `~token.FSTRING_MIDDLE `
@@ -1115,7 +1131,7 @@ The ``FSTRING_MIDDLE`` definition uses
11151131to indicate special characters (backslash, newline, ``{ ``, ``} ``) and
11161132sequences (``f_quote ``).
11171133
1118- .. grammar-snippet :: python-grammar
1134+ .. grammar-snippet ::
11191135 :group: python-grammar
11201136
11211137 fstring: `FSTRING_START ` `fstring_middle`* `FSTRING_END `
@@ -1158,47 +1174,15 @@ sequences (``f_quote``).
11581174 Constructing a more traditional formal grammar from this template is left
11591175 as an exercise for the reader.
11601176
1177+ The grammar for t-strings is identical to the one for f-strings, with *t *
1178+ instead of *f * at the beginning of rule and token names and in the prefix.
11611179
1162- .. _t-strings :
1163- .. _template-string-literals :
1164-
1165- t-strings
1166- ---------
1180+ .. grammar-snippet ::
1181+ :group: python-grammar
11671182
1168- .. versionadded :: 3.14
1183+ tstring: ` TSTRING_START ` `tstring_middle`* ` TSTRING_END `
11691184
1170- A :dfn: `template string literal ` or :dfn: `t-string ` is a string literal
1171- that is prefixed with '``t ``' or '``T ``'.
1172- These strings follow the same syntax and evaluation rules as
1173- :ref: `formatted string literals <f-strings >`, with the following differences:
1174-
1175- * Rather than evaluating to a ``str `` object, template string literals evaluate
1176- to a :class: `string.templatelib.Template ` object.
1177-
1178- * The :func: `format ` protocol is not used.
1179- Instead, the format specifier and conversions (if any) are passed to
1180- a new :class: `~string.templatelib.Interpolation ` object that is created
1181- for each evaluated expression.
1182- It is up to code that processes the resulting :class: `~string.templatelib.Template `
1183- object to decide how to handle format specifiers and conversions.
1184-
1185- * Format specifiers containing nested replacement fields are evaluated eagerly,
1186- prior to being passed to the :class: `~string.templatelib.Interpolation ` object.
1187- For instance, an interpolation of the form ``{amount:.{precision}f} `` will
1188- evaluate the inner expression ``{precision} `` to determine the value of the
1189- ``format_spec `` attribute.
1190- If ``precision `` were to be ``2 ``, the resulting format specifier
1191- would be ``'.2f' ``.
1192-
1193- * When the equals sign ``'=' `` is provided in an interpolation expression,
1194- the text of the expression is appended to the literal string that precedes
1195- the relevant interpolation.
1196- This includes the equals sign and any surrounding whitespace.
1197- The :class: `!Interpolation ` instance for the expression will be created as
1198- normal, except that :attr: `~string.templatelib.Interpolation.conversion ` will
1199- be set to '``r ``' (:func: `repr `) by default.
1200- If an explicit conversion or format specifier are provided,
1201- this will override the default behaviour.
1185+ <rest of the t-string grammar is omitted; see above>
12021186
12031187
12041188.. _numbers :
0 commit comments