PEP 617: Resolve unreferenced footnotes (#3250)
This commit is contained in:
parent
5a77bca05b
commit
8e978d4ac3
47
pep-0617.rst
47
pep-0617.rst
|
@ -1,7 +1,5 @@
|
||||||
PEP: 617
|
PEP: 617
|
||||||
Title: New PEG parser for CPython
|
Title: New PEG parser for CPython
|
||||||
Version: $Revision$
|
|
||||||
Last-Modified: $Date$
|
|
||||||
Author: Guido van Rossum <guido@python.org>,
|
Author: Guido van Rossum <guido@python.org>,
|
||||||
Pablo Galindo <pablogsal@python.org>,
|
Pablo Galindo <pablogsal@python.org>,
|
||||||
Lysandros Nikolaou <lisandrosnik@gmail.com>
|
Lysandros Nikolaou <lisandrosnik@gmail.com>
|
||||||
|
@ -13,6 +11,8 @@ Created: 24-Mar-2020
|
||||||
Python-Version: 3.9
|
Python-Version: 3.9
|
||||||
Post-History: 02-Apr-2020
|
Post-History: 02-Apr-2020
|
||||||
|
|
||||||
|
.. highlight:: PEG
|
||||||
|
|
||||||
========
|
========
|
||||||
Overview
|
Overview
|
||||||
========
|
========
|
||||||
|
@ -298,13 +298,13 @@ and "hidden left-recursion" like::
|
||||||
Syntax
|
Syntax
|
||||||
------
|
------
|
||||||
|
|
||||||
The grammar consists of a sequence of rules of the form: ::
|
The grammar consists of a sequence of rules of the form::
|
||||||
|
|
||||||
rule_name: expression
|
rule_name: expression
|
||||||
|
|
||||||
Optionally, a type can be included right after the rule name, which
|
Optionally, a type can be included right after the rule name, which
|
||||||
specifies the return type of the C or Python function corresponding to
|
specifies the return type of the C or Python function corresponding to
|
||||||
the rule: ::
|
the rule::
|
||||||
|
|
||||||
rule_name[return_type]: expression
|
rule_name[return_type]: expression
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ Python-style comments.
|
||||||
|
|
||||||
Match e1, then match e2.
|
Match e1, then match e2.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: first_rule second_rule
|
rule_name: first_rule second_rule
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ The first alternative can also appear on the line after the rule name
|
||||||
for formatting purposes. In that case, a \| must be used before the
|
for formatting purposes. In that case, a \| must be used before the
|
||||||
first alternative, like so:
|
first alternative, like so:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name[return_type]:
|
rule_name[return_type]:
|
||||||
| first_alt
|
| first_alt
|
||||||
|
@ -350,14 +350,14 @@ first alternative, like so:
|
||||||
|
|
||||||
Match e.
|
Match e.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: (e)
|
rule_name: (e)
|
||||||
|
|
||||||
A slightly more complex and useful example includes using the grouping
|
A slightly more complex and useful example includes using the grouping
|
||||||
operator together with the repeat operators:
|
operator together with the repeat operators:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: (e1 e2)*
|
rule_name: (e1 e2)*
|
||||||
|
|
||||||
|
@ -366,14 +366,14 @@ operator together with the repeat operators:
|
||||||
|
|
||||||
Optionally match e.
|
Optionally match e.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: [e]
|
rule_name: [e]
|
||||||
|
|
||||||
A more useful example includes defining that a trailing comma is
|
A more useful example includes defining that a trailing comma is
|
||||||
optional:
|
optional:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: e (',' e)* [',']
|
rule_name: e (',' e)* [',']
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ optional:
|
||||||
|
|
||||||
Match zero or more occurrences of e.
|
Match zero or more occurrences of e.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: (e1 e2)*
|
rule_name: (e1 e2)*
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ Match zero or more occurrences of e.
|
||||||
|
|
||||||
Match one or more occurrences of e.
|
Match one or more occurrences of e.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: (e1 e2)+
|
rule_name: (e1 e2)+
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ Match one or more occurrences of e, separated by s. The generated parse
|
||||||
tree does not include the separator. This is otherwise identical to
|
tree does not include the separator. This is otherwise identical to
|
||||||
``(e (s e)*)``.
|
``(e (s e)*)``.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: ','.e+
|
rule_name: ','.e+
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ An example taken from the proposed Python grammar specifies that a primary
|
||||||
consists of an atom, which is not followed by a ``.`` or a ``(`` or a
|
consists of an atom, which is not followed by a ``.`` or a ``(`` or a
|
||||||
``[``:
|
``[``:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
primary: atom !'.' !'(' !'['
|
primary: atom !'.' !'(' !'['
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ consists of an atom, which is not followed by a ``.`` or a ``(`` or a
|
||||||
|
|
||||||
Commit to the current alternative, even if it fails to parse.
|
Commit to the current alternative, even if it fails to parse.
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
rule_name: '(' ~ some_rule ')' | some_alt
|
rule_name: '(' ~ some_rule ')' | some_alt
|
||||||
|
|
||||||
|
@ -451,7 +451,7 @@ Variables in the Grammar
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
A subexpression can be named by preceding it with an identifier and an
|
A subexpression can be named by preceding it with an identifier and an
|
||||||
``=`` sign. The name can then be used in the action (see below), like this: ::
|
``=`` sign. The name can then be used in the action (see below), like this::
|
||||||
|
|
||||||
rule_name[return_type]: '(' a=some_other_rule ')' { a }
|
rule_name[return_type]: '(' a=some_other_rule ')' { a }
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ with all the parsed expressions gets returned (this is meant for debugging).
|
||||||
|
|
||||||
The full meta-grammar for the grammars supported by the PEG generator is:
|
The full meta-grammar for the grammars supported by the PEG generator is:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
start[Grammar]: grammar ENDMARKER { grammar }
|
start[Grammar]: grammar ENDMARKER { grammar }
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ As an illustrative example this simple grammar file allows directly
|
||||||
generating a full parser that can parse simple arithmetic expressions and that
|
generating a full parser that can parse simple arithmetic expressions and that
|
||||||
returns a valid C-based Python AST:
|
returns a valid C-based Python AST:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
start[mod_ty]: a=expr_stmt* $ { Module(a, NULL, p->arena) }
|
start[mod_ty]: a=expr_stmt* $ { Module(a, NULL, p->arena) }
|
||||||
expr_stmt[stmt_ty]: a=expr NEWLINE { _Py_Expr(a, EXTRA) }
|
expr_stmt[stmt_ty]: a=expr NEWLINE { _Py_Expr(a, EXTRA) }
|
||||||
|
@ -619,7 +619,7 @@ for the parser.
|
||||||
|
|
||||||
A similar grammar written to target Python AST objects:
|
A similar grammar written to target Python AST objects:
|
||||||
|
|
||||||
::
|
.. code:: PEG
|
||||||
|
|
||||||
start: expr NEWLINE? ENDMARKER { ast.Expression(expr) }
|
start: expr NEWLINE? ENDMARKER { ast.Expression(expr) }
|
||||||
expr:
|
expr:
|
||||||
|
@ -787,17 +787,16 @@ References
|
||||||
==========
|
==========
|
||||||
|
|
||||||
.. [1] Ford, Bryan
|
.. [1] Ford, Bryan
|
||||||
http://pdos.csail.mit.edu/~baford/packrat/thesis
|
https://pdos.csail.mit.edu/~baford/packrat/thesis/
|
||||||
|
|
||||||
.. [2] Medeiros et al.
|
.. [2] Medeiros et al.
|
||||||
https://arxiv.org/pdf/1207.0443.pdf
|
https://arxiv.org/pdf/1207.0443.pdf
|
||||||
|
|
||||||
.. [3] Warth et al.
|
.. [3] Warth et al.
|
||||||
http://web.cs.ucla.edu/~todd/research/pepm08.pdf
|
https://web.cs.ucla.edu/~todd/research/pepm08.pdf
|
||||||
|
|
||||||
.. [#GUIDO_PEG]
|
[4] Guido's series on PEG parsing
|
||||||
Guido's series on PEG parsing
|
\ https://medium.com/@gvanrossum_83706/peg-parsing-series-de5d41b2ed60
|
||||||
https://medium.com/@gvanrossum_83706/peg-parsing-series-de5d41b2ed60
|
|
||||||
|
|
||||||
=========
|
=========
|
||||||
Copyright
|
Copyright
|
||||||
|
|
Loading…
Reference in New Issue