-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor operations on the EDSL's AST using the visitor pattern #93
Conversation
With the new file structure make sure we apply mypy and black to the `backend` subfolders.
I think I've fixed the typing error described above. Now I'm running into issues when subclassing the
A similar issue is discussed in this thread and it appears that a solution would be to have default values for the extra arguments ( |
Thanks Dan, I think this looks like a really nice PR. I agree that it adds some complexity, but it will untangle some knots and make the core part of the code much simpler. In particular I didn't like having the rendering dependencies in core of the library. Is it possible that we can avoid the variadic methods by having a second template argument in addition to A for the argument the functions take? If they take 2 maybe that becomes a tuple? (however, I think we don't need that for most cases) def visit_compose(self, diagram: Compose, args: B), -> A: Also just to note: I like the idea of writing up some better documentation about the structure of the library once we feel like it is stable. Maybe we could even write a talk/paper and send somewhere like PyData. |
Oh also, let's not factor out the |
In order to make the code pass the typing checks, I've moved the arguments that were required when visiting the AST as attributes of the instanec (see for example `dwg` in `backend/svg.py`). I was able to move only the immutable arguments, while the ones that change during the traversal of hierarchy had to be kept as method arguments (otherwise we run into hairy bugs).
Yes, I was also thinking something along those lines, but I was afraid that the code would become too unwiedly, so I took a simpler approach in the end: I have moved the mandatory "global" arguments (e.g.,
I've corrected
Sounds great! Looking forward to this! By the way, I've created an organization page for the project (I am not very comfortable that the project is tied only to my name as you probably have contributed more than I did): https://github.com/chalk-diagrams I guess we can transfer the repository once we are done with this large refactoring.
Okay! Then I think I've mostly done what with this PR.
Yeah, I remember my own struggles with the |
This pull request continues the refactoring started in #92: it moves the logic initially defined in the data type (as methods, e.g.,
to_tikz
) to corresponding submodules (e.g.,backend/tikz.py
) using the visitor pattern (this roughly corresponds to pattern matching and fold of the EDSL's abstract syntax tree using an OOP style). It's not cleanest or easiest-to-read approach, but it does help in terms of modularity. (At some point I want to document a bit the library's internals and the various decisions we have made, since some of them are not exactly obvious.)@srush a couple of questions:
Shape
s to the corresponding backends, as you've previously hinted?