MagicPython icon indicating copy to clipboard operation
MagicPython copied to clipboard

Tokenization for match-case

Open alexr00 opened this issue 4 years ago • 3 comments

Originally from @SNvMK in https://github.com/microsoft/vscode/issues/120734

So, in python 3.10, there is match/case syntax. Currently, it is just white words(for monokai). I'd like if you add highlight for this. Thanks image

a = 'world'
match a:
    case 'world':
        print('Hello!')
    case _:
        print('I dont know you!')

Currently the match and case are only tokenized as source.python.

alexr00 avatar Apr 12 '21 09:04 alexr00

I opened #237 to address this one

cdce8p avatar May 01 '21 13:05 cdce8p

Though @cdce8p closed his PR, I think that this would still be beneficial. The VS Code markdown "previewer" use this grammar when rendering Python-labeled triple backtick blocks. I am happy to pick up on where @cdce8p left his great work.

I am trying to figure out if there is a reference for the yaml format that drives the production of the other files. In particular, I am wondering if there is documentation that explains whether there is a way to determine (using regular expression as much as possible) if the tokenizer is in a particular section. In other words, does the yaml file support defining a region (or something like that) according to two sets of regular expressions that could be used to label a section of code as belonging to the body of a lambda or with. We could write such a group detector for match statements which would make it easier to label case and _ as keywords when they are more likely to be keywords.

Obviously regular expressions are not enough to capture the full context sensitivity required to definitively mark match, case and _, but perhaps it could be a good start?

hawkinsw avatar Jun 25 '22 23:06 hawkinsw

This seems to be addressed by 7d0f2b22a5ad8fccbd7341bc7b7a715169283044. Is there going to be new release? Last one was in 2018.

contang0 avatar Oct 28 '22 22:10 contang0