Skip to content
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

Add syntactic sugar support in the MExpr pretty-printer #664

Open
3 tasks
larshum opened this issue Dec 26, 2022 · 0 comments
Open
3 tasks

Add syntactic sugar support in the MExpr pretty-printer #664

larshum opened this issue Dec 26, 2022 · 0 comments

Comments

@larshum
Copy link
Contributor

larshum commented Dec 26, 2022

I think this could be a good first issue, so I'm giving a thorough explanation of what needs to be done and how to get started. Feel free to contact me if you are interested in taking this on, or if would like more help getting started.


We have added a few forms of syntactic sugar over the last couple of years. However, I know of three examples of syntactic sugar that have not been implemented in the pretty-printer:

  • A match-in expression, with an implicit else-branch containing never
  • A switch-expression, a series of match-expressions on the same variable, and ending with a never
  • A series of record updates (of the form {r with x = a, y = b} instead of {{r with x = a} with y = b})

Supporting these patterns would make the output from the pretty-printer more readable. I made an example file which defines MExpr string examples of the forms of syntactic sugar I mentioned above, as well as that of record projections (which is supported in the pretty-printer), and pretty-prints them. Note that record projections are represented as

match r with {x = x} then
  x
else never

If we run the example file, we see that record projections are pretty-printed in the syntactic sugar form, rather than the form shown above. However, the three forms of syntactic sugar mentioned above are all printed in a more verbose format. The goal is that they should be identified and pretty-printed using their syntactic sugar form.

To get started, take a look at:

  • The AST nodes for match-expressions, TmMatch, and record updates, TmRecordUpdate, in stdlib/mexpr/ast.mc.
  • The pretty-printer implementation for MExpr, in stdlib/mexpr/pprint.mc. In particular, have a look at how record projection is implemented for match-expressions (TmMatch).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant