congo-cc / congo-parser-generator

The CongoCC Parser Generator, the Next Generation of JavaCC 21, which in turn was the next generation of JavaCC
https://discuss.congocc.org/
Other
36 stars 11 forks source link

Implementing the pertinent Python "Magic Methods" #92

Closed revusky closed 9 months ago

revusky commented 9 months ago

For some reason, I was trying to enhance (or refresh) my very minimal Python knowledge and I was interested in how operator overloading worked, and I came across: https://satish-p.medium.com/the-magic-of-python-a-comprehensive-guide-to-magic-methods-743bdeb4651f

Well, you know about all that. Anyway, it seems to me that our tree nodes in python should implement the relevant "magic methods", for example, that getitem should be defined to return the same thing as get_child(n), so anybody working with these nodes in Python, should actually be able to write myNode[n] to get the nth child node and so on. Well, we should have setitem hooked into set_child(index, node) and so on...

Is that not a good idea?