How to read python string formatting grammar?

The python documentation contains information about the grammar of the strings, however I cannot find information on how to read the table defining the grammar for the replacement field.

replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"
field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*
arg_name          ::=  [identifier | integer]
attribute_name    ::=  identifier
element_index     ::=  integer | index_string
index_string      ::=  <any source character except "]"> +
conversion        ::=  "r" | "s" | "a"
format_spec       ::=  <described in the next section>

The format section has a similar table.

I understand the parts of the table, how ::=separates the definiteness and the determinant, the characters inside the quotes are literals, which |means "or", but the rest of the table eludes me.

+4
source share
1 answer

-. BNF. , BNF - .

:

  • , :: =, |, <, > (, Python)
  • :: = " "
  • The | ""
  • <, > , .

, :

replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"
field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*

replacement_field field_name, conversion format_spec. ([]) .

field_name replacement_field, arg_name, attribute_name element_index. element_index , , , BNF .

+2

Source: https://habr.com/ru/post/1627384/


All Articles