circuitpython/ports
Jim Mussared 692d36d779 py: Implement partial PEP-498 (f-string) support.
This implements (most of) the PEP-498 spec for f-strings and is based on
https://github.com/micropython/micropython/pull/4998 by @klardotsh.

It is implemented in the lexer as a syntax translation to `str.format`:
  f"{a}" --> "{}".format(a)

It also supports:
  f"{a=}" --> "a={}".format(a)

This is done by extracting the arguments into a temporary vstr buffer,
then after the string has been tokenized, the lexer input queue is saved
and the contents of the temporary vstr buffer are injected into the lexer
instead.

There are four main limitations:
- raw f-strings (`fr` or `rf` prefixes) are not supported and will raise
  `SyntaxError: raw f-strings are not supported`.

- literal concatenation of f-strings with adjacent strings will fail
    "{}" f"{a}" --> "{}{}".format(a)    (str.format will incorrectly use
                                         the braces from the non-f-string)
    f"{a}" f"{a}" --> "{}".format(a) "{}".format(a) (cannot concatenate)

- PEP-498 requires the full parser to understand the interpolated
  argument, however because this entirely runs in the lexer it cannot
  resolve nested braces in expressions like
    f"{'}'}"

- The !r, !s, and !a conversions are not supported.

Includes tests and cpydiffs.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14 16:58:40 +10:00
..
bare-arm all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
cc3200 all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
esp32 esp32/makeimg.py: Get bootloader and partition offset from sdkconfig. 2021-08-10 00:19:49 +10:00
esp8266 esp8266,esp32: Include hidden networks in WLAN.scan results. 2021-08-07 13:28:34 +10:00
javascript all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
mimxrt ports: Rename USBD_VID/PID config macros to MICROPY_HW_USB_VID/PID. 2021-08-07 23:13:55 +10:00
minimal minimal/Makefile: Add support for building with user C modules. 2021-07-23 12:02:03 +10:00
nrf nrf: Set .mpy features consistent with documentation and other ports. 2021-08-13 23:22:54 +10:00
pic16bit all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
powerpc all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
qemu-arm all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
rp2 rp2/CMakeLists.txt: Allow a board's cmake to set the manifest path. 2021-08-10 11:05:33 +10:00
samd ports: Rename USBD_VID/PID config macros to MICROPY_HW_USB_VID/PID. 2021-08-07 23:13:55 +10:00
stm32 stm32/mbedtls: Fix compile warning about uninitialized val. 2021-08-10 23:43:25 +10:00
teensy all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
unix py: Implement partial PEP-498 (f-string) support. 2021-08-14 16:58:40 +10:00
windows py: Implement partial PEP-498 (f-string) support. 2021-08-14 16:58:40 +10:00
zephyr all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00