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

do .. done: report "unclosed" error if done is missing #11297

Merged
merged 4 commits into from Jul 10, 2022
Merged

Conversation

nojb
Copy link
Contributor

@nojb nojb commented Jun 6, 2022

  • Allow do done (equivalent to do () done)
  • Allow "shortcut" attributes, extensions: do%foo ... done, do[@foo] ... done.
  • Give "unclosed" error when done is missing.

@nojb nojb force-pushed the do_done branch 2 times, most recently from f4a94e0 to 1bddc78 Compare June 6, 2022 06:54
@xavierleroy
Copy link
Contributor

Do we write so many busy waiting loops

for i = 1 to n do () done

that we need a special syntax to save three keystrokes? :-)

@alainfrisch
Copy link
Contributor

Do we write so many busy waiting loops

for i = 1 to n do () done

that we need a special syntax to save three keystrokes? :-)

I often write while (...) do () done (as a way to do do-while or similar loops). (I'm not claiming I cannot live with the ().)

@nojb
Copy link
Contributor Author

nojb commented Jun 6, 2022

No problem taking the do done sugar out of the PR, but do we agree that there is no reason to reject the other two tweaks?

@xavierleroy
Copy link
Contributor

I'm not looking for reasons to reject, just for reasons to accept.

The "unclosed" error explanation is nice to have.

Attributes and extensions on do, I'll let someone more competent than me say.

do done as a shortcut for do () done doesn't seem very useful to me, even for while where it makes more sense than for for. There's something to be said in favor of regularity in the syntax. Plus, all Algol-like languages have explicit empty statements (skip in IMP, a lone ; in C), and () works reasonably well as OCaml's explicit empty statement.

@gasche
Copy link
Member

gasche commented Jun 6, 2022

What is the meaning of do[@foo] e done or do%foo e done? If I understand the parsing rule correctly, this is considered as equivalent to do e[@foo] done or do [%foo e] done, which I find a bit confusing. Are we sure that this is the right behavior, is there a precedent for this? Ohter uses of ext_attributes I could easily find apply to the first keyword of the construct (here for, while where they are already supported), not inside.

(I guess I'm not convinced by the "attributes" part of this PR either.)

@nojb
Copy link
Contributor Author

nojb commented Jun 6, 2022

Are we sure that this is the right behavior, is there a precedent for this?

It is similar to what we do for begin%foo e end and begin[@foo] e end:

ocaml/parsing/parser.mly

Lines 2369 to 2370 in 85a3d4d

| BEGIN ext = ext attrs = attributes e = seq_expr END
{ e.pexp_desc, (ext, attrs @ e.pexp_attributes) }

@nojb nojb changed the title Bring parsing of do .. done in line with begin .. end and object .. end do .. done: report "unclosed" error if done is missing Jul 10, 2022
@nojb
Copy link
Contributor Author

nojb commented Jul 10, 2022

I updated this PR with only the "unclosed" error, which should be uncontroversial :)

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

Clearly a nice improvement. Thanks!

@gasche gasche merged commit 4b5dc16 into ocaml:trunk Jul 10, 2022
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.

None yet

4 participants