<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/py/lexer.h, branch 5.3.1</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=5.3.1</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=5.3.1'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2020-03-09T14:03:25+00:00</updated>
<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>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>all: Use the name MicroPython consistently in comments</title>
<updated>2017-07-31T08:35:40+00:00</updated>
<author>
<name>Alexander Steffen</name>
<email>devel.20.webmeister@spamgourmet.com</email>
</author>
<published>2017-06-30T07:22:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=55f33240f3d7051d4213629e92437a36f1fac50e'/>
<id>urn:sha1:55f33240f3d7051d4213629e92437a36f1fac50e</id>
<content type='text'>
There were several different spellings of MicroPython present in comments,
when there should be only one.
</content>
</entry>
<entry>
<title>all: Unify header guard usage.</title>
<updated>2017-07-18T01:57:39+00:00</updated>
<author>
<name>Alexander Steffen</name>
<email>devel.20.webmeister@spamgourmet.com</email>
</author>
<published>2017-06-29T21:14:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=299bc625864b9e624ed599c94a5f95870516139a'/>
<id>urn:sha1:299bc625864b9e624ed599c94a5f95870516139a</id>
<content type='text'>
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.

This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.

The rules are as follows.

Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _

In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.

py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
</content>
</entry>
<entry>
<title>py/lexer: Convert mp_uint_t to size_t where appropriate.</title>
<updated>2017-02-17T01:44:24+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-02-17T01:44:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=5124a940670dbb5c07f6681070b3d1580c71d697'/>
<id>urn:sha1:5124a940670dbb5c07f6681070b3d1580c71d697</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/lexer: Simplify handling of line-continuation error.</title>
<updated>2017-02-17T00:30:14+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-02-17T00:30:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=773278ec3030ea9ed809c5a248fde2278ce4b557'/>
<id>urn:sha1:773278ec3030ea9ed809c5a248fde2278ce4b557</id>
<content type='text'>
Previous to this patch there was an explicit check for errors with line
continuation (where backslash was not immediately followed by a newline).

But this check is not necessary: if there is an error then the remaining
logic of the tokeniser will reject the backslash and correctly produce a
syntax error.
</content>
</entry>
<entry>
<title>py/lexer: Use strcmp to make keyword searching more efficient.</title>
<updated>2017-02-17T00:10:35+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-02-17T00:10:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=ae436797927c3c9f7ccdc25dd78af3dd279ca7ff'/>
<id>urn:sha1:ae436797927c3c9f7ccdc25dd78af3dd279ca7ff</id>
<content type='text'>
Since the table of keywords is sorted, we can use strcmp to do the search
and stop part way through the search if the comparison is less-than.

Because all tokens that are names are subject to this search, this
optimisation will improve the overall speed of the lexer when processing
a script.

The change also decreases code size by a little bit because we now use
strcmp instead of the custom str_strn_equal function.
</content>
</entry>
<entry>
<title>py/lexer: Permanently disable the mp_lexer_show_token function.</title>
<updated>2016-12-21T23:49:54+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-12-21T23:49:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=c305ae32436e37327d33df979d57d9ac1fb822c1'/>
<id>urn:sha1:c305ae32436e37327d33df979d57d9ac1fb822c1</id>
<content type='text'>
The lexer is very mature and this debug function is no longer used.  If
it's really needed one can uncomment it and recompile.
</content>
</entry>
<entry>
<title>py/lexer: Make lexer use an mp_reader as its source.</title>
<updated>2016-11-16T07:35:01+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-11-16T07:27:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=5bdf1650de782d766a648f992270306269cc985a'/>
<id>urn:sha1:5bdf1650de782d766a648f992270306269cc985a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py: add async/await/async for/async with syntax</title>
<updated>2016-04-13T14:26:38+00:00</updated>
<author>
<name>pohmelie</name>
<email>multisosnooley@gmail.com</email>
</author>
<published>2016-01-27T20:23:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=81ebba7e0236163b7594938201bf3a6b802ebfaa'/>
<id>urn:sha1:81ebba7e0236163b7594938201bf3a6b802ebfaa</id>
<content type='text'>
They are sugar for marking function as generator, "yield from"
and pep492 python "semantically equivalents" respectively.

@dpgeorge was the original author of this patch, but @pohmelie made
changes to implement `async for` and `async with`.
</content>
</entry>
</feed>
