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

:label supports Civet reserved words (but not JS reserved words) #1641

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Dec 9, 2024

Fixes #1638

  • Allow reserved words in :label
    • JavaScript reserved words will fail on output
    • Civet reserved words like loop and and are useful
    • :void remains untouched for possible return type annotation...
  • break :label can also use a reserved word, with the same caveats
  • break loop also works like break :loop, because it's "natural" meaning while (true) break isn't useful.

It's debatable to me whether :void should be allowed as a return-type annotation. It's extremely fragile; for example, :number doesn't work as a return-type annotation at the beginning of a line (it's treated as a label). UPDATE: But I guess :void is common enough to be worth keeping.

We could allow JavaScript reserved words in :label (possibly excepting :void) by transpiling them to _label: (though we need to avoid conflicts here, and can't exactly use refs). I'm not sure how useful this would be. But it might be nice e.g. to write

:while while cond()
  ...
  break :while

Copy link
Contributor

@STRd6 STRd6 left a comment

Choose a reason for hiding this comment

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

Thanks!

@edemaine edemaine merged commit 39911d7 into main Dec 9, 2024
4 checks passed
@edemaine edemaine deleted the reserved-labels branch December 9, 2024 21:02
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.

Calling Symbol.for("loop")
2 participants