-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Simplify the Grammar #116988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This appears to be a simple oversight, since |
Sure! Thank you for checking my sanity in understanding the grammar. Other than the grammar file itself, what else needs to be done for a PR? I am not familiar with contributing to CPython. |
Don't feel pressured to fix this. You can let me know and I can push a quick PR as well. If you want to open a PR for it though, start by going through the Developer's Guide. After having changed the grammar file ( |
Sounds good, I can do it now. |
8000
I'm having an issue with something I'm trying. I've looked into other instances of this rule being duplicated and successfully swapped all other oversights, except this one: Line 1402 in 408e127
Because
What is the correct solution here? |
Did you add a parenthesis around EDIT: Can you maybe post the diff here? |
Both versions generate the same problem. Here's the diff: diff --git a/Grammar/python.gram b/Grammar/python.gram
index 5153b02..69f2ed4 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -913,7 +913,7 @@ fstring_middle[expr_ty]:
| fstring_replacement_field
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
fstring_replacement_field[expr_ty]:
- | '{' a=(yield_expr | star_expressions) debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
+ | '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
_PyPegen_formatted_value(p, a, debug_expr, conversion, format, rbrace, EXTRA) }
| invalid_replacement_field
fstring_conversion[ResultTokenWithMetadata*]:
@@ -1198,7 +1198,7 @@ invalid_assignment:
| (star_targets '=')* a=star_expressions '=' {
RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
| (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") }
- | a=star_expressions augassign (yield_expr | star_expressions) {
+ | a=star_expressions augassign annotated_rhs {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a,
"'%s' is an illegal expression for augmented assignment",
@@ -1399,17 +1399,17 @@ invalid_replacement_field:
| '{' a='!' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before '!'") }
| '{' a=':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before ':'") }
| '{' a='}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before '}'") }
- | '{' !(yield_expr | star_expressions) { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting a valid expression after '{'")}
- | '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') {
+ | '{' !(annotated_rhs) { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting a valid expression after '{'")}
+ | '{' annotated_rhs !('=' | '!' | ':' | '}') {
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '=', or '!', or ':', or '}'") }
- | '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') {
+ | '{' annotated_rhs '=' !('!' | ':' | '}') {
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '!', or ':', or '}'") }
- | '{' (yield_expr | star_expressions) '='? invalid_conversion_character
- | '{' (yield_expr | star_expressions) '='? ['!' NAME] !(':' | '}') {
+ | '{' annotated_rhs '='? invalid_conversion_character
+ | '{' annotated_rhs '='? ['!' NAME] !(':' | '}') {
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting ':' or '}'") }
- | '{' (yield_expr | star_expressions) '='? ['!' NAME] ':' fstring_format_spec* !'}' {
+ | '{' annotated_rhs '='? ['!' NAME] ':' fstring_format_spec* !'}' {
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '}', or format specs") }
- | '{' (yield_expr | star_expressions) '='? ['!' NAME] !'}' {
+ | '{' annotated_rhs '='? ['!' NAME] !'}' {
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '}'") }
invalid_conversion_character: |
Right, this is the first time we're using a negative lookahead on a rule that's explicitly typed to something other than diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index 7cdd5debe9..84ed183c76 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -253,7 +253,7 @@ def lookahead_call_helper(self, node: Lookahead, positive: int) -> FunctionCall:
else:
return FunctionCall(
function=f"_PyPegen_lookahead",
- arguments=[positive, call.function, *call.arguments],
+ arguments=[positive, f"(void *(*)(Parser *)) {call.function}", *call.arguments],
return_type="int",
) |
Funny how we came to the same conclusion at the same time. That is what I just did. |
This is a small enough change (with no visible behavior changes) that it probably doesn't need a NEWS blurb. |
Excuse me.
What's the meaning of these patterns, for example, What is |
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
I've been implementing a Python runtime for a couple of months and I've been meaning to ask about something I noticed in the grammar.
Why do we use:
Instead of:
Forgive my ignorance when it comes to grammars but are these not the same thing?
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
annotated_rhs
in the Grammar #117004The text was updated successfully, but these errors were encountered: