catala
catala copied to clipboard
Feature request: syntactic sugar for Variant + Constructor
This is getting a little verbose:
declaration structure Foo:
data f₁ content t₁
...
declaration structure Bar:
data g₁ content u₁
declaration enumeration Baz:
-- Foo content Foo
-- Bar content Bar
because at construction-time, I need to write Foo (content Foo { f₁ = … })
suggested sugar is:
Foo content { f₁ = … }
with no parentheses
I think this is a good sugar to add. The changes for implementing it will likely cover:
- the parser (adding the sugar syntax)
- the desugaring pass (retrieving the struct id and fields from the id of the enum constructor)
I'd love to work on this! I'm a bit new to OCaml so I'll need to do some additional learning, but based on your comment @denismerigoux it seems like parser.mly
might be a good file to start with, right?
Are there other files in the compiler that would be relevant to this issue? Or do you have any suggested resources for learning more about how the parser currently works? I'm reading up on Obelisk and would be happy to look into other resources that you think might be helpful.
Hi @widal001 ! Thanks for proposing your help. Here are the places where you will probably insert the new sugar :
https://github.com/CatalaLang/catala/blob/fbd6b073722258b9f0edf974c46dfe2229037977/compiler/surface/parser.mly#L89
https://github.com/CatalaLang/catala/blob/fbd6b073722258b9f0edf974c46dfe2229037977/compiler/surface/ast.ml#L429-L432
https://github.com/CatalaLang/catala/blob/fbd6b073722258b9f0edf974c46dfe2229037977/compiler/surface/desugaring.ml#L398-L463
So the parser uses Menhir (and not Obelisk, which is just a visualization tool), whose manual is here. However the menhir manual assumes some knowledge about parser theory ; if you're curious and want to learn you can check out some lecture notes but otherwise you can just look at the Catala grammar and build an intuitive sense of how it works, and copy-paste things to build what you want to do :)
@denismerigoux Thanks for pointing me in the right direction and for sharing the additional resources on parser theory and Menhir specifically. I'll dig into this over the weekend, and follow up on this ticket if I have any other questions. Appreciate your time and willingness to welcome me to the project!
Hi @denismerigoux, wanted to ask if this issue has been resolved? If not, I'd like to work on this feature. Thanks !
@yokurang Yeah sorry I should have commented on the ticket a while ago, but I never got a chance to take this on. Would be great for someone else to pick up!
Hi @yokurang and thanks a lot for your interest. With our extended usage of the language since then we haven't been hitting the case covered by the sugar proposed here very often, which explains there has been no update on this issue.
Therefore, and if you are still willing to lend a hand, your efforts could be more helpful on something else. I just did a review of our open issues to check which ones could be best first picks. Among those, I could suggest:
- #590 for something that does not involve too much complexity, to get started
- #248 would get you closer to the backends, with concerns about out Python output
- #591 if you are willing to get more into the AST analysis parts
- #282 for something a bit more beefy related to small AST transformations