lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.93k stars 416 forks source link

Support python match on Tree #1487

Open philzook58 opened 2 weeks ago

philzook58 commented 2 weeks ago

I really like the new python match construct but it seems the Tree datatype doesn't currently support it.

I can monkey patch it in with Tree.__match_args__ = ("data", "children") , but inserting this line into https://github.com/lark-parser/lark/blob/master/lark/tree.py should support it reasonably. Alternatively, a dataclass annotation I believe would also enable pattern matching.

erezsh commented 2 weeks ago

I support adding it.