<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/py/parse.c, branch 6.2.0-beta.1</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.2.0-beta.1</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.2.0-beta.1'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2020-07-06T18:16:25+00:00</updated>
<entry>
<title>Add license to some obvious files.</title>
<updated>2020-07-06T18:16:25+00:00</updated>
<author>
<name>Diego Elio Pettenò</name>
<email>flameeyes@flameeyes.com</email>
</author>
<published>2020-06-03T22:40:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=34b4993d63a6b576f29d624385c681f679b4124c'/>
<id>urn:sha1:34b4993d63a6b576f29d624385c681f679b4124c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>f-strings: Make optional, defaulting to !CIRCUITPY_MINIMAL_BUILD</title>
<updated>2020-03-09T14:03:25+00:00</updated>
<author>
<name>Jeff Epler</name>
<email>jepler@gmail.com</email>
</author>
<published>2020-03-09T14:02:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=473e9c5ffb081ae2750948099ac8288b039d4255'/>
<id>urn:sha1:473e9c5ffb081ae2750948099ac8288b039d4255</id>
<content type='text'>
This should reclaim *most* code space added to handle f-strings.
However, there may be some small code growth as parse_string_literal
takes a new parameter (which will always be 0, so hopefully the optimizer
eliminates it)
</content>
</entry>
<entry>
<title>Address dpgeorge feedback - largely simplifications</title>
<updated>2020-03-09T13:16:07+00:00</updated>
<author>
<name>Josh Klar</name>
<email>josh@klar.sh</email>
</author>
<published>2019-09-26T23:48:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=40bc05ee1eafcc2f0b3ed48f212a1526b65163bc'/>
<id>urn:sha1:40bc05ee1eafcc2f0b3ed48f212a1526b65163bc</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py: Implement partial PEP-498 (f-string) support</title>
<updated>2020-03-09T13:16:07+00:00</updated>
<author>
<name>Josh Klar</name>
<email>josh@klar.sh</email>
</author>
<published>2019-08-11T04:27:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=3a7a5ba6860c787cc691b5c828eff9a130f39526'/>
<id>urn:sha1:3a7a5ba6860c787cc691b5c828eff9a130f39526</id>
<content type='text'>
This implements (most of) the PEP-498 spec for f-strings, with two
exceptions:

- raw f-strings (`fr` or `rf` prefixes) raise `NotImplementedError`
- one special corner case does not function as specified in the PEP
(more on that in a moment)

This is implemented in the core as a syntax translation, brute-forcing
all f-strings to run through `String.format`. For example, the statement
`x='world'; print(f'hello {x}')` gets translated *at a syntax level*
(injected into the lexer) to `x='world'; print('hello {}'.format(x))`.
While this may lead to weird column results in tracebacks, it seemed
like the fastest, most efficient, and *likely* most RAM-friendly option,
despite being implemented under the hood with a completely separate
`vstr_t`.

Since [string concatenation of adjacent literals is implemented in the
lexer](https://github.com/micropython/micropython/commit/534b7c368dc2af7720f3aaed0c936ef46d773957),
two side effects emerge:

- All strings with at least one f-string portion are concatenated into a
single literal which *must* be run through `String.format()` wholesale,
and:
- Concatenation of a raw string with interpolation characters with an
f-string will cause `IndexError`/`KeyError`, which is both different
from CPython *and* different from the corner case mentioned in the PEP
(which gave an example of the following:)

```python
x = 10
y = 'hi'
assert ('a' 'b' f'{x}' '{c}' f'str&lt;{y:^4}&gt;' 'd' 'e') == 'ab10{c}str&lt; hi &gt;de'
```

The above-linked commit detailed a pretty solid case for leaving string
concatenation in the lexer rather than putting it in the parser, and
undoing that decision would likely be disproportionately costly on
resources for the sake of a probably-low-impact corner case. An
alternative to become complaint with this corner case of the PEP would
be to revert to string concatenation in the parser *only when an
f-string is part of concatenation*, though I've done no investigation on
the difficulty or costs of doing this.

A decent set of tests is included. I've manually tested this on the
`unix` port on Linux and on a Feather M4 Express (`atmel-samd`) and
things seem sane.
</content>
</entry>
<entry>
<title>parse: push_result_token: throw an exception on too-long names</title>
<updated>2020-03-01T15:38:34+00:00</updated>
<author>
<name>Jeff Epler</name>
<email>jepler@gmail.com</email>
</author>
<published>2020-03-01T15:38:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=511c1808699ef29908ab99180866c46dfeae4b95'/>
<id>urn:sha1:511c1808699ef29908ab99180866c46dfeae4b95</id>
<content type='text'>
Before this, such names would instead cause an assertion error inside
qstr_from_strn.

A simple reproducer is a python source file containing the letter "a"
repeated 256 times
</content>
</entry>
<entry>
<title>Two fixes and translate more strings.</title>
<updated>2018-08-09T20:29:30+00:00</updated>
<author>
<name>Scott Shawcroft</name>
<email>scott@tannewt.org</email>
</author>
<published>2018-08-09T01:24:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=96ebf5bc3fb455162286b9bc31e763f3c4f1c457'/>
<id>urn:sha1:96ebf5bc3fb455162286b9bc31e763f3c4f1c457</id>
<content type='text'>
* Fix finding translations with escaped characters.
* Add back \r to translations since its needed by screen.
</content>
</entry>
<entry>
<title>continued WIP: almost compiling</title>
<updated>2018-07-12T18:13:51+00:00</updated>
<author>
<name>Dan Halbert</name>
<email>halbert@halwitz.org</email>
</author>
<published>2018-07-12T18:13:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=0d27f4d9a66dcb47b545e715d1833094b0c7b484'/>
<id>urn:sha1:0d27f4d9a66dcb47b545e715d1833094b0c7b484</id>
<content type='text'>
</content>
</entry>
<entry>
<title>WIP: after merge; before testing</title>
<updated>2018-07-11T20:45:30+00:00</updated>
<author>
<name>Dan Halbert</name>
<email>halbert@halwitz.org</email>
</author>
<published>2018-07-11T20:45:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=7c219600a246d8956d0b23ea3f5d125a820e6b6a'/>
<id>urn:sha1:7c219600a246d8956d0b23ea3f5d125a820e6b6a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Make parsing more memory flexible.</title>
<updated>2018-01-25T02:22:20+00:00</updated>
<author>
<name>Scott Shawcroft</name>
<email>scott.shawcroft@gmail.com</email>
</author>
<published>2018-01-17T22:27:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=dff744558b32de05bbcf2e7a4804cb3c89e6658e'/>
<id>urn:sha1:dff744558b32de05bbcf2e7a4804cb3c89e6658e</id>
<content type='text'>
The parser attempts to allocate two large (~512 byte) chunks up
front. If it couldn't, then it would error out. This change will
cause it to try allocating half the previous attempt until its down
to two copies. This is ok upfront because later code checks bounds
and tries to extend the allocation if needed.
</content>
</entry>
<entry>
<title>py/parse: Fix macro evaluation by avoiding empty __VA_ARGS__.</title>
<updated>2017-12-29T02:44:26+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-28T13:53:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=c7cb1dfcb9f89eb0a2d2a90a5e496e919c8a0b94'/>
<id>urn:sha1:c7cb1dfcb9f89eb0a2d2a90a5e496e919c8a0b94</id>
<content type='text'>
Empty __VA_ARGS__ are not allowed in the C preprocessor so adjust the rule
arg offset calculation to not use them.  Also, some compilers (eg MSVC)
require an extra layer of macro expansion.
</content>
</entry>
</feed>
