PythonExtra/tools
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
..
autobuild tools/autobuild: Add auto build for Silicognition wESP32. 2021-08-13 23:25:24 +10:00
mpremote tools/mpremote: Add "devs" shortcut for "connect list". 2021-08-14 00:13:35 +10:00
.gitattributes micropython-upip: Mark as binary file and re-commit. 2015-06-06 23:09:23 +03:00
.gitignore tools: check-in errordeveloper/tinytest@eb2dbc858f 2014-05-08 01:41:21 +03:00
cc1 tools: Add C middle-processor to make builtin tables proper hash tables. 2015-12-31 00:24:33 +00:00
ci.sh tools/ci.sh: Add mpy-cross build to nrf port. 2021-08-08 23:17:55 +10:00
codeformat.py tools/codeformat.py: Include ports/nrf/modules/nrf in code formatting. 2021-08-08 23:17:55 +10:00
codestats.sh all: Update Makefiles and others to build with new ports/ dir layout. 2017-09-06 14:09:13 +10:00
dfu.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
file2h.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
gen-changelog.sh Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
gen-cpydiff.py tools/gen-cpydiff.py: Don't rename foo to ufoo in diff output. 2021-08-13 23:14:08 +10:00
gendoc.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
insert-usb-ids.py ports: Rename USBD_VID/PID config macros to MICROPY_HW_USB_VID/PID. 2021-08-07 23:13:55 +10:00
make-frozen.py tools: Write msvc-compatible frozen content. 2020-09-11 10:51:55 +10:00
makemanifest.py tools/makemanifest.py: Allow passing flags to mpy-tool.py. 2021-06-28 01:50:00 +03:00
metrics.py tools/metrics.py: Add rp2 port to table of ports that can be built. 2021-04-20 21:39:53 +10:00
mpy-tool.py tools/mpy-tool.py: Support relocating ARMv6 arch. 2021-05-26 16:24:00 +10:00
mpy_bin2res.py tools/mpy_bin2res: Tools to convert binary resources to Python module. 2017-07-27 14:41:27 +03:00
mpy_cross_all.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpy_ld.py tools/mpy_ld.py: Support R_X86_64_GOTPCREL reloc for x86-64 arch. 2021-05-20 23:34:20 +10:00
pyboard.py tools/pyboard.py: Add cmd-line option to make soft reset configurable. 2021-07-01 12:37:08 +10:00
pydfu.py tools/pydfu.py: Remove default VID/PID values. 2021-05-21 15:39:40 +10:00
tinytest-codegen.py py: Implement partial PEP-498 (f-string) support. 2021-08-14 16:58:40 +10:00
uf2conv.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
uncrustify.cfg tools/uncrustify: Enable more opts to remove space between func and '('. 2020-06-19 22:07:32 +10:00
upip.py tools/upip.py: Use .errno instead of .args[0] for OSError exceptions. 2021-04-23 22:03:46 +10:00
upip_utarfile.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
verifygitlog.py tools/verifygitlog.py: Show required format regexp in error message. 2021-02-21 15:55:44 +11:00