Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is __peg_parser__ in Python?

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!?

like image 666
Abhigyan Jaiswal Avatar asked Dec 29 '20 03:12

Abhigyan Jaiswal


People also ask

What is PEG parser in Python?

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.

What is PEG parser in Python 3. 9?

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.


1 Answers

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.

like image 200
ShadowRanger Avatar answered Sep 25 '22 15:09

ShadowRanger