Merged
Conversation
Some notes: - This approach is not perfect, but it's rather simple and I can't think of an edge case. - I did not use the `words` function to create the regex matching the keywords list, because it returns a capturing group (`()`) and it needs to be non-capturing here (because of `bygroups` usage). - I chose to go to the 'soft-keywords-inner' state after both `match` and `case`, even though it's unnecessary for `match` (the inner state catches the `_` wildcard keyword which appears only after a `case`). This is mostly harmless and saves us from writing the 'soft-keywords' regex twice each for `match` and `case` with the extra inner state just for `case`. The only piece of code this will lex incorrectly is `match _:` (`_` will be lexed as keyword). I doubt though that pattern mathcing will be used like this.
Collaborator
|
Merged, thanks a lot! |
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.
Some notes:
This approach is very similar to what @taleinat did in bpo-44010: IDLE: colorize pattern-matching soft keywords python/cpython#25851 (thank you! this was a huge help).
It is not perfect, but it's rather simple and I can't think of an edge case.
I did not use the
wordsfunction to create the regex matching thekeywords list, because it returns a capturing group (
()) and itneeds to be non-capturing here (because of
bygroupsusage).I chose to go to the 'soft-keywords-inner' state after both
matchandcase, even though it's unnecessary formatch(the inner state catches the
_wildcard keyword which appearsonly after a
case).This is mostly harmless and saves us from writing the 'soft-keywords'
regex twice each for
matchandcasewith the extra inner statejust for
case.The only piece of code this will lex incorrectly is
match _:(
_will be lexed as keyword). I doubt though that pattern matchingwill be used like this.
Fixes #1797.