micropython/ports/unix
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
..
variants unix/variants: Enable help and help("modules") on standard and dev. 2021-07-13 16:18:15 +10:00
.gitignore
Makefile unix/Makefile: Add back LIB_SRC_C to list of object files. 2021-07-13 15:58:39 +10:00
alloc.c
coverage.c
coveragecpp.cpp
fatfs_port.c
gccollect.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
input.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
input.h
main.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
modffi.c
modjni.c py: Introduce and use mp_raise_type_arg helper. 2021-07-15 00:12:41 +10:00
modmachine.c
modos.c
modtermios.c
modtime.c
moduos_vfs.c
moduselect.c
modusocket.c
mpbthciport.c
mpbtstackport.h
mpbtstackport_common.c
mpbtstackport_h4.c
mpbtstackport_usb.c
mpconfigport.h py: Implement partial PEP-498 (f-string) support. 2021-08-14 16:58:40 +10:00
mpconfigport.mk
mphalport.h all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
mpnimbleport.c
mpnimbleport.h
mpthreadport.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
mpthreadport.h
qstrdefsport.h
unix_mphal.c