diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-10-28 00:14:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-28 00:14:15 (GMT) |
commit | 24a7c298d47658295673dc04d1b6d59f2b200a7c (patch) | |
tree | 9045adac177946b15f31eb22033fbc912bbf1703 /Grammar | |
parent | c4b58cea4771afc0ddfdb857b0fb5115b9f4bc9f (diff) | |
download | cpython-24a7c298d47658295673dc04d1b6d59f2b200a7c.zip cpython-24a7c298d47658295673dc04d1b6d59f2b200a7c.tar.gz cpython-24a7c298d47658295673dc04d1b6d59f2b200a7c.tar.bz2 |
[3.9] bpo-42123: Run the parser two times and only enable invalid rules on the second run (GH-22111) (GH-23011)
* Implement running the parser a second time for the errors messages
The first parser run is only responsible for detecting whether
there is a `SyntaxError` or not. If there isn't the AST gets returned.
Otherwise, the parser is run a second time with all the `invalid_*`
rules enabled so that all the customized error messages get produced.
(cherry picked from commit bca701403253379409dece03053dbd739c0bd059)
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 6c36b6a..b709d3d 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -535,7 +535,7 @@ yield_expr[expr_ty]: arguments[expr_ty] (memo): | a=args [','] &')' { a } - | incorrect_arguments + | invalid_arguments args[expr_ty]: | a=','.(starred_expression | named_expression !'=')+ b=[',' k=kwargs {k}] { _PyPegen_collect_call_seqs(p, a, b, EXTRA) } | a=kwargs { _Py_Call(_PyPegen_dummy_name(p), @@ -620,7 +620,7 @@ t_atom[expr_ty]: # From here on, there are rules for invalid syntax with specialised error messages -incorrect_arguments: +invalid_arguments: | args ',' '*' { RAISE_SYNTAX_ERROR("iterable argument unpacking follows keyword argument unpacking") } | a=expression for_if_clauses ',' [args | expression for_if_clauses] { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "Generator expression must be parenthesized") } |