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 exception to delimiter logic for parenthesized with syntax #154

Merged
merged 7 commits into from
Feb 4, 2025

Conversation

rvanasa
Copy link
Contributor

@rvanasa rvanasa commented Feb 4, 2025

Accounts for new syntax in dfinity/motoko#4812.

@rvanasa rvanasa changed the title Add exception to delimiter logic for parenthesized with expressions Add exception to delimiter logic for parenthesized with syntax Feb 4, 2025
@@ -615,4 +615,11 @@ public type T = {
await expectFormatted('?#abc\n');
expect(await format('? #abc')).toEqual('?#abc\n');
});

test('parenthesized `with` expression', async () => {
await expectFormatted('(x with a = 1);\n');
Copy link

Choose a reason for hiding this comment

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

Suggested change
await expectFormatted('(x with a = 1);\n');
await expectFormatted('(x with a = 1)\n');

These are never followed by a semi, as they are not expressions/statements. Instead they prefix expressions.

Copy link

@ggreif ggreif Feb 4, 2025

Choose a reason for hiding this comment

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

Also maybe test await expectFormatted('(with a = 1)\n'); (and friends).

Copy link
Contributor Author

@rvanasa rvanasa Feb 4, 2025

Choose a reason for hiding this comment

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

Oh I see what you're saying. I'll update the tests so that it includes the following actor, since these cases are assumed to be (invalid) standalone expressions which end in trailing semicolons.

Copy link

Choose a reason for hiding this comment

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

Yeah, see:

$ rlwrap moc
Motoko compiler (source 0.13.7-202-g68eddf78f-dirty)
> (x with a = 1; b = 2);
stdin:1.22-1.23: syntax error [M0001], unexpected token ';', expected one of token or <phrase> sequence:
  <obj_or_class_dec>
  async <exp_nest>
  <exp_post(ob)> <inst> <exp_nullary(ob)>

Copy link

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

Looks good! THX!

@rvanasa rvanasa enabled auto-merge (squash) February 4, 2025 19:23
@rvanasa rvanasa merged commit 1c1f4bf into main Feb 4, 2025
5 checks passed
@rvanasa rvanasa deleted the migration-syntax branch February 4, 2025 19:23
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