-
-
Notifications
You must be signed in to change notification settings - Fork 163
Using Zephyr ASDL
andychu edited this page Dec 1, 2019
·
4 revisions
If you define a sum type like
expr = Unary(expr e) | Binary(expr left, expr right)
Then you will get three pieces of generated code:
-
expr_e.Unary
: An integer tag.- typical usage:
if node.tag == expr_e.Unary
- typical usage:
-
expr.Unary()
: A Python class / type / constructor.- typical usage:
node = expr.Unary(child)
- Note that this is an alias for
expr__Unary()
. MyPy seems to like this form better. It makes it easier to statically type the code.
- typical usage:
-
expr_t
: A common superclass of all the nodes.- typical usage:
isinstance(node, expr_t)
- typical usage:
The implementation is here, with some more notes in the README.
https://github.com/oilshell/oil/tree/master/asdl
For conceptual background, see blog posts tagged #ASDL.