-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix error with pyparsing 3 for 3.5.x #21454
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
certifi | ||
coverage | ||
pyparsing<3.0.0 | ||
pytest!=4.6.0,!=5.4.0 | ||
pytest-cov | ||
pytest-rerunfailures | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also have been fixed by changing
oneOf(list(tex2uni))
tooneOf(list(tex2uni), asKeyword=True)
and removing the FollowedBy altogether? This has the benefit of reducing the number of pyparsing terms to be matched, which should translate to faster parsing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem of asKeyword is that "word boundary" needs a custom definition here (e.g. underscores and digits also separate words). I this this is configurable on pyparsing's side, but I'd rather just write our own regex (something like
(?![a-zA-Z])
) and be done with it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a better approach than trying to do custom keywords.
If you really want to collapse this down to a single
Regex
, then you could useoneOf
to build aRegex
for you of just the word choices, but then extract the generated regex pattern into a newRegex
, something likeRegex(r"\\(" + oneOf(text2uni).pattern + ")(?![a-zA-Z])")
. (untested, ymmv, etc.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tex symbols should not have any metacharacters, so the middle part is probably even just
"|".join(tex2uni)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beware of this -
oneOf
also takes care of reordering longer entries before shorter in the event the shorter entry is a leading subset, and also deduping. You could just reverse sort the keys intex2uni
by length, but if there are known frequencies to some symbols vs others, and more frequent entries were placed first,oneOf
would only reorder them to avoid masking entries, whereas sorting by longest-to-shortest would lose some of this priority ordering.You can test this for yourself:
will return "ab", not the longer and more desirable match "abb". And there are several cases in tex2uni of these kind of masking pairs.
Maybe keep it simple first, just do
"|".join(sorted(set(tex2uni), key=len, reverse=True))
and then get clever with the frequency-based ordering as a later experiment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point, thanks for mentioning that.