Python中的__peg_parser__是什么?
What is __peg_parser__ in Python?
我正在使用 keyword
内置模块来获取当前 Python 版本的所有关键字的列表。这就是我所做的:
>>> 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']
并且在 keyword.kwlist
列表中有 __peg_parser__
。因此,为了查看它的作用,我在 Windows 上的 Python 3.9 解释器中键入 __peg_parser__
(您将在 Mac OS 和 Linux),这就是 get:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!
所以我的问题是,什么是 __peg_parser__
,为什么我会得到 SyntaxError: You found it!
?
这是与 the new PEG parser. The easter egg, along with the old LL(1) parser, will be removed in 3.10 推出相关的彩蛋。
什么是 __peg_parser__
?
它是 Python 中的彩蛋(属于 Peg Parser) for when the new Peg Parser was released. As mentioned in this discussion,将在 Python 3.10 中删除。
在复活节彩蛋之前被称为 __new_parser__
,但被更改为 __peg_parser__
,以使其成为 message 中提到的未来证明:
new
, ex
or ng
are not really future proof names. Can we rename the keyword to __peg_parser__
?
为什么会得到SyntaxError: You found it!
?
你会得到 SyntaxError: You found it!
因为它是复活节彩蛋的一部分。
以后会被移除吗?
自 LL(1) parser will be replaced be the new Peg Parser 起,它将在 Python 3.10 中删除。
__peg_parser__
在 Python
的早期和后期版本中
它在 Python 的早期版本中不存在。
Python 3.8 及更早版本:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined
Python 3.9:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!
Python 3.10:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined
Guido 在 github here 上发布了新的 PEG 解析器。
它也在 Python PEP。
正如它提到的:
This PEP proposes replacing the current LL(1)-based parser of CPython with a new PEG-based parser. This new parser would allow the elimination of multiple "hacks" that exist in the current grammar to circumvent the LL(1)-limitation. It would substantially reduce the maintenance costs in some areas related to the compiling pipeline such as the grammar, the parser and the AST generation. The new PEG parser will also lift the LL(1) restriction on the current Python grammar.
Python 3.9 What's new 页中也提到了。
在 Python 3.10 中,LL(1)
解析器将被删除。 Python 3.9 使用新的解析器,基于 PEG 而不是 LL(1)。
在Python3.6中没有定义:
>>> __peg_parser__
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
__peg_parser__
NameError: name '__peg_parser__' is not defined
>>>
此 PEP 提议用新的基于 PEG 的解析器替换当前基于 LL(1) 的 CPython 解析器。这个新的解析器将允许消除当前语法中存在的多个“hacks”以规避 LL(1) 限制。它将大大降低与编译管道相关的某些领域的维护成本,例如语法、解析器和 AST 生成。新的 PEG 解析器还将取消对当前 Python 语法的 LL(1) 限制。
我正在使用 keyword
内置模块来获取当前 Python 版本的所有关键字的列表。这就是我所做的:
>>> 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']
并且在 keyword.kwlist
列表中有 __peg_parser__
。因此,为了查看它的作用,我在 Windows 上的 Python 3.9 解释器中键入 __peg_parser__
(您将在 Mac OS 和 Linux),这就是 get:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!
所以我的问题是,什么是 __peg_parser__
,为什么我会得到 SyntaxError: You found it!
?
这是与 the new PEG parser. The easter egg, along with the old LL(1) parser, will be removed in 3.10 推出相关的彩蛋。
什么是 __peg_parser__
?
它是 Python 中的彩蛋(属于 Peg Parser) for when the new Peg Parser was released. As mentioned in this discussion,将在 Python 3.10 中删除。
在复活节彩蛋之前被称为 __new_parser__
,但被更改为 __peg_parser__
,以使其成为 message 中提到的未来证明:
new
,ex
orng
are not really future proof names. Can we rename the keyword to__peg_parser__
?
为什么会得到SyntaxError: You found it!
?
你会得到 SyntaxError: You found it!
因为它是复活节彩蛋的一部分。
以后会被移除吗?
自 LL(1) parser will be replaced be the new Peg Parser 起,它将在 Python 3.10 中删除。
__peg_parser__
在 Python
的早期和后期版本中
它在 Python 的早期版本中不存在。
Python 3.8 及更早版本:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined
Python 3.9:
>>> __peg_parser__
File "<stdin>", line 1
__peg_parser__
^
SyntaxError: You found it!
Python 3.10:
>>> __peg_parser__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined
Guido 在 github here 上发布了新的 PEG 解析器。
它也在 Python PEP。
正如它提到的:
This PEP proposes replacing the current LL(1)-based parser of CPython with a new PEG-based parser. This new parser would allow the elimination of multiple "hacks" that exist in the current grammar to circumvent the LL(1)-limitation. It would substantially reduce the maintenance costs in some areas related to the compiling pipeline such as the grammar, the parser and the AST generation. The new PEG parser will also lift the LL(1) restriction on the current Python grammar.
Python 3.9 What's new 页中也提到了。
在 Python 3.10 中,LL(1)
解析器将被删除。 Python 3.9 使用新的解析器,基于 PEG 而不是 LL(1)。
在Python3.6中没有定义:
>>> __peg_parser__
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
__peg_parser__
NameError: name '__peg_parser__' is not defined
>>>
此 PEP 提议用新的基于 PEG 的解析器替换当前基于 LL(1) 的 CPython 解析器。这个新的解析器将允许消除当前语法中存在的多个“hacks”以规避 LL(1) 限制。它将大大降低与编译管道相关的某些领域的维护成本,例如语法、解析器和 AST 生成。新的 PEG 解析器还将取消对当前 Python 语法的 LL(1) 限制。