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

Support the use of do as a connective in UCS #246

Merged
merged 7 commits into from
Dec 4, 2024

Conversation

chengluyu
Copy link
Member

@chengluyu chengluyu commented Dec 3, 2024

Main features:

  • Keyword do can appear in place of then, and the default value of its UCS expression will be replaced with UnitLit.
  • Keyword do can appear in a split of UCS to introduce expressions whose results are not needed between branches.

Relevant changes:

  • Keyword do has the same left and right precedence as then and can be parsed as an infix operator.
  • Add two Sets to Desugarer tracking the usage of do and then. If they are all used in the same UCS expression, an error will be reported.
  • Add test file ucs/syntax/Do.mls, which shows the semantic difference between do and then.

Not so relevant changes:

  • Add a unified apply to Desugarer. It should be called no matter we want to desugar case, if, or UCS shorthands.
  • Add kwLoc: Opt[Loc] field to IfLike and Case for better error reporting.

@LPTK
Copy link
Contributor

LPTK commented Dec 3, 2024

Nice change! There are a few places to update that currently use while imperatively but with then because we didn't have do at the time.

@chengluyu
Copy link
Member Author

Can you please squash this PR when you merge?

@LPTK LPTK force-pushed the hkmc2-ucs/do-keyword branch from 8b4b6a5 to 747a099 Compare December 4, 2024 12:35
Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, let's merge this.

Though I am not quite sure about the do situation. I don't like that it's currently overloaded, making things a bit difficult to parse sometimes, as in:

while
  do log(i)
  i < 3 do set i += 1

or

while
  do print(ls)
  ls is Cons(h, tl) do set ls = tl

Here the two uses of do serve quite different purposes, making things read a bit awkward.

@LPTK LPTK merged commit dbc6bcb into hkust-taco:hkmc2 Dec 4, 2024
1 check passed
@LPTK LPTK deleted the hkmc2-ucs/do-keyword branch December 4, 2024 12:41
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

Successfully merging this pull request may close these issues.

2 participants