boisgera / pandoc

Pandoc (Python Library)
https://boisgera.github.io/pandoc/
MIT License
143 stars 16 forks source link

Structural Pattern Matching #38

Closed boisgera closed 2 years ago

boisgera commented 2 years ago

Study https://www.python.org/dev/peps/pep-0622/ and see what would be required to make pattern matching possible.

Given the brief review I have made, I think that's merely the definition of attributes _arg1, _arg2, etc. associated to _args and the definition of __match_args__ as ["_arg1", "_arg2", ...].

The idea would be to support feature extraction such as

match:
   case Pandoc(Meta({"author", MetaInlines(author)}), _):
       ...

to get the author metadata (as a list of inlines here).

boisgera commented 2 years ago

Actually _arg1 and so on would probably need to be read-only properties if _args stays the source of truth.