bpo-36256: Fix bug in parsermodule when parsing if statements#12477
Merged
pablogsal merged 7 commits intopython:masterfrom Mar 21, 2019
Merged
bpo-36256: Fix bug in parsermodule when parsing if statements#12477pablogsal merged 7 commits intopython:masterfrom
pablogsal merged 7 commits intopython:masterfrom
Conversation
In the parser module, when validating nodes before starting the parsing with to create a ST in "parser_newstobject" there is a problem that appears when two arcs in the same DFA state has transitions with labels with the same type. For example, the DFA for if_stmt has a state with two labels with the same type: "elif" and "else" (type NAME). The algorithm tries one by one the arcs until the label that starts the arc transition has a label with the same type of the current child label we are triying to accept. In this case, the arc for "elif" comes before the arc for "else"and passes this test (because the current child label is "else" and has the same type as "elif"). This lead to expecting a namedexpr_test (305) instead of a colon (11). The solution is to compare also the string representation (in case there is one) of the labels to see if the transition that we have is the correct one.
Contributor
|
Note that the generation of error message at https://github.com/python/cpython/pull/12477/files#diff-73f51bbc1366ee12a4f041d90bbb902dR700 wouldn't handle mismatching NAMEs correctly. Please see https://github.com/python/cpython/pull/10995/files#diff-73f51bbc1366ee12a4f041d90bbb902dR698 for the remaining part of the fix |
Contributor
|
An illustration of what I mean: I.e., it complains on a NAME saying that it expected NAME instead: not very informative! |
Contributor
|
Very good, thanks! |
brettcannon
approved these changes
Mar 21, 2019
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Member
Author
|
Thank you, everyone, for your review and code suggestions! |
Contributor
|
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
GH-12488 is a backport of this pull request to the 3.7 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 21, 2019
…GH-12477) bpo-36256: Fix bug in parsermodule when parsing if statements In the parser module, when validating nodes before starting the parsing with to create a ST in "parser_newstobject" there is a problem that appears when two arcs in the same DFA state has transitions with labels with the same type. For example, the DFA for if_stmt has a state with two labels with the same type: "elif" and "else" (type NAME). The algorithm tries one by one the arcs until the label that starts the arc transition has a label with the same type of the current child label we are trying to accept. In this case, the arc for "elif" comes before the arc for "else"and passes this test (because the current child label is "else" and has the same type as "elif"). This lead to expecting a namedexpr_test (305) instead of a colon (11). The solution is to compare also the string representation (in case there is one) of the labels to see if the transition that we have is the correct one. (cherry picked from commit 9a0000d) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This one was tricky! :)
In the parser module, when validating nodes before starting the parsing with to create a ST in "parser_newstobject" there is a problem that appears when two arcs in the same DFA state has transitions with labels with the same type. For example, the DFA for if_stmt has a state with
two labels with the same type: "elif" and "else" (type NAME). The algorithm tries one by one the arcs until the label that starts the arc transition has a label with the same type of the current child label we are
triying to accept. In this case, the arc for "elif" comes before the arc for "else"and passes this test (because the current child label is "else" and has the same type as "elif"). This lead to expecting a namedexpr_test (305) instead of a colon (11). The solution is to compare also the string representation (in case there is one) of the labels to see if the transition that we have is the correct one.
https://bugs.python.org/issue36256