I was using the keyword
built-in module to get a list of all the keywords of the current Python version. And this is what I did:
>>> import keyword >>> print(keyword.kwlist) ['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
And in the keyword.kwlist
list there is __peg_parser__
. So to see what it does, I type __peg_parser__
in a Python 3.9 interpreter on Windows (you'll get the same output on Mac OS and Linux as well), and this is what is get:
>>> __peg_parser__ File "<stdin>", line 1 __peg_parser__ ^ SyntaxError: You found it!
So my question is, what is __peg_parser__
and why do I get SyntaxError: You found it!
?
PEG parsers are usually constructed as a recursive descent parser in which every rule in the grammar corresponds to a function in the program implementing the parser and the parsing expression (the “expansion” or “definition” of the rule) represents the “code” in said function.
Python 3.9 uses a new parser, based on PEG instead of LL(1). The new parser's performance is roughly comparable to that of the old parser, but the PEG formalism is more flexible than LL(1) when it comes to designing new language features. We'll start using this flexibility in Python 3.10 and later.
It was an easter egg related to the rollout of the new PEG parser. The easter egg, along with the old LL(1) parser, will be removed in 3.10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With