Support named arguments

This commit is contained in:
jamboree
2015-06-10 09:32:59 +08:00
parent ed2dfe5124
commit 7487bde587
5 changed files with 239 additions and 16 deletions
+7 -5
View File
@@ -15,13 +15,15 @@ literal text, it can be escaped by doubling: ``{{`` and ``}}``.
The grammar for a replacement field is as follows:
.. productionlist:: sf
replacement_field: "{" [`arg_index`] [":" `format_spec`] "}"
replacement_field: "{" [`arg_field`] [":" `format_spec`] "}"
arg_field: `arg_index` | `arg_name`
arg_index: `integer`
arg_name: \^[a-zA-Z_][a-zA-Z0-9_]*$\
In less formal terms, the replacement field can start with an *arg_index*
In less formal terms, the replacement field can start with an *arg_field*
that specifies the argument whose value is to be formatted and inserted into
the output instead of the replacement field.
The *arg_index* is optionally followed by a *format_spec*, which is preceded
The *arg_field* is optionally followed by a *format_spec*, which is preceded
by a colon ``':'``. These specify a non-default format for the replacement value.
See also the :ref:`formatspec` section.
@@ -73,8 +75,8 @@ The general form of a *standard format specifier* is:
fill: <a character other than '{' or '}'>
align: "<" | ">" | "=" | "^"
sign: "+" | "-" | " "
width: `integer` | "{" `arg_index` "}"
precision: `integer` | "{" `arg_index` "}"
width: `integer` | "{" `arg_field` "}"
precision: `integer` | "{" `arg_field` "}"
type: `int_type` | "c" | "e" | "E" | "f" | "F" | "g" | "G" | "p" | "s"
int_type: "b" | "B" | "d" | "o" | "x" | "X"